pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Siracusa <siracusa@mindspring.com>
To: Postgres Performance <pgsql-performance@postgresql.org>
Subject: Re: Feature request: smarter use of conditional indexes
Date: Sat, 6 Mar 2004 21:29:27 -0500
Message-ID: <41C473B6-6FDF-11D8-9156-000A95BA4506@mindspring.com> (raw)

On 3/3/04 6:53 PM, Tom Lane wrote:
>  John Siracusa <siracusa@mindspring.com> writes:
>>  Given an index like this:
>>      CREATE UNIQUE INDEX i1 ON t1 (c1) WHERE c1 IS NOT NULL;
>>  and a query like this:
>>      SELECT * FROM t1 WHERE c1 = 123;
>>  I'd like the planner to be smart enough to use an index scan using 
>> i1.
>
>  Send a patch ;-)

How does this look?  It seems to do what I want without horribly 
breaking anything as far as I can tell.  I ran "make check" and got the 
same result as I did before my changes (5 failures in OS X 10.3.2).  
But then, I also got the same result when I wasn't even checking to 
make sure that both clauses were looking at the same variable :)  I'm 
not sure how to add a test for this particular change either.

% cvs diff src/backend/optimizer/path/indxpath.c
Index: src/backend/optimizer/path/indxpath.c
===================================================================
RCS file: 
/projects/cvsroot/pgsql-server/src/backend/optimizer/path/indxpath.c,v
retrieving revision 1.156
diff -r1.156 indxpath.c
1032a1033,1055
 >	{
 >		/* One last chance: "var = const" or "const = var" implies "var is 
not null" */
 >		if (IsA(predicate, NullTest) &&
 >			((NullTest *) predicate)->nulltesttype == IS_NOT_NULL &&
 >			is_opclause(clause) && op_strict(((OpExpr *) clause)->opno) &&
 >			length(((OpExpr *) clause)->args) == 2)
 >		{
 >			leftop = get_leftop((Expr *) clause);
 >			rightop = get_rightop((Expr *) clause);
 >
 >			/* One of the two arguments must be a constant */
 >			if (IsA(rightop, Const))
 >				clause_var = leftop;
 >			else if (IsA(leftop, Const))
 >				clause_var = rightop;
 >			else
 >				return false;
 >
 >			/* Finally, make sure "var" is the same var in both clauses */
 >			if (equal(((NullTest *) predicate)->arg, clause_var))
 >				return true;
 >		}
 >
1033a1057
 >	}




view thread (11+ messages)  latest in thread

Message-ID: <41C473B6-6FDF-11D8-9156-000A95BA4506@mindspring.com>
Permalink:  ../41C473B6-6FDF-11D8-9156-000A95BA4506@mindspring.com/
Also on:    postgresql.org/message-id/41C473B6-6FDF-11D8-9156-000A95BA4506@mindspring.com

 · 

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: siracusa@mindspring.com
  Subject: Re: Feature request: smarter use of conditional indexes
  In-Reply-To: <41C473B6-6FDF-11D8-9156-000A95BA4506@mindspring.com>

* 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