Re: Different execution plan between PostgreSQL 8.4 and 12.11

Поиск
Список
Период
Сортировка
От Klint Gore
Тема Re: Different execution plan between PostgreSQL 8.4 and 12.11
Дата
Msg-id MEYPR01MB710115DAD64C0C15DE914657A4259@MEYPR01MB7101.ausprd01.prod.outlook.com
обсуждение исходный текст
Ответ на Re: Different execution plan between PostgreSQL 8.4 and 12.11  (gzh <gzhcoder@126.com>)
Список pgsql-general
From: gzh <gzhcoder@126.com> Sent: Wednesday, 12 October 2022 9:30 PM
 
> Who can tell me which solution is better below:

> Solution 1: Change the configuration parameters

>    set enable_seqscan = off

> Solution 2: Add DISTINCT clause to SQL

>    explain analyze select DISTINCT 2 from analyze_word_reports where (cseid = 94) limit 1;

> If I don't want to change SQL, is Solution 1 OK?


Both solutions are ugly

enable_seqscan is a really blunt instrument and may affect the rest of your system as well as just this query.  Queries that boil down to "select * from partition" are now encouraged to use the index in a useless manor.  A small table (e.g. to hold application settings) now has to do a primary key lookup when all rows fit on the first page anyway.

distinct+limit is really just trying to convince the v12 planner that it can bail out after the first row found at all levels. Having both is superfluous as they individually end up at the same result.   it may not work in v13/14/15/... or even be needed.  Have you tried it on your v12?  My data may be different enough to your data that it doesn't work anyway.  What it does in the old postgres version is anyone's guess.

Solution 1 I'd treat as an emergency stop gap to buy time to find a better solution.  The patient is no longer bleeding out and the path forward can be considered.  If you're not going to change the app, then the only other choice is play with other system wide settings (like random_page_cost).  Not as blunt as enable_seqscan but still affects all queries, not just this one.

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

Предыдущее
От: Chun Fan Lin
Дата:
Сообщение: PGAdmin 4 fatal error after enabling the import logging
Следующее
От: gzh
Дата:
Сообщение: Re:Re: Does psqlodbc_11_01_0000-x64 support special characters?