@@ -35,37 +35,31 @@ bool VariablePropIndexSeek::matchNode(NodeContext* nodeCtx) {
35
35
if (!whereClause || !whereClause->filter ) return false ;
36
36
37
37
auto filter = whereClause->filter ;
38
- std::string refVarName, propName ;
38
+ std::string refVarName;
39
39
std::shared_ptr<IndexItem> idxItem;
40
40
Expression* indexFilter = nullptr ;
41
41
if (filter->kind () == Expression::Kind::kLogicalAnd ) {
42
42
auto logExpr = static_cast <const LogicalExpression*>(filter);
43
43
bool found = false ;
44
44
for (auto op : logExpr->operands ()) {
45
- if (getIndexItem (nodeCtx, op, label, nodeInfo.alias , &refVarName, &propName, &idxItem)) {
46
- if (!nodeCtx->aliasesAvailable ->count (refVarName)) {
47
- return false ;
48
- }
45
+ if (getIndexItem (nodeCtx, op, label, nodeInfo.alias , &refVarName, &indexFilter, &idxItem)) {
49
46
// TODO(yee): Only select the first index as candidate filter expression and not support
50
47
// the combined index
51
- indexFilter = TagPropertyExpression::make (nodeCtx->qctx ->objPool (), label, propName);
52
48
found = true ;
53
49
break ;
54
50
}
55
51
}
56
52
if (!found) return false ;
57
53
} else {
58
- if (!getIndexItem (nodeCtx, filter, label, nodeInfo.alias , &refVarName, &propName, &idxItem)) {
54
+ if (!getIndexItem (
55
+ nodeCtx, filter, label, nodeInfo.alias , &refVarName, &indexFilter, &idxItem)) {
59
56
return false ;
60
57
}
61
-
62
- if (!nodeCtx->aliasesAvailable ->count (refVarName)) {
63
- return false ;
64
- }
65
-
66
- indexFilter = TagPropertyExpression::make (nodeCtx->qctx ->objPool (), label, propName);
67
58
}
68
59
60
+ if (!nodeCtx->aliasesAvailable ->count (refVarName)) {
61
+ return false ;
62
+ }
69
63
nodeCtx->refVarName = refVarName;
70
64
71
65
nodeCtx->scanInfo .filter = DCHECK_NOTNULL (indexFilter);
@@ -105,7 +99,7 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
105
99
const std::string& label,
106
100
const std::string& alias,
107
101
std::string* refVarName,
108
- std::string* propName ,
102
+ Expression** indexFilter ,
109
103
std::shared_ptr<IndexItem>* idxItem) {
110
104
if (filter->kind () != Expression::Kind::kRelEQ && filter->kind () != Expression::Kind::kRelIn ) {
111
105
return false ;
@@ -117,7 +111,8 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
117
111
return false ;
118
112
}
119
113
120
- if (!MatchSolver::extractTagPropName (relInExpr->left (), alias, label, propName)) {
114
+ std::string propName;
115
+ if (!MatchSolver::extractTagPropName (relInExpr->left (), alias, label, &propName)) {
121
116
return false ;
122
117
}
123
118
// TODO(yee): workaround for index selection
@@ -129,7 +124,7 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
129
124
auto schemaId = itemPtr->get_schema_id ();
130
125
if (schemaId.get_tag_id () == nodeCtx->info ->tids .back ()) {
131
126
const auto & fields = itemPtr->get_fields ();
132
- if (!fields.empty () && fields.front ().get_name () == * propName) {
127
+ if (!fields.empty () && fields.front ().get_name () == propName) {
133
128
idxItemList.push_back (itemPtr);
134
129
}
135
130
}
@@ -140,6 +135,10 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
140
135
});
141
136
*refVarName = static_cast <const LabelExpression*>(right)->name ();
142
137
*idxItem = idxItemList.front ();
138
+ auto objPool = nodeCtx->qctx ->objPool ();
139
+ auto tagPropExpr = TagPropertyExpression::make (objPool, label, propName);
140
+ *indexFilter =
141
+ RelationalExpression::makeKind (objPool, filter->kind (), tagPropExpr, right->clone ());
143
142
return true ;
144
143
}
145
144
0 commit comments