MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / tryRewriteActiveBoundCount

Method tryRewriteActiveBoundCount

src/optimizer/count_rel_table_optimizer.cpp:321–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319}
320
321std::shared_ptr<LogicalOperator> CountRelTableOptimizer::tryRewriteActiveBoundCount(
322 std::shared_ptr<LogicalOperator> op) {
323 auto* current = op->getChild(0).get();
324 while (current->getOperatorType() == LogicalOperatorType::PROJECTION) {
325 current = current->getChild(0).get();
326 }
327 if (current->getOperatorType() != LogicalOperatorType::EXTEND) {
328 return op;
329 }
330 auto& extend = current->constCast<LogicalExtend>();
331 auto boundNode = extend.getBoundNode();
332 if (boundNode->isMultiLabeled()) {
333 return op;
334 }
335 auto boundKey = boundNode->getPrimaryKey(boundNode->getTableIDs()[0]);
336 if (!boundKey || !isDistinctCountNodeKey(op.get(), boundKey)) {
337 return op;
338 }
339 if (!extend.getProperties().empty()) {
340 return op;
341 }
342 auto* scan = current->getChild(0).get();
343 if (scan->getOperatorType() != LogicalOperatorType::SCAN_NODE_TABLE) {
344 return op;
345 }
346 auto& scanNode = scan->constCast<LogicalScanNodeTable>();
347 for (auto& property : scanNode.getProperties()) {
348 if (!(*property == *boundKey)) {
349 return op;
350 }
351 }
352 std::vector<table_id_t> relTableIDs;
353 RelGroupCatalogEntry* relGroupEntry = nullptr;
354 if (!relTablesForExtend(extend, relTableIDs, relGroupEntry)) {
355 return op;
356 }
357 auto countExpr = op->constCast<LogicalAggregate>().getAggregates()[0];
358 auto result =
359 std::make_shared<LogicalRelDegreeTable>(relGroupEntry, std::move(relTableIDs), boundNode,
360 extend.getDirection(), RelDegreeTableMode::ACTIVE_BOUND_COUNT, boundKey, countExpr, 1);
361 result->computeFlatSchema();
362 return result;
363}
364
365std::shared_ptr<LogicalOperator> CountRelTableOptimizer::visitOrderByReplace(
366 std::shared_ptr<LogicalOperator> op) {

Callers

nothing calls this directly

Calls 12

relTablesForExtendFunction · 0.85
isMultiLabeledMethod · 0.80
getPrimaryKeyMethod · 0.80
getAggregatesMethod · 0.80
getMethod · 0.45
getChildMethod · 0.45
getBoundNodeMethod · 0.45
getTableIDsMethod · 0.45
emptyMethod · 0.45
getPropertiesMethod · 0.45
getDirectionMethod · 0.45
computeFlatSchemaMethod · 0.45

Tested by

no test coverage detected