Skip to content

Commit 03008de

Browse files
committed
Rework my fix for #5654: Could not execute query (select from view with nested view) -- the original solution was too restrictive, causing regressions in plans/performance
1 parent c922856 commit 03008de

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/jrd/opt.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,14 +1498,15 @@ static USHORT distribute_equalities(BoolExprNodeStack& org_stack, CompilerScratc
14981498
*
14991499
**************************************/
15001500

1501-
// dimitr: Dumb protection against too many injected conjuncts (see CORE-5381).
1502-
// Don't produce more additional conjuncts than we originally had
1503-
// (i.e. this routine should never more than double the number of conjuncts).
1504-
// Ideally, we need two separate limits here:
1505-
// 1) number of injected conjuncts (affects required impure size)
1506-
// 2) number of input conjuncts (affects search time inside this routine)
1507-
1508-
if (base_count * 2 > MAX_CONJUNCTS)
1501+
// dimitr: Simplified protection against too many injected conjuncts (see CORE-5381).
1502+
// Two separate limits are applied here:
1503+
// 1) number of input conjuncts (affects search time inside this routine)
1504+
// 2) number of injected conjuncts (affects required impure size)
1505+
1506+
constexpr unsigned MAX_CONJUNCTS_TO_PROCESS = 1024;
1507+
const unsigned MAX_CONJUNCTS_TO_INJECT = MAX(base_count, 256);
1508+
1509+
if (base_count > MAX_CONJUNCTS_TO_PROCESS)
15091510
return 0;
15101511

15111512
ObjectsArray<ValueExprNodeStack> classes;
@@ -1592,7 +1593,7 @@ static USHORT distribute_equalities(BoolExprNodeStack& org_stack, CompilerScratc
15921593
{
15931594
for (ValueExprNodeStack::iterator inner(outer); (++inner).hasData(); )
15941595
{
1595-
if (count < base_count)
1596+
if (count < MAX_CONJUNCTS_TO_INJECT)
15961597
{
15971598
AutoPtr<ComparativeBoolNode> cmpNode(FB_NEW_POOL(csb->csb_pool)
15981599
ComparativeBoolNode(csb->csb_pool, blr_eql));
@@ -1653,7 +1654,7 @@ static USHORT distribute_equalities(BoolExprNodeStack& org_stack, CompilerScratc
16531654
{
16541655
for (ValueExprNodeStack::iterator temp(*eq_class); temp.hasData(); ++temp)
16551656
{
1656-
if (!node_equality(node1, temp.object()) && count < base_count)
1657+
if (!node_equality(node1, temp.object()) && count < MAX_CONJUNCTS_TO_INJECT)
16571658
{
16581659
ValueExprNode* arg1;
16591660
ValueExprNode* arg2;

0 commit comments

Comments
 (0)