The current ByteHouse self-developed query optimizer uses statistical information to enhance query performance. Currently, it supports users manually creating stats to collect statistics from tables or change query designs to enhance query performance. Future support for automatic collection and update capabilities will be provided. The supported syntax is as follows:
CREATE STATS [IF NOT EXISTS] (<db>.* | ALL | [<db>.]<table>['(' <col1>, <col2>, ..., <coln> ')']) [WITH (FULLSCAN | SAMPLE [<rows> ROWS] [<ratio> RATIO])]
SHOW (STATS|COLUMN_STATS) (<db>.* | ALL | [<db>.]<table>'('<col1>, <col2>, ..., <coln> ')' )
DROP STATS (<db>.* | ALL | [<db>.]<table>['(' <col1>, <col2>, ..., <coln> ')' ])
For data engineers, diagnosing issues through execution plans is a crucial troubleshooting method. For example, problems such as Join order, whether the statistical information is missing, whether the estimation is reasonable, and whether the pushdown is activated. ByteHouse provides the capability to display physical execution plans. It uses the Explain + Query method for performing analyses, which facilitates a more intuitive analysis and optimization of queries alongside the visualization of Enquiry Details via Query Profiler.
tip
Currently, statistical information needs to be manually collected before generating execution plans.
EXPLAIN (QUERY Statement) ;
tip
Currently, EXPLAIN semantics only support the analysis of DQL SELECT syntax.
CREATE DATABASE sampledb; CREATE TABLE sampledb.t1 ( id Int64, name Int64 ) ENGINE = CnchMergeTree() ORDER BY id; CREATE TABLE sampledb.t2 ( uid Int64, name Int64 ) ENGINE = CnchMergeTree() ORDER BY uid;
INSERT INTO sampledb.t1 VALUES (1,'bob'),(2,'alice'),(3,'peter'),(4,'jay'),(5,'yiyang'),(6,'aurora'); INSERT INTO sampledb.t2 VALUES (1,'smith'),(2,'parker'),(3,'taylor'),(4,'davis'),(5,'joines');
CREATE stats sampledb.t1; CREATE stats sampledb.t2;
Show the following results
table_name | row_count | elapsed_time |
|---|---|---|
t1 | 6 | 0.026777215 |
SHOW stats sampledb.t1;
USE sampledb; EXPLAIN SELECT * FROM t1 JOIN t2 ON (t1.id = t2.uid);
Show the following information:
Gather Exchange est. 6 rows └─ Projection est. 6 rows │ Expressions: [id, name, uid], t2.name:=name_1 └─ Inner Join est. 6 rows │ Condition: id == uid ├─ Local Exchange est. 6 rows │ └─ ReadFromStorage 2100069045.sampledb.t1 est. 6 rows │ Outputs: [id, name] └─ Broadcast Exchange est. 5 rows └─ ReadFromStorage 2100069045.sampledb.t2 est. 5 rows Outputs: [uid], name_1:=name
DROP stats sampledb.t1; DROP stats sampledb.t1;