pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Greg Stark <gsstark@mit.edu>
Cc: Stephan Szabo <sszabo@megazone23.bigpanda.com>
Cc: pgsql-general@postgresql.org
Subject: Re: index scan with index cond on first column doesn't recognize sort order of second column
Date: 13 Feb 2003 20:04:07 -0500
Message-ID: <87isvnk708.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <1915.1045178941@sss.pgh.pa.us>
References: <20030213113156.T47380-100000@megazone23.bigpanda.com>
	<87u1f7kf1y.fsf@stark.dyndns.tv>
	<1915.1045178941@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.us> writes:

> Greg Stark <gsstark@mit.edu> writes:
> > I'm not clear on what truncate_useless_pathkeys is doing.
> 
> It's throwing away pathkey info that isn't relevant for the current
> query (and would cause the planner to consider a multi-column-index
> scan as better-ordered than a scan of an index with fewer columns,
> when no such thing is true if the extra columns aren't relevant).

But it might be better ordered. I think you may have missed the original
context. In a query like:

  SELECT * FROM table_a join table_b using (col2) WHERE a.col1 = $0

Where there's an index on table_a(col1,col2) could use a merge join without a
sort.

Having truncate_useless_pathkeys removing the prefix means removing col2 from
the pathkeys leaving col1. In fact once the restriction is taken into account
the ordering of the path is in fact simply col2, which is just what's needed
for the mergejoin.

> > If it were changed to just keep the suffix would that break other things?
> 
> Yes, that would be completely backwards.

I'm not clear on how removing the suffix is ever useful. Even in a query like:

  SELECT * FROM table_a join table_b using (col1,col2) WHERE a.col1 between $0 and $1

The suffix is still relevant, the merge join is still possible.

--
greg




view thread (10+ messages)  latest in thread

Message-ID: <87isvnk708.fsf@stark.dyndns.tv>
Permalink:  ../87isvnk708.fsf@stark.dyndns.tv/
Also on:    postgresql.org/message-id/87isvnk708.fsf@stark.dyndns.tv

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: gsstark@mit.edu, tgl@sss.pgh.pa.us, sszabo@megazone23.bigpanda.com
  Subject: Re: index scan with index cond on first column doesn't recognize sort order of second column
  In-Reply-To: <87isvnk708.fsf@stark.dyndns.tv>
  References: <20030213113156.T47380-100000@megazone23.bigpanda.com> <87u1f7kf1y.fsf@stark.dyndns.tv> <1915.1045178941@sss.pgh.pa.us> <87isvnk708.fsf@stark.dyndns.tv>

* 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