![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, Is there an option in PG to do it? |
#3
| |||
| |||
|
|
Coniglio Sgabbiato<nobody (AT) nowhere (DOT) net> wrote: Hi, Is there an option in PG to do it? No. Only for primary keys. Andreas |
#4
| |||
| |||
|
|
No. Only for primary keys. Andreas What a shame! Is it possible to request such a feature for PG next release? Im my opinion it should be active by default (it is expected that foreign keys will be used in joins besides referential integrity). |
#5
| |||
| |||
|
|
Do you know any DBMS where FK columns are automatically indexed? Thomas |
|
Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ test2 | 0 | PRIMARY | 1 | id | A 0 | NULL | NULL | | BTREE | | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ |
#6
| |||
| |||
|
|
Il 18/12/2009 7.45, Andreas Kretschmer ha scritto: Coniglio Sgabbiato<nobody (AT) nowhere (DOT) net> wrote: Hi, Is there an option in PG to do it? No. Only for primary keys. Andreas What a shame! Is it possible to request such a feature for PG next release? Im my opinion it should be active by default (it is expected that foreign keys will be used in joins besides referential integrity). |
#7
| |||
| |||
|
|
http://dev.mysql.com/doc/refman/5.1/...nstraints.html it _seems_ to say that Mysql _could_ do that: |
|
I tested it but it seems it does not work. |
#8
| |||
| |||
|
|
In short: -1 from me. No, there are a LOT of use cases where nobody needs such an index, especially with small refereced tables. |
#9
| |||
| |||
|
|
[CUT] In short: -1 from me. No, there are a LOT of use cases where nobody needs such an index, especially with small refereced tables. I meant creation of index in referencing table, not referenced, what do you think about? |
#10
| |||||
| |||||
|
|
In short: -1 from me. No, there are a LOT of use cases where nobody needs such an index, especially with small refereced tables. I meant creation of index in referencing table, not referenced, what do you think about? |
|
-- create a set of rows with low cardinality CREATE TABLE week ( dayname VARCHAR PRIMARY KEY, stuff FLOAT ); INSERT INTO week VALUES ('monday', 3.1415926535897931), ('tuesday', 2.7182818284590451), ('wednesday', 1.4142135623730951), ('thurstday', 0.3010299956639812), ('friday', 0.8660254037844386), ('saturday', 0.99627207622074998), ('sunday', 0); -- and a table that will contain a lot of data, referencing the first one CREATE TABLE bigone ( pk SERIAL, dayname VARCHAR REFERENCES week ); -- 700k rows INSERT INTO bigone (dayname) SELECT dayname FROM ( SELECT * FROM week CROSS JOIN (SELECT * FROM generate_series(1,100000)) numbers ) days ORDER BY random(); INSERT INTO bigone (dayname) VALUES ((SELECT dayname FROM week ORDER BY RANDOM() LIMIT 1)); |
|
test=# EXPLAIN SELECT pk, stuff FROM bigone natural JOIN week; QUERY PLAN --------------------------------------------------------------------- Hash Join (cost=36.10..14089.86 rows=440832 width=12) Hash Cond: ((bigone.dayname)::text = (week.dayname)::text) -> Seq Scan on bigone (cost=0.00..7992.32 rows=440832 width=36) -> Hash (cost=21.60..21.60 rows=1160 width=40) -> Seq Scan on week (cost=0.00..21.60 rows=1160 width=40) (5 rows) |
|
test=# CREATE INDEX bigone_dayname_idx ON bigone (dayname); CREATE INDEX |
|
coges=# EXPLAIN SELECT pk, stuff FROM bigone natural JOIN week; QUERY PLAN ---------------------------------------------------------------------- Hash Join (cost=36.10..20245.12 rows=700001 width=12) Hash Cond: ((bigone.dayname)::text = (week.dayname)::text) -> Seq Scan on bigone (cost=0.00..10584.01 rows=700001 width=12) -> Hash (cost=21.60..21.60 rows=1160 width=40) -> Seq Scan on week (cost=0.00..21.60 rows=1160 width=40) |
![]() |
| Thread Tools | |
| Display Modes | |
| |