[HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Pavel Stehule
Hello I test using index on foreign key. I found situation, when planner choose worse plan. create table f1(pk serial primary key); create table f2(fk integer references f1(pk)); insert into f1 select a from generate_series(1,1) a; insert into f2 select (random()*)::int+1 from

Re: [HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Martijn van Oosterhout
On Tue, May 16, 2006 at 11:52:05AM +0200, Pavel Stehule wrote: Hello I test using index on foreign key. I found situation, when planner choose worse plan. Can we seen an EXPLAIN ANALYZE output to see where the miscalculation lies. Is it underestimating the cost of the index scan, or

Re: [HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Pavel Stehule
Can we seen an EXPLAIN ANALYZE output to see where the miscalculation lies. Is it underestimating the cost of the index scan, or overestimating the cost of the hash join. postgres= explain analyze select count(*) from f1 join f2 on pk=fk;

Re: [HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Martijn van Oosterhout
On Tue, May 16, 2006 at 12:54:58PM +0200, Pavel Stehule wrote: Can we seen an EXPLAIN ANALYZE output to see where the miscalculation lies. Is it underestimating the cost of the index scan, or overestimating the cost of the hash join. postgres= explain analyze select count(*) from f1 join f2

Re: [HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Pavel Stehule
These are all minor abberations though, on the whole the estimates are pretty good. Perhaps you need to tweak the values of random_page_cost and similar variables. Thank You, It's general problem or only mine? I have 100% standard current PC. Pavel

Re: [HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Zeugswetter Andreas DCP SD
These are all minor abberations though, on the whole the estimates are pretty good. Perhaps you need to tweak the values of random_page_cost and similar variables. Thank You, It's general problem or only mine? I have 100% standard current PC. The default random_page_cost assumes some

Re: [HACKERS] Wrong plan for simple join with index on FK

2006-05-16 Thread Pavel Stehule
These are all minor abberations though, on the whole the estimates are pretty good. Perhaps you need to tweak the values of random_page_cost and similar variables. Thank You, It's general problem or only mine? I have 100% standard current PC. The default random_page_cost assumes some