Skip to content

Commit b2d91e8

Browse files
committed
NO SUBCHUNK MATERIALIZATION: fixed a bug in the query constructor
1 parent 90e5b55 commit b2d91e8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/query/WhereClause.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,26 @@ void WhereClause::prependAndTerm(std::shared_ptr<BoolTerm> t) {
141141
throw std::logic_error("Term of first OR term is not an AND term; there is no global AND term");
142142
}
143143
} else {
144-
throw std::logic_error("There is more than term in the root OR term; can't pick a global AND term");
144+
// We've hit the following case:
145+
//
146+
// WHERE ... OR .. OR ...
147+
//
148+
// A solution is to construct the new root and the global AndTerm.
149+
// Push down the current root as the only child of the AndTerm.
150+
// In essence, we're replacing the following constraints:
151+
//
152+
// WHERE ... OR .. OR ...
153+
//
154+
// With:
155+
//
156+
// WHERE <BoolTerm> AND (... OR .. OR ...)
157+
//
158+
auto newRootOrTerm = std::make_shared<OrTerm>();
159+
andTerm = std::make_shared<AndTerm>();
160+
andTerm->addBoolTerm(_rootOrTerm);
161+
newRootOrTerm->addBoolTerm(andTerm);
162+
_rootOrTerm = newRootOrTerm;
163+
andTerm = std::dynamic_pointer_cast<AndTerm>(_rootOrTerm->_terms[0]);
145164
}
146165

147166
if (!andTerm->merge(*t, AndTerm::PREPEND)) {

0 commit comments

Comments
 (0)