Re: Slow query in trigger function
| От | Guido Niewerth |
|---|---|
| Тема | Re: Slow query in trigger function |
| Дата | |
| Msg-id | 83359cf9670c4026bbef97cac9005f43@EX2k13.ocsnet.local обсуждение исходный текст |
| Ответ на | Slow query in trigger function (Guido Niewerth <gniewerth@ocsgmbh.com>) |
| Список | pgsql-performance |
These are the queries I used to get the execution planer use the index scan instead of the sequential scan:
IF NOT EXISTS (SELECT 1 FROM custom_data WHERE key = old.key) => sequential scan
IF NOT EXISTS (SELECT 1 FROM custom_data WHERE key = old.key LIMIT 1) => sequential scan
IF NOT EXISTS (SELECT max( 1 ) FROM custom_data WHERE key = old.key) => sequential scan
After breaking up the code into two statements the execution planer uses the index scan:
result INTEGER;
SELECT 1 FROM custom_data where key = old.key INTO result;
IF result ISNULL THEN
...
END IF;
To me it looks like the execution planer does not choose the optimal strategy. Even small changes in the function body make the execution planer use the slow sequential scan.
Guido Niewerth |
В списке pgsql-performance по дате отправления: