| 20 | } |
| 21 | |
| 22 | void LimitPushDownOptimizer::visitOperator(planner::LogicalOperator* op) { |
| 23 | switch (op->getOperatorType()) { |
| 24 | case LogicalOperatorType::LIMIT: { |
| 25 | auto& limit = op->constCast<LogicalLimit>(); |
| 26 | if (limit.hasSkipNum() && ExpressionUtil::canEvaluateAsLiteral(*limit.getSkipNum())) { |
| 27 | skipNumber = ExpressionUtil::evaluateAsSkipLimit(*limit.getSkipNum()); |
| 28 | } |
| 29 | if (limit.hasLimitNum() && ExpressionUtil::canEvaluateAsLiteral(*limit.getLimitNum())) { |
| 30 | limitNumber = ExpressionUtil::evaluateAsSkipLimit(*limit.getLimitNum()); |
| 31 | } |
| 32 | visitOperator(limit.getChild(0).get()); |
| 33 | return; |
| 34 | } |
| 35 | case LogicalOperatorType::MULTIPLICITY_REDUCER: |
| 36 | case LogicalOperatorType::EXPLAIN: |
| 37 | case LogicalOperatorType::ACCUMULATE: |
| 38 | case LogicalOperatorType::FILTER: |
| 39 | case LogicalOperatorType::PROJECTION: { |
| 40 | visitOperator(op->getChild(0).get()); |
| 41 | return; |
| 42 | } |
| 43 | case LogicalOperatorType::TABLE_FUNCTION_CALL: { |
| 44 | if (limitNumber == INVALID_LIMIT && skipNumber == 0) { |
| 45 | return; |
| 46 | } |
| 47 | auto& tableFuncCall = op->cast<LogicalTableFunctionCall>(); |
| 48 | if (tableFuncCall.getTableFunc().supportsPushDownFunc()) { |
| 49 | tableFuncCall.setLimitNum(skipNumber + limitNumber); |
| 50 | } |
| 51 | return; |
| 52 | } |
| 53 | case LogicalOperatorType::DISTINCT: { |
| 54 | if (limitNumber == INVALID_LIMIT && skipNumber == 0) { |
| 55 | return; |
| 56 | } |
| 57 | auto& distinctOp = op->cast<LogicalDistinct>(); |
| 58 | distinctOp.setLimitNum(limitNumber); |
| 59 | distinctOp.setSkipNum(skipNumber); |
| 60 | return; |
| 61 | } |
| 62 | case LogicalOperatorType::HASH_JOIN: { |
| 63 | if (limitNumber == INVALID_LIMIT && skipNumber == 0) { |
| 64 | return; |
| 65 | } |
| 66 | if (op->getChild(0)->getOperatorType() == LogicalOperatorType::HASH_JOIN) { |
| 67 | op->ptrCast<LogicalHashJoin>()->getSIPInfoUnsafe().position = SemiMaskPosition::NONE; |
| 68 | // OP is the hash join reading destination node property. Continue push limit down. |
| 69 | op = op->getChild(0).get(); |
| 70 | } |
| 71 | if (op->getChild(0)->getOperatorType() == LogicalOperatorType::PATH_PROPERTY_PROBE) { |
| 72 | // LCOV_EXCL_START |
| 73 | if (op->getChild(0)->getChild(0)->getOperatorType() != |
| 74 | LogicalOperatorType::RECURSIVE_EXTEND) { |
| 75 | throw RuntimeException("Trying to push limit to a non RECURSIVE_EXTEND operator. " |
| 76 | "This should never happen."); |
| 77 | } |
| 78 | // LCOV_EXCL_STOP |
| 79 | auto& extend = op->getChild(0)->getChild(0)->cast<LogicalRecursiveExtend>(); |
nothing calls this directly
no test coverage detected