why SPI_execute_with_args don't use known values for optimalisation

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема why SPI_execute_with_args don't use known values for optimalisation
Дата
Msg-id 162867790805212342y19bf1594h9b026f04ecdc0ee6@mail.gmail.com
обсуждение исходный текст
Список pgsql-hackers
Hello

I would to use EXECUTE USING for optimalisation query

SELECT * FROM tab WHERE column = param OR param IS NULL

(if param isn't null then use param else ignore this params)

Planner can do it:

postgres=# explain select * from test where a = 100 or 100 is null;                            QUERY PLAN
---------------------------------------------------------------------Index Scan using test_idx on test
(cost=0.00..8.28rows=1 width=4)  Index Cond: (a = 100)
 
(2 rows)

postgres=# explain select * from test where a = null or null is null;                        QUERY PLAN
------------------------------------------------------------Seq Scan on test  (cost=0.00..1393.00 rows=100000 width=4)
(1 row)

but:

create or replace function test_using(p integer)
returns int as $$
declare r record;
begin for r in execute 'explain analyze select a from test where a = $1 or
$1 is null' using p loop   raise notice '%', r; end loop; return 0; end;
$$ language plpgsql;

postgres=# select test_using(100);
NOTICE:  ("Seq Scan on test  (cost=0.00..1643.00 rows=501 width=4)
(actual time=0.076..26.546 rows=1 loops=1)")
NOTICE:  ("  Filter: ((a = $1) OR ($1 IS NULL))")
NOTICE:  ("Total runtime: 26.596 ms")test_using
------------         0
(1 row)

Regards
Pavel Stehule


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

Предыдущее
От: "Robert Haas"
Дата:
Сообщение: Re: idea: storing view source in system catalogs
Следующее
От: Hannu Krosing
Дата:
Сообщение: Re: proposal: table functions and plpgsql