Re: Predicate migration on complex self joins

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Simon Riggs" <simon(at)2ndQuadrant(dot)com>, "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Predicate migration on complex self joins
Date: 2009-07-13 19:03:13
Message-ID: 4A5B3EA1020000250002872A@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Writing a join for a single-table query? Why, in heavens name?
> (Or have you mercifully blotted the details from your memory?)

Actually, I had only the vaguest recollection of why, but I found an
email where I was explaining the problem to Sybase. Basically, it
boiled down to a corner case involving the intersection of named
caches and index optimizations similar to what Heikki's currently
developing. If we did a search such as:

SELECT searchName FROM Party WHERE searchName LIKE 'PET%,RANDY%'

where searchName was the first column of an index bound to a named
cache, it would scan the range of the index where searchName >= 'PET'
and searchName < 'PEU', determine which rows actually matched the
whole pattern, and access the heap pages only for those rows which
matched the pattern. (In this case, 298 rows.) As long as only
columns from the index were returned, there were only 298 access to
the heap. Now, if you added a column which was not in the index, it
went to the heap before checking the full pattern, so it went to the
heap 87,632 times for the above criteria, and returned the same 298
rows. Since the primary key columns were in all indexes (to allow use
of READ UNCOMMITTED :-/ ), we could select those columns without
driving it to the heap, so we used the first table reference just
for selecting the rows, and joined back to the same table on primary
key to get the values to return.

We could not convince Sybase that they should fix that issue.

-Kevin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Sam Mason 2009-07-13 19:15:27 Re: New types for transparent encryption
Previous Message Tom Lane 2009-07-13 19:02:17 Re: [RFC] obtaining the function call stack