Обсуждение: new BUG: "postgresql 9.2.3: very long query time"

Поиск
Список
Период
Сортировка

new BUG: "postgresql 9.2.3: very long query time"

От
Claude Speed
Дата:
Hi all,

Postgresql 9.2.3 is processing my query is much longer than Postgresql 9.1.8:
Postgresql 9.1.8 - 2292 ms
Postgresql 9.2.3 - 163336 ms

I provided my query in attach and the database dump too,
this bug is reproducible.

Operating system: Gentoo x86_64 Linux 2.6.36
Вложения

Re: new BUG: "postgresql 9.2.3: very long query time"

От
bricklen
Дата:
On Wed, Feb 20, 2013 at 5:42 AM, Claude Speed <gta3user@gmail.com> wrote:
> Postgresql 9.2.3 is processing my query is much longer than Postgresql
> 9.1.8:
> Postgresql 9.1.8 - 2292 ms
> Postgresql 9.2.3 - 163336 ms
>
> I provided my query in attach and the database dump too,
> this bug is reproducible.

1). Can you supply the EXPLAIN ANALYZE plans for both queries?
2). Have you ANALYZEd the relevant tables recently?
3). Maybe supply the results of this query too:

SELECT name, current_setting(name), source
FROM pg_settings
WHERE source NOT IN ('default', 'override')
UNION ALL
SELECT 'version' as name, version(), null;

Re: new BUG: "postgresql 9.2.3: very long query time"

От
Claude Speed
Дата:
20.02.2013 19:45, bricklen пишет:
On Wed, Feb 20, 2013 at 5:42 AM, Claude Speed <gta3user@gmail.com> wrote:
Postgresql 9.2.3 is processing my query is much longer than Postgresql
9.1.8:
Postgresql 9.1.8 - 2292 ms
Postgresql 9.2.3 - 163336 ms

I provided my query in attach and the database dump too,
this bug is reproducible.
1). Can you supply the EXPLAIN ANALYZE plans for both queries?
2). Have you ANALYZEd the relevant tables recently?
3). Maybe supply the results of this query too:

SELECT name, current_setting(name), source
FROM pg_settings
WHERE source NOT IN ('default', 'override')
UNION ALL
SELECT 'version' as name, version(), null;
1) Explains in attach
2) tables are does not analyzed yet
3) Here they are
Postgres 9.2.3:
"application_name""pgAdmin III - Query Tool""client"
"bytea_output""escape""session"
"client_encoding""UNICODE""session"
"client_min_messages""notice""session"
"DateStyle""ISO, DMY""session"
"default_text_search_config""pg_catalog.russian""configuration file"
"lc_messages""ru_RU.utf-8""configuration file"
"lc_monetary""ru_RU.utf-8""configuration file"
"lc_numeric""ru_RU.utf-8""configuration file"
"lc_time""ru_RU.utf-8""configuration file"
"listen_addresses""*""configuration file"
"log_timezone""W-SU""configuration file"
"max_connections""100""configuration file"
"max_stack_depth""2MB""environment variable"
"port""5432""environment variable"
"shared_buffers""24MB""configuration file"
"TimeZone""W-SU""configuration file"
"version""PostgreSQL 9.2.3 on x86_64-pc-linux-gnu, compiled by x86_64-pc-linux-gnu-gcc (Gentoo 4.5.4 p1.0, pie-0.4.7) 4.5.4, 64-bit"""


Postgres 9.1.8:
"application_name""pgAdmin III - Query Tool""client"
"bytea_output""escape""session"
"client_encoding""UNICODE""session"
"client_min_messages""notice""session"
"DateStyle""ISO, DMY""session"
"default_text_search_config""pg_catalog.russian""configuration file"
"lc_messages""ru_RU.utf-8""configuration file"
"lc_monetary""ru_RU.utf-8""configuration file"
"lc_numeric""ru_RU.utf-8""configuration file"
"lc_time""ru_RU.utf-8""configuration file"
"listen_addresses""*""configuration file"
"log_timezone""W-SU""environment variable"
"max_connections""100""configuration file"
"max_stack_depth""2MB""environment variable"
"port""5432""environment variable"
"shared_buffers""24MB""configuration file"
"silent_mode""on""command line"
"TimeZone""W-SU""environment variable"
"version""PostgreSQL 9.1.8 on x86_64-pc-linux-gnu, compiled by x86_64-pc-linux-gnu-gcc (Gentoo 4.5.4 p1.0, pie-0.4.7) 4.5.4, 64-bit"""



Вложения

Re: new BUG: "postgresql 9.2.3: very long query time"

От
Jeff Janes
Дата:
On Wed, Feb 20, 2013 at 5:42 AM, Claude Speed <gta3user@gmail.com> wrote:
> Hi all,
>
> Postgresql 9.2.3 is processing my query is much longer than Postgresql
> 9.1.8:
> Postgresql 9.1.8 - 2292 ms
> Postgresql 9.2.3 - 163336 ms
>
> I provided my query in attach and the database dump too,
> this bug is reproducible.
>
> Operating system: Gentoo x86_64 Linux 2.6.36

The slowness was introduced with this:

commit e2fa76d80ba571d4de8992de6386536867250474
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Fri Jan 27 19:26:38 2012 -0500

    Use parameterized paths to generate inner indexscans more flexibly.


Do you know of simpler queries that also exhibits this behavior?  It
would certainly make analysis of the issue easier.


Cheers,

Jeff

Re: new BUG: "postgresql 9.2.3: very long query time"

От
Claude Speed
Дата:
21.02.2013 21:25, Jeff Janes пишет:
> On Wed, Feb 20, 2013 at 5:42 AM, Claude Speed <gta3user@gmail.com> wrote:
>> Hi all,
>>
>> Postgresql 9.2.3 is processing my query is much longer than Postgresql
>> 9.1.8:
>> Postgresql 9.1.8 - 2292 ms
>> Postgresql 9.2.3 - 163336 ms
>>
>> I provided my query in attach and the database dump too,
>> this bug is reproducible.
>>
>> Operating system: Gentoo x86_64 Linux 2.6.36
> The slowness was introduced with this:
>
> commit e2fa76d80ba571d4de8992de6386536867250474
> Author: Tom Lane <tgl@sss.pgh.pa.us>
> Date:   Fri Jan 27 19:26:38 2012 -0500
>
>      Use parameterized paths to generate inner indexscans more flexibly.
>
>
> Do you know of simpler queries that also exhibits this behavior?  It
> would certainly make analysis of the issue easier.
>
>
> Cheers,
>
> Jeff
We was trying to find simple query, sadly unlucky. Only this query is
reproducible.

Re: new BUG: "postgresql 9.2.3: very long query time"

От
Tom Lane
Дата:
Jeff Janes <jeff.janes@gmail.com> writes:
> The slowness was introduced with this:
>     Use parameterized paths to generate inner indexscans more flexibly.

Try increasing from_collapse_limit to 11 or more.

I'm not exactly sure why the param-path patch might have changed this
behavior, but in any case the collapse limits ought to be the first
thing you think of when you see a crappy plan for a many-relation query.

The curious join nesting in this query makes me wonder if perhaps it was
hand-optimized to fit the behavior of some old version of the planner ...

            regards, tom lane

new BUG: "postgresql 9.2.3: very long query time"

От
Jeff Janes
Дата:
On Friday, February 22, 2013, Tom Lane wrote:

> Jeff Janes <jeff.janes@gmail.com> writes:
> > The slowness was introduced with this:
> >     Use parameterized paths to generate inner indexscans more flexibly.
>
> Try increasing from_collapse_limit to 11 or more.
>

I've increased it to 20 and still no luck.


>
> I'm not exactly sure why the param-path patch might have changed this
> behavior, but in any case the collapse limits ought to be the first
> thing you think of when you see a crappy plan for a many-relation query.
>

I've stripped it down to this:

explain (analyze,buffers)
select  1 as shift_date
from     cb_order order1
            inner join Template template2 on order1."template" =
template2."id"
            left outer join Product product1 on template2."id" =
product1."id",
        Template template1                              cross join Product
product2
        where   order1."template" = template1."id"
        and     (
                            template2."id"=product2."id"
                        or
                            case         when product1."id" is not null
then 1
                                        when template2."id" is not null
then 0
                            end <>1
                            and
                            product2."id"=2916353
                   ) ;


The good plan uses a BitmapOr on a product2.id index to satisfy "
template2.id=product2.id or product2.id= 2916353" (which then needs to use
a filter to check that the CASE part holds in case the true branch of the
OR was the branch with 2916353)

The bad plan seems to have forgotten how to do that, and so seq scans
product2 repeatedly.  If I remove the CASE, then it uses the BitmapOr, so
what it has forgotten seems to be that A or (B and C) can only be true if
(A or C) is true.

I say "forgot", because the planner knows that the bad plan is way worse
than the good one, so it is probably about a lack-of-proof-of-correctness
rather than some small change in cost estimation pushing one over the other.

But it isn't as simple as that, as if I replace the CASE with one that
doesn't refer to product1.id, then it relearns how to use the BitmapOr.

case         when random()<0.5 then 1
                 when template2."id" is not null then 0
end <>1

I'm not sure where to go from here.

Cheers,

Jeff

Re: new BUG: "postgresql 9.2.3: very long query time"

От
Tom Lane
Дата:
Jeff Janes <jeff.janes@gmail.com> writes:
> On Friday, February 22, 2013, Tom Lane wrote:
>> Try increasing from_collapse_limit to 11 or more.

> I've increased it to 20 and still no luck.

Huh --- that improved the results for me.

> I've stripped it down to this:

I'm not sure if that's exactly the same issue the OP is hitting, but
will take a look at it.  Thanks for the simpler test case.

            regards, tom lane