Skip to content

Commit

Permalink
add ReadOnly field in explain result (#535)
Browse files Browse the repository at this point in the history
* add readonly field in explain result

* fix test case error
  • Loading branch information
ljcui authored May 29, 2024
1 parent fec3d91 commit 42925a7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ci/images/tugraph-compile-arm64v8-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr
# tabulate
# if it is not accessible, replace it with the link below
# https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-1.5.tar.gz \
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \
&& tar zxf tabulate-1.5.tar.gz && cp -rf tabulate-1.5/include/tabulate /usr/local/include \
&& rm -rf /tabulate*

Expand Down
2 changes: 1 addition & 1 deletion ci/images/tugraph-compile-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr
# tabulate
# if it is not accessible, replace it with the link below
# https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-1.5.tar.gz \
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \
&& tar zxf tabulate-1.5.tar.gz && cp -rf tabulate-1.5/include/tabulate /usr/local/include \
&& rm -rf /tabulate*

Expand Down
2 changes: 1 addition & 1 deletion ci/images/tugraph-compile-centos8-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr
# tabulate
# if it is not accessible, replace it with the link below
# https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-1.5.tar.gz \
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \
&& tar zxf tabulate-1.5.tar.gz && cp -rf tabulate-1.5/include/tabulate /usr/local/include \
&& rm -rf /tabulate*

Expand Down
2 changes: 1 addition & 1 deletion ci/images/tugraph-compile-ubuntu18.04-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/graphar/Gr
# tabulate
# if it is not accessible, replace it with the link below
# https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-1.5.tar.gz \
RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/tabulate-d553e5.tar.gz \
&& tar zxf tabulate-1.5.tar.gz && cp -rf tabulate-1.5/include/tabulate /usr/local/include \
&& rm -rf /tabulate*

Expand Down
4 changes: 3 additions & 1 deletion src/cypher/execution_plan/execution_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,9 @@ int ExecutionPlan::Execute(RTContext *ctx) {
const ResultInfo &ExecutionPlan::GetResultInfo() const { return _result_info; }

std::string ExecutionPlan::DumpPlan(int indent, bool statistics) const {
std::string s = statistics ? "Profile statistics:\n" : "Execution Plan:\n";
std::string s;
s.append(FMA_FMT("ReadOnly:{}\n", ReadOnly()));
s.append(statistics ? "Profile statistics:\n" : "Execution Plan:\n");
OpBase::DumpStream(_root, indent, statistics, s);
return s;
}
Expand Down
20 changes: 9 additions & 11 deletions src/import/import_v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ void Importer::RocksdbToLmdb() {
EdgeId out_last_eid = -1, in_last_eid = -1;
size_t total_size = 0;
VertexId pre_vid = InvalidVid;
EdgeUid last_uid(-1, -1, 0, -1, -1);

auto throw_kvs_to_lmdb = [&lmdb_writer, &pending_tasks, this, &stage, i]
(std::vector<std::pair<Value, Value>> kvs,
Expand Down Expand Up @@ -1243,6 +1244,7 @@ void Importer::RocksdbToLmdb() {
in_last_dst = -1;
out_last_eid = -1;
in_last_eid = -1;
last_uid = {-1, -1, 0, -1, -1};
};

while (true) {
Expand Down Expand Up @@ -1318,19 +1320,15 @@ void Importer::RocksdbToLmdb() {
uid.lid = labelId;
uid.dst = vertexId;
uid.tid = tid;
if (edge_property.empty()) {
uid.eid = 0;
if (last_uid.src == uid.src &&
last_uid.lid == uid.lid &&
last_uid.dst == uid.dst &&
last_uid.tid == uid.tid) {
uid.eid = last_uid.eid + 1;
} else {
auto& last = edge_property.back();
if (std::get<1>(last).src == uid.src &&
std::get<1>(last).lid == uid.lid &&
std::get<1>(last).dst == uid.dst &&
std::get<1>(last).tid == uid.tid) {
uid.eid = std::get<1>(last).eid + 1;
} else {
uid.eid = 0;
}
uid.eid = 0;
}
last_uid = uid;
edge_property.emplace_back(
labelId, uid, Value::MakeCopy(val.data(), val.size()));
outs.emplace_back(labelId, tid, vertexId, import_v2::DenseString());
Expand Down
38 changes: 19 additions & 19 deletions test/cypher_plan_validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,107 +8,107 @@
"vid": [
{
"query": "MATCH (n) WHERE id(n)=10 RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node By Id Seek[10,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node By Id Seek[10,]\n",
"res": 1
},
{
"query": "MATCH (n) WHERE id(n) IN [1,2,4] RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node By Id Seek[1,2,4,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node By Id Seek[1,2,4,]\n",
"res": 3
},
{
"query": "MATCH (n) WHERE id(n)=1 OR id(n)=3 OR id(n)=4 OR id(n)=18 OR id(n)=1111 RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node By Id Seek[1,3,4,18,1111,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node By Id Seek[1,3,4,18,1111,]\n",
"res": 4
},
{
"query": "MATCH (n) WHERE id(n)=1 OR id(n)=3 AND id(n)=4 OR id(n)=18 OR id(n)=1111 RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Filter [((({id(false,n) = 1}||({id(false,n) = 3}&&{id(false,n) = 4}))||{id(false,n) = 18})||{id(false,n) = 1111})]\n All Node Scan [n]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Filter [((({id(false,n) = 1}||({id(false,n) = 3}&&{id(false,n) = 4}))||{id(false,n) = 18})||{id(false,n) = 1111})]\n All Node Scan [n]\n",
"res": 2
}
],
"uid": [
{
"query": "MATCH (n) where n.name=\"Rachel Kempson\" RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,]\n",
"res": 1
},
{
"query": "MATCH (n) where n.name in [\"Rachel Kempson\",\"Dennis Quaid\",\"none\"] RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,Dennis Quaid,none,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,Dennis Quaid,none,]\n",
"res": 2
},
{
"query": "MATCH (n) where n.name =\"Rachel Kempson\" or n.name= \"Dennis Quaid\" or n.name=\"none\" RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,Dennis Quaid,none,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,Dennis Quaid,none,]\n",
"res": 2
},
{
"query": "MATCH (n) where n.name = \"Rachel Kempson\" and n.name = \"Dennis Quaid\" or n.name = \"Vanessa Redgrave\" RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Filter [(({n.name = Rachel Kempson}&&{n.name = Dennis Quaid})||{n.name = Vanessa Redgrave})]\n All Node Scan [n]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Filter [(({n.name = Rachel Kempson}&&{n.name = Dennis Quaid})||{n.name = Vanessa Redgrave})]\n All Node Scan [n]\n",
"res": 1
},
{
"query": "MATCH (n) where n.name = \"Rachel Kempson\" or n.name = \"Dennis Quaid\" or n.name = \"Vanessa Redgrave\" RETURN n",
"plan": "Execution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,Dennis Quaid,Vanessa Redgrave,]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Node Index Seek [n] name IN [Rachel Kempson,Dennis Quaid,Vanessa Redgrave,]\n",
"res": 3
}
],
"list": [
{
"query": "MATCH (n) RETURN id(n),label(n),properties(n);",
"plan": "Execution Plan:\nProduce Results\n Project [id(n),label(n),properties(n)]\n All Node Scan [n]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [id(n),label(n),properties(n)]\n All Node Scan [n]\n",
"res": 21
}
],
"parallel_traversal": [
{
"query": "MATCH (n:Person) return count(n)",
"plan": "Execution Plan:\nProduce Results\n Traversal [n]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Traversal [n]\n",
"res": 1
},
{
"query": "MATCH (n:Person) where n.birthyear > 1900 and n.birthyear < 2000 return count(n) ",
"plan": "Execution Plan:\nProduce Results\n Traversal [n]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Traversal [n]\n",
"res": 1
},
{
"query": "MATCH (n:Person) return n.birthyear, count(n)",
"plan": "Execution Plan:\nProduce Results\n Traversal [n]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Traversal [n]\n",
"res": 13
},
{
"query": "MATCH (f:Film)<-[:ACTED_IN]-(p:Person)-[:BORN_IN]->(c:City) return c.name, count(f)",
"plan": "Execution Plan:\nProduce Results\n Traversal [f<--p-->c]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Traversal [f<--p-->c]\n",
"res": 3
}
],
"issue148": [
{
"query": "WITH 'a' as a UNWIND ['a', 'b'] as k RETURN a, k",
"plan": "Execution Plan:\nProduce Results\n Project [a,k]\n Cartesian Product\n Unwind [[a,b],k]\n Project [a]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [a,k]\n Cartesian Product\n Unwind [[a,b],k]\n Project [a]\n",
"res": 2
},
{
"query": "WITH 'a' as a UNWIND ['b']+a as k RETURN a, k",
"plan": "Execution Plan:\nProduce Results\n Project [a,k]\n Apply\n Unwind [([b],a,+),k]\n Argument [a]\n Project [a]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Project [a,k]\n Apply\n Unwind [([b],a,+),k]\n Argument [a]\n Project [a]\n",
"res": 2
}
],
"schema_rewrite": [
{
"query": "MATCH p=(n1)-[r1]->(n2)-[r2]->(m:Person) return count(p)",
"plan": "Execution Plan:\nProduce Results\n Aggregate [count(p)]\n Expand(All) [n2 --> m ]\n Expand(All) [n1 --> n2 ]\n Node By Label Scan [n1:Person]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Aggregate [count(p)]\n Expand(All) [n2 --> m ]\n Expand(All) [n1 --> n2 ]\n Node By Label Scan [n1:Person]\n",
"res": 1
},
{
"query": "MATCH p1=(n1)-[r1]->(n2)-[r2]->(m1:City),p2=(n3)-[r3]->(m2:Film) return count(p1)",
"plan": "Execution Plan:\nProduce Results\n Aggregate [count(p1)]\n Cartesian Product\n Expand(All) [n2 --> m1 ]\n Expand(All) [n1 --> n2 ]\n Node By Label Scan [n1:Person]\n Expand(All) [n3 --> m2 ]\n Node By Label Scan [n3:Person]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Aggregate [count(p1)]\n Cartesian Product\n Expand(All) [n2 --> m1 ]\n Expand(All) [n1 --> n2 ]\n Node By Label Scan [n1:Person]\n Expand(All) [n3 --> m2 ]\n Node By Label Scan [n3:Person]\n",
"res": 1
},
{
"query": "MATCH p1=(n1)-[r1]->(n2)-[r2]->(m1:City) with count(p1) as cp match p1=(n1)-[r1]->(m1:Film) return count(p1)",
"plan": "Execution Plan:\nProduce Results\n Aggregate [count(p1)]\n Apply\n Expand(All) [n1 --> m1 ]\n Node By Label Scan Dynamic [n1:Person]\n Argument [cp]\n Aggregate [cp]\n Expand(All) [n2 --> m1 ]\n Expand(All) [n1 --> n2 ]\n Node By Label Scan [n1:Person]\n",
"plan": "ReadOnly:1\nExecution Plan:\nProduce Results\n Aggregate [count(p1)]\n Apply\n Expand(All) [n1 --> m1 ]\n Node By Label Scan Dynamic [n1:Person]\n Argument [cp]\n Aggregate [cp]\n Expand(All) [n2 --> m1 ]\n Expand(All) [n1 --> n2 ]\n Node By Label Scan [n1:Person]\n",
"res": 1
}
]
Expand Down
4 changes: 3 additions & 1 deletion test/test_lgraph_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ created 0 vertices, created 1 edges.
n
(:person {int16:16,float:1.11,double:100.98,int8:8,string:"foo bar",int32:32,int64:64,bool:true,datetime:1493632800000000000,date:17289})
@plan
ReadOnly:1
Execution Plan:
Produce Results
Project [n]
Expand Down Expand Up @@ -156,7 +157,7 @@ p
["n"]
["(:person {int16:16,float:1.11,double:100.98,int8:8,string:\"foo bar\",int32:32,int64:64,bool:true,datetime:1493632800000000000,date:17289})"]
["@plan"]
["Execution Plan:\nProduce Results\n Project [n]\n Expand(All) [n --> m ]\n Node By Label Scan [n:person]\n"]
["ReadOnly:1\nExecution Plan:\nProduce Results\n Project [n]\n Expand(All) [n --> m ]\n Node By Label Scan [n:person]\n"]
["r"]
["[:is_friend {message:\"hi..\"}]"]
["@profile"]
Expand Down Expand Up @@ -228,6 +229,7 @@ p
+-------------------------------------------+
| @plan |
+-------------------------------------------+
| ReadOnly:1 |
| Execution Plan: |
| Produce Results |
| Project [n] |
Expand Down

0 comments on commit 42925a7

Please sign in to comment.