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.
sql: implement a fast compressed logical plan mechanism
Implement a plan "gist" serializer piggy backing on the exec gen/explain factory infrastructure so that we can always know what the logical plan was and can do historical and statistical tracking. Logically its like an explain (SHAPE) but is even more stripped down. A gist is a sequence of bytes representing the flattened tree of operators and various operator specific metadata. The goal is to record every logical plan we use for every query to have historical data on which plans are used possibly linked up to statistics so we know which stats go with which logical plan. Also implement a decoder to turn the serialized plan back into a tree of explain.Node's that can be displayed using existing explain code. Currently this functionality is only exposed via a new EXPLAIN mode and via a crdb_internal "decoder" SRF. EXPLAIN (GIST) takes a query and returns a single string which is the encoded gist. crdb_internal.decode_plan_gist() takes an encoded gist string and writes out the logical plan one row per line. For performance numbers of the ExecBuild comparing a StubFactory to a PlanGistFactory wrapped around a StubFactory see the PR. Release note (sql change): Record compressed plan gist for all queries. For example, a query like this: SELECT * FROM abc UNION SELECT * FROM abc ORDER BY b,a Produces the following plan according to EXPLAIN (SHAPE) • distinct │ distinct on: a │ └── • union all │ ├── • sort │ │ order: +b,+a │ │ │ └── • scan │ missing stats │ table: abc@primary │ spans: FULL SCAN │ └── • sort │ order: +b,+a │ └── • scan missing stats table: abc@primary spans: FULL SCAN produces the following "gist": AgFuAgAHAAAAEQFuAgAHAAAAERANAAYGAA== The "gist" can be turned back into the following plan: • distinct │ distinct on │ └── • union all │ ├── • sort │ │ order │ │ │ └── • scan │ table: abc@primary │ spans: FULL SCAN │ └── • sort │ order │ └── • scan table: abc@primary spans: FULL SCAN Fixes: cockroachdb#63885
- Loading branch information
Showing
36 changed files
with
2,787 additions
and
128 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
statement ok | ||
CREATE TABLE t (a INT PRIMARY KEY) | ||
|
||
query T | ||
EXPLAIN (GIST) SELECT * FROM t | ||
---- | ||
AgFqAgABAAAABgI= | ||
|
||
query T | ||
SELECT * FROM crdb_internal.decode_plan_gist('AgFqAgABAAAABgI=') | ||
---- | ||
• scan | ||
table: t@primary | ||
spans: FULL SCAN | ||
|
||
query T | ||
SELECT crdb_internal.decode_plan_gist('AgFqAgABAAAABgI=') | ||
---- | ||
• scan | ||
table: t@primary | ||
spans: FULL SCAN | ||
|
||
statement error pq: unknown signature: crdb_internal\.decode_plan_gist\(int\) | ||
SELECT * FROM crdb_internal.decode_plan_gist(10) | ||
|
||
statement error pq: unknown signature: crdb_internal\.decode_plan_gist\(int\) | ||
SELECT crdb_internal.decode_plan_gist(10) | ||
|
||
statement error pq: illegal base64 data at input byte 0 | ||
SELECT crdb_internal.decode_plan_gist('a') |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
explain_factory.og.go | ||
plan_gist_factory.og.go |
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.