forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariablePropIndexSeek.cpp
67 lines (53 loc) · 2.1 KB
/
VariablePropIndexSeek.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright (c) 2023 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/
#include "graph/planner/match/VariablePropIndexSeek.h"
#include "graph/planner/match/MatchSolver.h"
#include "graph/planner/plan/Logic.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"
namespace nebula {
namespace graph {
bool VariablePropIndexSeek::matchNode(NodeContext* nodeCtx) {
const auto& labels = nodeCtx->info->labels;
if (labels.size() != 1) {
// TODO multiple tag index seek need the IndexScan support
VLOG(2) << "Multiple tag index seek is not supported now.";
return false;
}
auto whereClause = nodeCtx->bindWhereClause;
if (!whereClause || !whereClause->filter) return false;
// auto qctx = nodeCtx->qctx;
auto newFilter = ExpressionUtils::rewriteInnerInExpr(whereClause->filter);
auto filter = newFilter;
// auto filter = MatchSolver::rewriteTagIndexFilter(
// labels.back(), nodeInfo.alias, newFilter, qctx, &nodeCtx->refVarName);
if (!filter) return false;
nodeCtx->scanInfo.filter = filter;
nodeCtx->scanInfo.schemaIds = nodeInfo.tids;
nodeCtx->scanInfo.schemaNames = nodeInfo.labels;
return true;
}
StatusOr<SubPlan> VariablePropIndexSeek::transformNode(NodeContext* nodeCtx) {
SubPlan plan;
const auto& schemaIds = nodeCtx->scanInfo.schemaIds;
DCHECK_EQ(schemaIds.size(), 1u) << "Not supported multiple tag properties seek.";
auto qctx = nodeCtx->qctx;
auto argument = Argument::make(qctx, nodeCtx->refVarName);
argument->setColNames({nodeCtx->refVarName});
using IQC = nebula::storage::cpp2::IndexQueryContext;
IQC iqctx;
iqctx.filter_ref() = Expression::encode(*nodeCtx->scanInfo.filter);
auto scan =
IndexScan::make(qctx, argument, nodeCtx->spaceId, {iqctx}, {kVid}, false, schemaIds.back());
scan->setColNames({kVid});
plan.tail = argument;
plan.root = scan;
// initialize start expression in project node
auto* pool = nodeCtx->qctx->objPool();
nodeCtx->initialExpr = VariablePropertyExpression::make(pool, "", kVid);
return plan;
}
} // namespace graph
} // namespace nebula