diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2023-12-18 12:53:50 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2023-12-18 12:53:50 +0000 |
commit | e83f2ba4fb649a31b5a9656dbc471d3caf55ba84 (patch) | |
tree | efc9568b4c31c282511ba65bec7355c002c9515c /searchlib/src | |
parent | ce02fe1d45877ec7543e35d9a87ac65f9f8744e3 (diff) |
do nested collapsing of AND when collapsing ANDNOT
this is needed since the AND getting the extra AND as a child has
already been processed for the optimize pass that performs AND
collapsing.
Diffstat (limited to 'searchlib/src')
-rw-r--r-- | searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp | 16 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp | 9 |
2 files changed, 24 insertions, 1 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index e24e91c2f1d..53803c9c9e7 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -716,6 +716,22 @@ TEST("AND_NOT AND AND_NOT collapsing") { optimize_and_compare(std::move(top), std::move(expect)); } +TEST("AND_NOT AND AND_NOT AND nested collapsing") { + Blueprint::UP top = make::ANDNOT() + .add(make::AND() + .add(make::ANDNOT() + .add(make::AND().leafs({1,2})) + .leafs({5,6})) + .add(make::ANDNOT() + .add(make::AND().leafs({3,4})) + .leafs({8,9}))) + .leaf(7); + Blueprint::UP expect = make::ANDNOT() + .add(make::AND().leafs({1,2,3,4})) + .leafs({9,8,7,6,5}); + optimize_and_compare(std::move(top), std::move(expect)); +} + TEST("AND_NOT AND AND_NOT collapsing into full source blender optimization") { InvalidSelector sel; Blueprint::UP top = diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp index c43335a6fdf..364602cba03 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp @@ -133,7 +133,14 @@ AndNotBlueprint::optimize_self(OptimizePass pass) while (grand_child->childCnt() > 1) { addChild(grand_child->removeLastChild()); } - child->addChild(grand_child->removeChild(0)); + auto orphan = grand_child->removeChild(0); + if (auto *orphan_and = orphan->asAnd()) { + while (orphan_and->childCnt() > 0) { + child->addChild(orphan_and->removeLastChild()); + } + } else { + child->addChild(std::move(orphan)); + } child->removeChild(i--); } } |