How to push predicate down

Поиск
Список
Период
Сортировка
От salah jubeh
Тема How to push predicate down
Дата
Msg-id 1327585878.63499.YahooMailNeo@web161504.mail.bf1.yahoo.com
обсуждение исходный текст
Ответы Re: How to push predicate down  (Volodymyr Kostyrko <c.kworr@gmail.com>)
Список pgsql-general

Hello Guys,

In the past  I had a view defined as follows

CREATE view abcd as
SELECT whatever ...... --- query1

Some business requierments came up and I had to change it like this
 
CREATE view abcd as
SELECT whatever ...... --- query1
UNION
SELECT whatever ......---- query2



Now I have a problem in the time for calculating the query when using a predicate

-- this time makes sense
SELECT * FROM abcd

Query time ( Past)   = X
Query time (current)  = X +Y -- (Y is the time which introduced by query2)



But If I run the query

-- This does not make sense
SELECT * FROM abcd  where predicate = 'predicate_a'
Query time ( Past)   = 1 /10 * X
Query time (current) = X + Y  -- I assume the time should be 1/10*X + Y

--Note,  Y is much smaller than X  so I do not care too much about it, so X is the dominant factor

I had a look on the execution plane and the predicate 'predicate_a' was pushed up  on the top  in the current situation

i.e.

In the past  the excution plane was like this

Filter using the predicate 'predicate_a' and then do the calculation of the rest of  query1, this is why the time is reduced to 1/10 * X

Now the execution plan is like this

Calculate query1  and  then calculate query2 and then Union the result and finally   filter using predicate 'predicate_a',


Why it is not like this

Filter  first using the predicate 'predicate_a' when calculating query1
Filter  first using the predicate 'predicate_a' when calculating query2
Then do the union 



Sorry I did not post the execution plan but it is more than 5000 line

Regards



В списке pgsql-general по дате отправления:

Предыдущее
От: Chris Angelico
Дата:
Сообщение: Re: Best way to create unique primary keys across schemas?
Следующее
От: Jon Smark
Дата:
Сообщение: Let-bindings in SQL statements