MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / decomposeBoolean

Method decomposeBoolean

src/jrd/optimizer/Optimizer.cpp:1264–1355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1262//
1263
1264unsigned Optimizer::decomposeBoolean(BoolExprNode* boolNode, BoolExprNodeStack& stack)
1265{
1266 if (const auto binaryNode = nodeAs<BinaryBoolNode>(boolNode))
1267 {
1268 if (binaryNode->blrOp == blr_and)
1269 {
1270 auto count = decomposeBoolean(binaryNode->arg1, stack);
1271 count += decomposeBoolean(binaryNode->arg2, stack);
1272 return count;
1273 }
1274 else if (binaryNode->blrOp == blr_or)
1275 {
1276 BoolExprNodeStack or_stack;
1277
1278 if (decomposeBoolean(binaryNode->arg1, or_stack) >= 2)
1279 {
1280 binaryNode->arg1 = or_stack.pop();
1281
1282 while (or_stack.hasData())
1283 {
1284 const auto newBoolNode =
1285 FB_NEW_POOL(getPool()) BinaryBoolNode(getPool(), blr_and);
1286 newBoolNode->arg1 = or_stack.pop();
1287 newBoolNode->arg2 = binaryNode->arg1;
1288
1289 binaryNode->arg1 = newBoolNode;
1290 }
1291 }
1292
1293 or_stack.clear();
1294
1295 if (decomposeBoolean(binaryNode->arg2, or_stack) >= 2)
1296 {
1297 binaryNode->arg2 = or_stack.pop();
1298
1299 while (or_stack.hasData())
1300 {
1301 const auto newBoolNode =
1302 FB_NEW_POOL(getPool()) BinaryBoolNode(getPool(), blr_and);
1303 newBoolNode->arg1 = or_stack.pop();
1304 newBoolNode->arg2 = binaryNode->arg2;
1305
1306 binaryNode->arg2 = newBoolNode;
1307 }
1308 }
1309 }
1310 }
1311 else if (const auto cmpNode = nodeAs<ComparativeBoolNode>(boolNode))
1312 {
1313 // turn a between into (a greater than or equal) AND (a less than or equal)
1314
1315 if (cmpNode->blrOp == blr_between)
1316 {
1317 auto newCmpNode = FB_NEW_POOL(getPool()) ComparativeBoolNode(getPool(), blr_geq);
1318 newCmpNode->arg1 = cmpNode->arg1;
1319 newCmpNode->arg2 = cmpNode->arg2;
1320
1321 stack.push(newCmpNode);

Callers 1

checkIndexConditionMethod · 0.80

Calls 7

CMP_clone_node_optFunction · 0.85
ComparativeBoolNodeClass · 0.70
BinaryBoolNodeClass · 0.50
popMethod · 0.45
hasDataMethod · 0.45
clearMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected