Re: [GENERAL] Different query plan used for the same query depending on how parameters are passed

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [GENERAL] Different query plan used for the same query depending on how parameters are passed
Дата
Msg-id 20300.1494949918@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [GENERAL] Different query plan used for the same query dependingon how parameters are passed  (David Chapman <david.chapman@mavensecurities.com>)
Список pgsql-general
David Chapman <david.chapman@mavensecurities.com> writes:
> Here is the output of EXPLAIN ANALYZE on the two queries.

> Index Scan using test_index_t1_t2 on test  (cost=0.43..684.11 rows=71
> width=245) (actual time=0.022..1.147 rows=99 loops=1)
>   Index Cond: ((t1 = 'X'::bpchar) AND (t2 = ANY ('{2286575,2139022,2139030,
                 ^^^^^^^^^^^^^^^^^^

> Seq Scan on test  (cost=0.00..403725.30 rows=1 width=245) (actual
> time=47.543..5362.518 rows=99 loops=1)
>   Filter: (((t1)::text = 'X'::text) AND (t2 = ANY
             ^^^^^^^^^^^^^^^^^^^^^^^^

There's your problem.  t1 is evidently of char(n) type, and when you
write "t1 = 'X'" the literal also becomes char(n) and so you have
a condition that can match the index.  But the parameter is evidently
being assigned type text, which wins the type conflict so then you have
"t1::text text-eq text-constant", and that operator doesn't match the index.

Probably, casting the parameter to char(n) explicitly would fix this.

            regards, tom lane


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

Предыдущее
От: Martin Goodson
Дата:
Сообщение: Re: [GENERAL] EnterpriseDB installed PostgreSQL 9.6 vs. REPMGR. Round4 - compilation issues on RHEL 7.2
Следующее
От: "Peter J. Holzer"
Дата:
Сообщение: Re: [GENERAL] storing large files in database - performance