pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Cc: Andreas Kretschmer <akretschmer@spamfence.net>
Subject: Re: BETWEEN optimizer problems with single-value
Date: Wed, 15 Mar 2006 14:25:58 -0600
Message-ID: <441823F5.EE98.0025.0@wicourts.gov> (raw)
In-Reply-To: <28798.1142450270@sss.pgh.pa.us>
References: <44180105.EE98.0025.0@wicourts.gov>
	<20060315181735.GA22240@KanotixBox>
	<44180D33.EE98.0025.0@wicourts.gov>
	<44180D33.EE98.0025.0@wicourts.gov>
	<28798.1142450270@sss.pgh.pa.us>

>>> On Wed, Mar 15, 2006 at  1:17 pm, in message
<28798.1142450270@sss.pgh.pa.us>,
Tom Lane <tgl@sss.pgh.pa.us> wrote: 
> 
> 8.1 is certainly capable of devising the plan you want, for example
> in the regression database:
> 
> regression=# explain select * from tenk1 where thousand = 10 and
tenthous 
> between 42 and 144;
>                                      QUERY PLAN
>
------------------------------------------------------------------------------------
>  Index Scan using tenk1_thous_tenthous on tenk1  (cost=0.00..6.01
rows=1 
> width=244)
>    Index Cond: ((thousand = 10) AND (tenthous >= 42) AND (tenthous <=
144))
> (2 rows)

That matches one of the examples where it optimized well.  I only saw
the bad plan when low and high ends of the BETWEEN range were equal.

> It looks to me like this is a matter of bad cost estimation, ie,
it's
> thinking the other index is cheaper to use.  Why that is is not
clear.
> Can we see the pg_stats rows for ctofcNo and calDate?

 schemaname | tablename | attname | null_frac | avg_width | n_distinct
|                                                most_common_vals       
                                         |                              
       most_common_freqs                                      |         
                                            histogram_bounds            
                                         | correlation
------------+-----------+---------+-----------+-----------+------------+-----------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+-------------
 public     | Cal       | calDate |         0 |         4 |       2114
|
{2003-06-02,2000-06-20,2001-04-16,2003-06-17,2003-12-01,2004-10-12,2001-04-23,2001-10-15,2002-03-06,2002-05-03}
|
{0.00333333,0.00233333,0.00233333,0.00233333,0.00233333,0.00233333,0.002,0.002,0.002,0.002}
|
{1986-03-14,1999-06-11,2000-07-14,2001-05-18,2002-03-21,2002-12-04,2003-08-12,2004-05-13,2005-02-01,2005-09-28,2080-12-31}
|   0.0545768
 public     | Cal       | ctofcNo |         0 |         8 |        669
| {0793,1252,1571,0964,0894,1310,"DA  ",0944,1668,0400}                 
                                         |
{0.024,0.019,0.015,0.0123333,0.012,0.011,0.0106667,0.01,0.00966667,0.00866667}
             | {0000,0507,0733,0878,1203,1336,14AG,1633,1971,3705,YVJO} 
                                                                 | 
-0.0179665
(2 rows)


> Also, try to force it to generate the plan you want, so we can see
what
> it thinks the cost is for that.  If you temporarily drop the wrong
index
> you should be able to get there:
> 
> 	begin;
> 	drop index  "Cal_CalDate";
> 	explain analyze select ... ;
> 	--  repeat as needed if it chooses some other wrong index
> 	rollback;

 Sort  (cost=4.03..4.03 rows=1 width=12) (actual time=48.484..48.486
rows=4 loops=1)
   Sort Key: "calDate", "startTime"
   ->  Index Scan using "Cal_CtofcNo" on "Cal" "CA"  (cost=0.00..4.02
rows=1 width=12) (actual time=36.750..48.228 rows=4 loops=1)
         Index Cond: ((("ctofcNo")::bpchar = '2192'::bpchar) AND
(("calDate")::date >= '2006-03-15'::date) AND (("calDate")::date <=
'2006-03-15'::date))
 Total runtime: 56.616 ms




view thread (20+ messages)  latest in thread

Message-ID: <441823F5.EE98.0025.0@wicourts.gov>
Permalink:  ../441823F5.EE98.0025.0@wicourts.gov/
Also on:    postgresql.org/message-id/441823F5.EE98.0025.0@wicourts.gov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: Kevin.Grittner@wicourts.gov, tgl@sss.pgh.pa.us, akretschmer@spamfence.net
  Subject: Re: BETWEEN optimizer problems with single-value
  In-Reply-To: <441823F5.EE98.0025.0@wicourts.gov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox