Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Chapman <david.chapman@xxxxxxxxxxxxxxxxxxx> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux