From 835bb975d8d11268582d9dbd26b0eeaa62b60632 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 29 Jun 2003 23:05:05 +0000 Subject: Restructure building of join relation targetlists so that a join plan node emits only those vars that are actually needed above it in the plan tree. (There were comments in the code suggesting that this was done at some point in the dim past, but for a long time we have just made join nodes emit everything that either input emitted.) Aside from being marginally more efficient, this fixes the problem noted by Peter Eisentraut where a join above an IN-implemented-as-join might fail, because the subplan targetlist constructed in the latter case didn't meet the expectation of including everything. Along the way, fix some places that were O(N^2) in the targetlist length. This is not all the trouble spots for wide queries by any means, but it's a step forward. --- src/backend/nodes/bitmapset.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/backend/nodes/bitmapset.c') diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c index 5798b726497..45c6ead0fc0 100644 --- a/src/backend/nodes/bitmapset.c +++ b/src/backend/nodes/bitmapset.c @@ -14,7 +14,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/bitmapset.c,v 1.1 2003/02/08 20:20:53 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/bitmapset.c,v 1.2 2003/06/29 23:05:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -388,6 +388,36 @@ bms_overlap(const Bitmapset *a, const Bitmapset *b) return false; } +/* + * bms_nonempty_difference - do sets have a nonempty difference? + */ +bool +bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b) +{ + int shortlen; + int i; + + /* Handle cases where either input is NULL */ + if (a == NULL) + return false; + if (b == NULL) + return !bms_is_empty(a); + /* Check words in common */ + shortlen = Min(a->nwords, b->nwords); + for (i = 0; i < shortlen; i++) + { + if ((a->words[i] & ~ b->words[i]) != 0) + return true; + } + /* Check extra words in a */ + for (; i < a->nwords; i++) + { + if (a->words[i] != 0) + return true; + } + return false; +} + /* * bms_singleton_member - return the sole integer member of set * -- cgit v1.2.3