minor bug in sort_inner_and_outer()
Tomas Vondra <tomas.vondra@enterprisedb.com>
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-01-14T00:48:33Z
Lists: pgsql-hackers
Attachments
- sort-inner-and-outer-fix.patch (text/x-patch) patch
Hi,
While looking at sort_inner_and_outer() I was rather confused what is
stored in all_pathkeys, because the code does this:
List *all_pathkeys;
...
all_pathkeys = select_outer_pathkeys_for_merge(root,
extra->mergeclause_list,
joinrel);
foreach(l, all_pathkeys)
{
List *front_pathkey = (List *) lfirst(l);
...
/* Make a pathkey list with this guy first */
if (l != list_head(all_pathkeys))
outerkeys = lcons(front_pathkey,
...);
else
...
which seems to suggest all_pathkeys is a list of lists, because why else
would front_pathkey be a (List *). But that doesn't seem to be the case,
front_pathkey is actually a PathKey, not a List, as demonstrated by gdb:
(gdb) p *front_pathkey
$2 = {type = T_PathKey, length = 0, ...}
Maybe it's some clever list-fu that I can't comprehend, but I guess it's
a bug present since ~2004. It's benign because we only ever pass the
front_pathkey to lcons() which does not really care.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Commits
-
Correct type of front_pathkey to PathKey
- 72ac4d71b54f 14.2 landed
- 4d8c4d2061f9 13.6 landed
- 93854d5b1bf3 12.10 landed
- 5e9fe2530771 11.15 landed
- a3eb08b809a4 10.20 landed
- 7b65862e2280 15.0 landed