![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
INSERT INTO bigone (dayname) VALUES ((SELECT dayname FROM week ORDER BY RANDOM() LIMIT 1)); |
|
coges=# EXPLAIN SELECT pk, stuff FROM bigone natural JOIN week; QUERY PLAN |
#12
| |||
| |||
|
|
Coniglio Sgabbiato<nobody (AT) nowhere (DOT) net> wrote: [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? Ahhh... test=# create table "Coniglio Sgabbiato" (id serial primary key); NOTICE: CREATE TABLE will create implicit sequence "Coniglio Sgabbiato_id_seq" for serial column "Coniglio Sgabbiato.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "Coniglio Sgabbiato_pkey" for table "Coniglio Sgabbiato" CREATE TABLE Read the NOTICE - lines careful ... But: test=*# create table foobar(i int references "Coniglio Sgabbiato" on delete cascade); CREATE TABLE |

#13
| |||
| |||
|
|
Marco Mariani wrote: INSERT INTO bigone (dayname) VALUES ((SELECT dayname FROM week ORDER BY RANDOM() LIMIT 1)); of course this is unneded coges=# EXPLAIN SELECT pk, stuff FROM bigone natural JOIN week; QUERY PLAN Fact is, even if you ANALYZE the table, postgres doesn't make use of the index. It need a bigger week table. How big I don't know, and I'd like to know if there are some heuristics. |
#14
| |||
| |||
|
|
Coniglio Sgabbiato wrote: 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? Ok, so I took the time to write a test case. Can you explain me the effect of the index bigone_dayname_idx, apart from taking space and slowing insertions? BTW, most of my foreign keys are never used in joins, are there purely for referential integrity, and reference small tables. [CUT] |
#15
| |||
| |||
|
|
Coniglio Sgabbiato wrote: [ talking about foreign keys in mysql ] 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. Maybe you could wait for a full moon and retry.. |

#16
| |||
| |||
|
|
Il 18/12/2009 17.39, Marco Mariani ha scritto: Coniglio Sgabbiato wrote: 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? Ok, so I took the time to write a test case. Can you explain me the effect of the index bigone_dayname_idx, apart from taking space and slowing insertions? BTW, most of my foreign keys are never used in joins, are there purely for referential integrity, and reference small tables. [CUT] I got your point, good one. Otherwise, I believe that an index on foreign keys in little tables is a negligible overhead, either in disk space and in cpu time on inserts. In big tables it might be useful if the join condition is associate to another condition, for example, if t1.foo references t2.foo then: select * from t1 join t2 on t1.foo=t2.foo and t1.foo>'something' I am assuming (did not test it) that when t1 is huge the planner will use the index, if present, on t2.foo. What do you think about? |
#17
| |||
| |||
|
|
I got your point, good one. Otherwise, I believe that an index on foreign keys in little tables is a negligible overhead, |
#18
| |||
| |||
|
|
On Dec 18, 7:13 pm, Coniglio Sgabbiato<nob... (AT) nowhere (DOT) net> wrote: I got your point, good one. Otherwise, I believe that an index on foreign keys in little tables is a negligible overhead, We're not talking about an index in a little table -- but about an index in a possibly HUGE table So this is an index that slows down a lot of things. An index that references a (relatively) small table, hence has a low selectivity, so it is useless because using it would be slower than a full scan. |

#19
| |||
| |||
|
|
So... what about Mysql? It is OT but now I'm curious about their decision to make it automatic ![]() |
#20
| |||
| |||
|
|
So... what about Mysql? It is OT but now I'm curious about their decision to make it automatic ![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |