PostgreSQL: Advanced SQL: Improving performance at the SQL level

  • EXPLAIN [ ANALYZE ]
01
02 CREATE VIEW comb_t AS SELECT i FROM t EXCEPT SELECT i FROM not_t;
03
04 template1=# EXPLAIN ANALYZE select * from comb_t where i=1;

05                                                              QUERY PLAN
06
07 -----------------------------------------------------------------------------------------------------------------------
08  Subquery Scan comb_t  (cost=169.66..182.16 rows=1 width=4) (actual time=0.118..0.118 rows=0 loops=1)
09    Filter: (i = 1)
10   ->  SetOp Except  (cost=169.66..179.66 rows=200 width=4) (actual time=0.105..0.106 rows=1 loops=1)
11      ->  Sort  (cost=169.66..174.66 rows=2000 width=4) (actual time=0.093..0.096 rows=3 loops=1)
12           Sort Key: i
13        ->  Append  (cost=0.00..60.00 rows=2000 width=4) (actual time=0.028..0.057 rows=3 loops=1)
14           ->  Subquery Scan "*SELECT* 1"  (cost=0.00..30.00 rows=1000 width=4) (actual time=0.026..0.037 rows=2 loops=1)
15                 ->  Seq Scan on t  (cost=0.00..20.00 rows=1000 width=4) (actual time=0.017..0.023 rows=2 loops=1)
16           ->  Subquery Scan "*SELECT* 2"  (cost=0.00..30.00 rows=1000 width=4) (actual time=0.008..0.012 rows=1 loops=1)
17                 ->  Seq Scan on not_t  (cost=0.00..20.00 rows=1000 width=4) (actual time=0.006..0.008 rows=1 loops=1)
18  Total runtime: 0.258 ms
19 (11 rows)




Prev

Next

Page 34