Skip to content

Skip NULL keys in strong equality hash and merge joins #8557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/jrd/RecordSourceNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class SortNode : public Firebird::PermanentStorage, public Printable
public:
explicit SortNode(MemoryPool& pool)
: PermanentStorage(pool),
unique(false),
expressions(pool),
direction(pool),
nullOrder(pool)
Expand All @@ -76,15 +75,17 @@ class SortNode : public Firebird::PermanentStorage, public Printable
{
if (direction[index] == ORDER_ASC)
return (nullOrder[index] == NULLS_DEFAULT) ? NULLS_FIRST : nullOrder[index];
else if (direction[index] == ORDER_DESC)

if (direction[index] == ORDER_DESC)
return (nullOrder[index] == NULLS_DEFAULT) ? NULLS_LAST : nullOrder[index];

fb_assert(false);
return NULLS_DEFAULT;
}

public:
bool unique; // sort uses unique key - for DISTINCT and GROUP BY
bool unique = false; // sort uses unique key - for DISTINCT and GROUP BY
bool ignoreNulls = false; // sort skips NULL keys
NestValueArray expressions; // sort expressions
Firebird::Array<SortDirection> direction; // rse_order_*
Firebird::Array<NullsPlacement> nullOrder; // rse_nulls_*
Expand Down
10 changes: 8 additions & 2 deletions src/jrd/optimizer/InnerJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,15 @@ River* InnerJoin::formRiver()
keys.add(FB_NEW_POOL(getPool()) NestValueArray(getPool()));
keys.add(FB_NEW_POOL(getPool()) NestValueArray(getPool()));

bool ignoreNulls = true;

for (const auto match : stream.equiMatches)
{
NestConst<ValueExprNode> node1;
NestConst<ValueExprNode> node2;
UCHAR blrOp;

if (!optimizer->getEquiJoinKeys(match, &node1, &node2))
if (!optimizer->getEquiJoinKeys(match, &node1, &node2, &blrOp))
fb_assert(false);

if (!node2->containsStream(stream.number))
Expand All @@ -565,6 +568,9 @@ River* InnerJoin::formRiver()
keys[1]->add(node2);

equiMatches.add(match);

if (blrOp == blr_equiv)
ignoreNulls = false;
}

// Ensure the smallest stream is the one to be hashed,
Expand All @@ -580,7 +586,7 @@ River* InnerJoin::formRiver()

// Create a hash join
rsb = FB_NEW_POOL(getPool())
HashJoin(tdbb, csb, INNER_JOIN, 2, hashJoinRsbs, keys.begin(), stream.selectivity);
HashJoin(tdbb, csb, INNER_JOIN, ignoreNulls, 2, hashJoinRsbs, keys.begin(), stream.selectivity);

// Clear priorly processed rsb's, as they're already incorporated into a hash join
rsbs.clear();
Expand Down
Loading
Loading