Re: Query plan for "heavy" SELECT with "lite" sub-SELECTs - Mailing list pgsql-performance

From Dave Dutcher
Subject Re: Query plan for "heavy" SELECT with "lite" sub-SELECTs
Date
Msg-id 012a01c6fe8a$bee330e0$8300a8c0@tridecap.com
Whole thread Raw
In response to Query plan for "heavy" SELECT with "lite" sub-SELECTs  ("Nikolay Samokhvalov" <samokhvalov@gmail.com>)
Responses Re: Query plan for "heavy" SELECT with "lite" sub-SELECTs
List pgsql-performance
> -----Original Message-----
> From: pgsql-performance-owner@postgresql.org
> Nikolay Samokhvalov
>
> What should I do to make Postgres work properly in such cases (I have
> a lot of similar queries; surely, they are executed w/o seqscans, but
> overall picture is the same - I see that starting from sub-selects
> dramatically decrease performance)?

How about this:

explain analyze
select (select typname from pg_type where pg_type.oid=mainq.prorettype limit
1)
from (select * from pg_proc offset 1500 limit 1) mainq;

                                                                QUERY PLAN
----------------------------------------------------------------------------
-------------------------------------------------
 Subquery Scan mainq  (cost=50.99..56.85 rows=1 width=4) (actual
time=13.646..13.659 rows=1 loops=1)
   ->  Limit  (cost=50.99..51.02 rows=1 width=310) (actual
time=13.575..13.579 rows=1 loops=1)
         ->  Seq Scan on pg_proc  (cost=0.00..62.34 rows=1834 width=310)
(actual time=0.014..7.297 rows=1501 loops=1)
   SubPlan
     ->  Limit  (cost=0.00..5.82 rows=1 width=64) (actual time=0.038..0.043
rows=1 loops=1)
           ->  Index Scan using pg_type_oid_index on pg_type
(cost=0.00..5.82 rows=1 width=64) (actual time=0.028..0.028 rows=1 loops=1)
                 Index Cond: (oid = $0)
 Total runtime: 13.785 ms

I would expect you to get closer to 2 ms on that query.  My machine takes 13
ms to do just the seq scan of pg_proc.

Dave




pgsql-performance by date:

Previous
From: Robins
Date:
Subject: Locking vs. Exceptions
Next
From: Madison Kelly
Date:
Subject: Setting "nice" values