forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
115468: sql: make CALL statements explainable r=DrewKimball a=DrewKimball This patch makes it possible to run CALL statements with EXPLAIN. Currently, most explain variants only display the name and arguments of the procedure. The `OPT` explain variants additionally show the SQL/PLpgSQL body statements of the procedure. This commit also changes the name displayed for a procedure in the output of `EXPLAIN (OPT)` from `udf` to `procedure`. Fixes cockroachdb#114674 Release note (sql change): It is now possible to run CALL statements with EXPLAIN. The `EXPLAIN (OPT)` variant will show the body of the procedure, while other variants will only show the procedure name and arguments. Co-authored-by: Drew Kimball <[email protected]>
- Loading branch information
Showing
20 changed files
with
486 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ explainable_stmt ::= | |
preparable_stmt | ||
| comment_stmt | ||
| execute_stmt | ||
| call_stmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
pkg/ccl/logictestccl/testdata/logic_test/explain_call_plpgsql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# LogicTest: local | ||
|
||
statement ok | ||
CREATE PROCEDURE foo(x INT) LANGUAGE PLpgSQL AS $$ | ||
BEGIN | ||
RAISE NOTICE 'foo: %', x; | ||
END | ||
$$ | ||
|
||
query T | ||
EXPLAIN CALL foo(0); | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• call | ||
procedure: foo(0) | ||
|
||
query T | ||
EXPLAIN (VERBOSE) CALL foo(1); | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• call | ||
columns: () | ||
estimated row count: 10 (missing stats) | ||
procedure: foo(1) | ||
|
||
query T | ||
EXPLAIN (OPT) CALL foo(3); | ||
---- | ||
call | ||
└── procedure: foo | ||
├── args | ||
│ └── 3 | ||
├── params: x | ||
└── body | ||
└── values | ||
└── (_stmt_raise_1(x),) | ||
|
||
query T | ||
EXPLAIN (OPT, VERBOSE) CALL foo(3); | ||
---- | ||
call | ||
├── volatile | ||
├── stats: [rows=10] | ||
├── cost: 0.02 | ||
├── distribution: test | ||
└── procedure: foo | ||
├── args | ||
│ └── 3 | ||
├── params: x:1 | ||
└── body | ||
└── values | ||
├── columns: "_stmt_raise_1":5 | ||
├── outer: (1) | ||
├── cardinality: [1 - 1] | ||
├── volatile | ||
├── stats: [rows=1] | ||
├── key: () | ||
├── fd: ()-->(5) | ||
└── (_stmt_raise_1(x:1),) | ||
|
||
query T | ||
EXPLAIN (OPT, TYPES) CALL foo(3); | ||
---- | ||
call | ||
├── volatile | ||
├── stats: [rows=10] | ||
├── cost: 0.02 | ||
├── distribution: test | ||
└── procedure: foo [type=void] | ||
├── args | ||
│ └── const: 3 [type=int] | ||
├── params: x:1(int) | ||
└── body | ||
└── values | ||
├── columns: "_stmt_raise_1":5(void) | ||
├── outer: (1) | ||
├── cardinality: [1 - 1] | ||
├── volatile | ||
├── stats: [rows=1] | ||
├── key: () | ||
├── fd: ()-->(5) | ||
└── tuple [type=tuple{void}] | ||
└── udf: _stmt_raise_1 [type=void] | ||
├── args | ||
│ └── variable: x:1 [type=int] | ||
├── params: x:2(int) | ||
└── body | ||
├── values | ||
│ ├── columns: stmt_raise_2:3(int) | ||
│ ├── outer: (2) | ||
│ ├── cardinality: [1 - 1] | ||
│ ├── volatile | ||
│ ├── stats: [rows=1] | ||
│ ├── key: () | ||
│ ├── fd: ()-->(3) | ||
│ └── tuple [type=tuple{int}] | ||
│ └── function: crdb_internal.plpgsql_raise [type=int] | ||
│ ├── const: 'NOTICE' [type=string] | ||
│ ├── concat [type=string] | ||
│ │ ├── concat [type=string] | ||
│ │ │ ├── const: 'foo: ' [type=string] | ||
│ │ │ └── coalesce [type=string] | ||
│ │ │ ├── cast: STRING [type=string] | ||
│ │ │ │ └── variable: x:2 [type=int] | ||
│ │ │ └── const: '<NULL>' [type=string] | ||
│ │ └── const: '' [type=string] | ||
│ ├── const: '' [type=string] | ||
│ ├── const: '' [type=string] | ||
│ └── const: '00000' [type=string] | ||
└── values | ||
├── columns: stmt_return_3:4(void) | ||
├── cardinality: [1 - 1] | ||
├── stats: [rows=1] | ||
├── key: () | ||
├── fd: ()-->(4) | ||
└── tuple [type=tuple{void}] | ||
└── null [type=void] | ||
|
||
query T | ||
EXPLAIN (DISTSQL) CALL foo(3); | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• call | ||
procedure: foo(3) | ||
· | ||
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJyMj0FL-0AQxe__TxHeqYXt3wRveyvWQyDWansQJMi6mdbFbSbubKhS8t0liUURD53DwLx5M7-ZI-TNQ-P6YVXM82UyWeTrzfqumCZX86JImvbZO_t_yzy5nEKh5oqWZk8C_YgMpUIT2JIIh146Doa8eodOFVzdtLGXSwXLgaCPiC56goZna3xijfdJepFCoaJonB_cnQK38XtWotkRdPYDli-g006dz7snabgWOouU_iLNsq5UoGpH45PCbbC0CmwH71jeDosGoSKJYzcbi7w-tSQGMvvx_FJh6_nw5CpopF8x-yOdAv2A2Un_2PqFD8PazUfTn7U1XkjhxrzSgiKFvaudRGehY2ip6_59BgAA__9oSZu_ | ||
|
||
query T | ||
EXPLAIN ANALYZE CALL foo(3); | ||
---- | ||
planning time: 10µs | ||
execution time: 100µs | ||
distribution: <hidden> | ||
vectorized: <hidden> | ||
maximum memory usage: <hidden> | ||
network usage: <hidden> | ||
regions: <hidden> | ||
isolation level: serializable | ||
priority: normal | ||
quality of service: regular | ||
· | ||
• call | ||
nodes: <hidden> | ||
regions: <hidden> | ||
actual row count: 0 | ||
procedure: foo(3) | ||
|
||
query T | ||
EXPLAIN ANALYZE (DISTSQL) CALL foo(3); | ||
---- | ||
planning time: 10µs | ||
execution time: 100µs | ||
distribution: <hidden> | ||
vectorized: <hidden> | ||
maximum memory usage: <hidden> | ||
network usage: <hidden> | ||
regions: <hidden> | ||
isolation level: serializable | ||
priority: normal | ||
quality of service: regular | ||
· | ||
• call | ||
nodes: <hidden> | ||
regions: <hidden> | ||
actual row count: 0 | ||
procedure: foo(3) | ||
· | ||
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJyMUMtq40AQvO9XiDrtwnhXYm9zW9YXg_MgyS2IMB617SEjtTLdwg5Gn5UfyJcFSTY4IYH0YaCqu6tq-gB5irD4_2-5zNpuFYP_vWb--fcXDBqu6NLVJLD3KFAatIk9iXAaqMM4sKj2sLlBaNpOB7o08JwI9gANGgkWkb2LmXcxZvmfHAYVqQtx1KU9-U4DN5mGmmyWv74IDFZO_ZYk407bTm02bCXenRNlbzCho62o2xBscZZzMYfNe_P9qDckLTdC70J-5ZR_cJoVfWlA1Yam-wh3ydN1Yj_OTvBqFBqJikSnbjGBRXNqiSZy9RS_NFhH3j2EChb5sWafPKfCsOA2Mnzsdsu7UfbuuR1irV0UMrhwjzQnpVSHJogGD6upo77_8RYAAP__9m6rjw== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.