Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
fa4aa1fe
Commit
fa4aa1fe
authored
2 years ago
by
Igor Kuznetsov
Browse files
Options
Downloads
Patches
Plain Diff
feat: add test `insert` operator to explain
parent
5d6e92d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1414
sbroad import
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ir/explain.rs
+52
-7
52 additions, 7 deletions
src/ir/explain.rs
src/ir/explain/tests.rs
+87
-0
87 additions, 0 deletions
src/ir/explain/tests.rs
with
139 additions
and
7 deletions
src/ir/explain.rs
+
52
−
7
View file @
fa4aa1fe
...
@@ -450,6 +450,9 @@ impl Display for InnerJoin {
...
@@ -450,6 +450,9 @@ impl Display for InnerJoin {
enum
ExplainNode
{
enum
ExplainNode
{
Except
,
Except
,
InnerJoin
(
InnerJoin
),
InnerJoin
(
InnerJoin
),
ValueRow
(
Row
),
Value
,
Insert
(
String
),
Projection
(
Projection
),
Projection
(
Projection
),
Scan
(
Scan
),
Scan
(
Scan
),
Selection
(
Selection
),
Selection
(
Selection
),
...
@@ -463,6 +466,9 @@ impl Display for ExplainNode {
...
@@ -463,6 +466,9 @@ impl Display for ExplainNode {
let
s
=
match
&
self
{
let
s
=
match
&
self
{
ExplainNode
::
Except
=>
"except"
.to_string
(),
ExplainNode
::
Except
=>
"except"
.to_string
(),
ExplainNode
::
InnerJoin
(
i
)
=>
i
.to_string
(),
ExplainNode
::
InnerJoin
(
i
)
=>
i
.to_string
(),
ExplainNode
::
ValueRow
(
r
)
=>
format!
(
"value row (data={})"
,
r
),
ExplainNode
::
Value
=>
"values"
.to_string
(),
ExplainNode
::
Insert
(
s
)
=>
format!
(
"insert {}"
,
s
),
ExplainNode
::
Projection
(
e
)
=>
e
.to_string
(),
ExplainNode
::
Projection
(
e
)
=>
e
.to_string
(),
ExplainNode
::
Scan
(
s
)
=>
s
.to_string
(),
ExplainNode
::
Scan
(
s
)
=>
s
.to_string
(),
ExplainNode
::
Selection
(
s
)
=>
format!
(
"selection {}"
,
s
),
ExplainNode
::
Selection
(
s
)
=>
format!
(
"selection {}"
,
s
),
...
@@ -732,13 +738,52 @@ impl FullExplain {
...
@@ -732,13 +738,52 @@ impl FullExplain {
let
condition
=
Selection
::
new
(
ir
,
*
condition
,
&
sq_ref_map
)
?
;
let
condition
=
Selection
::
new
(
ir
,
*
condition
,
&
sq_ref_map
)
?
;
Some
(
ExplainNode
::
InnerJoin
(
InnerJoin
{
condition
}))
Some
(
ExplainNode
::
InnerJoin
(
InnerJoin
{
condition
}))
}
}
Relational
::
Insert
{
..
}
Relational
::
ValuesRow
{
data
,
children
,
..
}
=>
{
|
Relational
::
Values
{
..
}
let
mut
sq_ref_map
:
HashMap
<
usize
,
usize
>
=
|
Relational
::
ValuesRow
{
..
}
=>
{
HashMap
::
with_capacity
(
children
.len
());
return
Err
(
QueryPlannerError
::
CustomError
(
format!
(
"Explain hasn't supported node {:?} yet"
,
for
sq_id
in
children
.iter
()
.rev
()
{
node
let
sq_node
=
stack
.pop
()
.ok_or_else
(||
{
)))
QueryPlannerError
::
CustomError
(
"Insert node failed to get a sub-query."
.into
(),
)
})
?
;
result
.subqueries
.push
(
sq_node
);
let
offset
=
result
.subqueries
.len
()
-
1
;
sq_ref_map
.insert
(
*
sq_id
,
offset
);
}
let
values
=
ir
.get_expression_node
(
*
data
)
?
.get_row_list
()
?
;
let
row
=
Row
::
from_ir_nodes
(
ir
,
values
,
&
sq_ref_map
)
?
;
Some
(
ExplainNode
::
ValueRow
(
row
))
}
Relational
::
Values
{
children
,
..
}
=>
{
let
mut
amount_values
=
children
.len
();
while
amount_values
>
0
{
let
value_row
=
stack
.pop
()
.ok_or_else
(||
{
QueryPlannerError
::
CustomError
(
"Insert node failed to get a value row."
.into
(),
)
})
?
;
current_node
.children
.insert
(
0
,
value_row
);
amount_values
-=
1
;
}
Some
(
ExplainNode
::
Value
)
}
Relational
::
Insert
{
relation
,
..
}
=>
{
let
values
=
stack
.pop
()
.ok_or_else
(||
{
QueryPlannerError
::
CustomError
(
"Insert node failed to get a value row."
.into
(),
)
})
?
;
current_node
.children
.push
(
values
);
Some
(
ExplainNode
::
Insert
(
relation
.into
()))
}
}
};
};
stack
.push
(
current_node
);
stack
.push
(
current_node
);
...
...
This diff is collapsed.
Click to expand it.
src/ir/explain/tests.rs
+
87
−
0
View file @
fa4aa1fe
...
@@ -302,3 +302,90 @@ fn unary_condition_plan() {
...
@@ -302,3 +302,90 @@ fn unary_condition_plan() {
assert_eq!
(
actual_explain
,
explain_tree
.to_string
())
assert_eq!
(
actual_explain
,
explain_tree
.to_string
())
}
}
#[test]
fn
insert_plan
()
{
let
query
=
r#"INSERT INTO "test_space" ("id", "FIRST_NAME") VALUES (1, '123')"#
;
let
plan
=
sql_to_optimized_ir
(
query
,
vec!
[]);
let
top
=
&
plan
.get_top
()
.unwrap
();
let
explain_tree
=
FullExplain
::
new
(
&
plan
,
*
top
)
.unwrap
();
let
mut
actual_explain
=
String
::
new
();
actual_explain
.push_str
(
r#"insert "test_space"
motion [policy: segment([ref(COLUMN_1)]), generation: sharding_column]
values
value row (data=ROW(1, '123'))
"#
,
);
assert_eq!
(
actual_explain
,
explain_tree
.to_string
())
}
#[test]
fn
multiply_insert_plan
()
{
let
query
=
r#"INSERT INTO "test_space" ("id", "FIRST_NAME") VALUES (1, '123'), (2, '456'), (3, '789')"#
;
let
plan
=
sql_to_optimized_ir
(
query
,
vec!
[]);
let
top
=
&
plan
.get_top
()
.unwrap
();
let
explain_tree
=
FullExplain
::
new
(
&
plan
,
*
top
)
.unwrap
();
let
mut
actual_explain
=
String
::
new
();
actual_explain
.push_str
(
r#"insert "test_space"
motion [policy: segment([ref(COLUMN_5)]), generation: sharding_column]
values
value row (data=ROW(1, '123'))
value row (data=ROW(2, '456'))
value row (data=ROW(3, '789'))
"#
,
);
assert_eq!
(
actual_explain
,
explain_tree
.to_string
())
}
#[test]
fn
insert_select_plan
()
{
let
query
=
r#"INSERT INTO "test_space" ("id", "FIRST_NAME")
SELECT "identification_number", "product_code" FROM "hash_testing""#
;
let
plan
=
sql_to_optimized_ir
(
query
,
vec!
[]);
let
top
=
&
plan
.get_top
()
.unwrap
();
let
explain_tree
=
FullExplain
::
new
(
&
plan
,
*
top
)
.unwrap
();
let
mut
actual_explain
=
String
::
new
();
actual_explain
.push_str
(
r#"insert "test_space"
motion [policy: segment([ref("identification_number")]), generation: sharding_column]
projection ("hash_testing"."identification_number" -> "identification_number", "hash_testing"."product_code" -> "product_code")
scan "hash_testing"
"#
,
);
assert_eq!
(
actual_explain
,
explain_tree
.to_string
())
}
#[test]
fn
select_value_plan
()
{
let
query
=
r#"select * from (values (1))"#
;
let
plan
=
sql_to_optimized_ir
(
query
,
vec!
[]);
let
top
=
&
plan
.get_top
()
.unwrap
();
let
explain_tree
=
FullExplain
::
new
(
&
plan
,
*
top
)
.unwrap
();
let
mut
actual_explain
=
String
::
new
();
actual_explain
.push_str
(
r#"projection (COLUMN_1 -> COLUMN_1)
scan
values
value row (data=ROW(1))
"#
,
);
assert_eq!
(
actual_explain
,
explain_tree
.to_string
())
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment