Re: [PERFORM] Bad plan when join on function

2011-01-18 Thread Shaun Thomas
On 01/17/2011 02:03 AM, Zotov wrote: select c.id from OneRow c join abstract a on a.id=AsInteger(c.id) OneRow Contains only one row, abstract contains 22 953 500 rows AsInteger is simple function on Delphi it just return input value Ok... there has to be some kind of misunderstanding, here.

[PERFORM] Bad plan when join on function

2011-01-17 Thread Zotov
It`s just a sample. select c.id from OneRow c join abstract a on a.id=AsInteger(c.id) Nested Loop (cost=0.00..786642.96 rows=1 width=4) (actual time=91021.167..119601.344 rows=1 loops=1) Join Filter: ((a.id)::integer = asinteger((c.id)::integer)) - Seq Scan on onerow c (cost=0.00..1.01

Re: [PERFORM] Bad plan when join on function

2011-01-17 Thread Pavel Stehule
2011/1/17 Zotov zo...@oe-it.ru: It`s just a sample. select c.id from OneRow c join abstract a on a.id=AsInteger(c.id) Nested Loop  (cost=0.00..786642.96 rows=1 width=4) (actual time=91021.167..119601.344 rows=1 loops=1)   Join Filter: ((a.id)::integer = asinteger((c.id)::integer))   -  Seq

Re: [PERFORM] Bad plan when join on function

2011-01-17 Thread Kevin Grittner
Zotov wrote: select c.id from OneRow c join abstract a on a.id=AsInteger(c.id) Why SeqScan??? Because you don't have an index on AsInteger(c.id). If your function is IMMUTABLE (each possible combination of input values always yields the same result), and you declare it such, then you

Re: [PERFORM] Bad plan when join on function

2011-01-17 Thread Pavel Stehule
2011/1/17 Kevin Grittner kevin.gritt...@wicourts.gov: Zotov  wrote: select c.id from OneRow c join abstract a on a.id=AsInteger(c.id) Why SeqScan??? Because you don't have an index on AsInteger(c.id). If your function is IMMUTABLE (each possible combination of input values always yields

Re: [PERFORM] Bad plan when join on function

2011-01-17 Thread Tom Lane
Pavel Stehule pavel.steh...@gmail.com writes: it should to work without functional index - but not sure about effectivity As long as the function is VOLATILE, the planner can't use any intelligent query plan. Merge or hash join both require at least stable join keys.

Re: [PERFORM] Bad plan when join on function

2011-01-17 Thread Pavel Stehule
2011/1/17 Tom Lane t...@sss.pgh.pa.us: Pavel Stehule pavel.steh...@gmail.com writes: it should to work without functional index - but not sure about effectivity As long as the function is VOLATILE, the planner can't use any intelligent query plan.  Merge or hash join both require at least