| 319 | } |
| 320 | |
| 321 | std::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 | |
| 365 | std::shared_ptr<LogicalOperator> CountRelTableOptimizer::visitOrderByReplace( |
| 366 | std::shared_ptr<LogicalOperator> op) { |
nothing calls this directly
no test coverage detected