Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enchancement](statistics) Support sampling collection of statistics #18880

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 90 additions & 21 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ terminal String
KW_ROW,
KW_ROWS,
KW_S3,
KW_SAMPLE,
KW_SCHEMA,
KW_SCHEMAS,
KW_SECOND,
Expand Down Expand Up @@ -890,6 +891,10 @@ nonterminal PauseSyncJobStmt pause_sync_job_stmt;
nonterminal StopSyncJobStmt stop_sync_job_stmt;
nonterminal JobName job_name;

// analyze
nonterminal Map<String, String> with_analysis_properties;
nonterminal List<Map<String, String>> opt_with_analysis_properties;

nonterminal String opt_db, procedure_or_function, opt_comment, opt_engine;
nonterminal ColumnDef.DefaultValue opt_default_value;
nonterminal Boolean opt_if_exists, opt_if_not_exists;
Expand Down Expand Up @@ -2812,30 +2817,45 @@ show_create_reporitory_stmt ::=

// analyze statment
analyze_stmt ::=
KW_ANALYZE opt_sync:sync KW_TABLE table_name:tbl opt_col_list:cols opt_properties:properties
{:
boolean is_whole_tbl = (cols == null);
boolean is_histogram = false;
boolean is_increment = false;
RESULT = new AnalyzeStmt(tbl, sync, cols, properties, is_whole_tbl, is_histogram, is_increment);
:}
| KW_ANALYZE opt_sync:sync KW_INCREMENTAL KW_TABLE table_name:tbl opt_col_list:cols opt_partition_names:partitionNames opt_properties:properties
{:
boolean is_whole_tbl = (cols == null);
boolean is_histogram = false;
boolean is_increment = true;
RESULT = new AnalyzeStmt(tbl, sync, cols, properties, is_whole_tbl, is_histogram, is_increment);
:}
| KW_ANALYZE opt_sync:sync KW_TABLE table_name:tbl KW_UPDATE KW_HISTOGRAM KW_ON ident_list:cols opt_partition_names:partitionNames opt_properties:properties
// statistics
KW_ANALYZE opt_sync:sync KW_TABLE table_name:tbl opt_col_list:cols
opt_with_analysis_properties:withAnalysisProperties opt_properties:properties
{:
boolean is_whole_tbl = false;
boolean is_histogram = true;
boolean is_increment = false;
RESULT = new AnalyzeStmt(tbl, sync, cols, properties, is_whole_tbl, is_histogram, is_increment);
if (properties == null) {
properties = Maps.newHashMap();
}
for (Map<String, String> property : withAnalysisProperties) {
properties.putAll(property);
}
if (!properties.containsKey("sync")) {
properties.put("sync", String.valueOf(sync));
}
// Rule: If no type is specified, see if there is a specified column
if (!properties.containsKey("analysis.type")) {
if ((cols == null)) {
properties.put("analysis.type", "INDEX");
} else {
properties.put("analysis.type", "COLUMN");
}
}
RESULT = new AnalyzeStmt(tbl, cols, properties);
:}
| KW_ANALYZE opt_sync:sync KW_TABLE table_name:tbl KW_UPDATE KW_HISTOGRAM
// histogram
| KW_ANALYZE opt_sync:sync KW_TABLE table_name:tbl opt_col_list:cols KW_UPDATE KW_HISTOGRAM
opt_with_analysis_properties:withAnalysisProperties opt_properties:properties
{:
RESULT = new AnalyzeStmt(tbl, sync, null, new HashMap<>(), true, true, false);
if (properties == null) {
properties = Maps.newHashMap();
}
for (Map<String, String> property : withAnalysisProperties) {
properties.putAll(property);
}
if (!properties.containsKey("sync")) {
properties.put("sync", String.valueOf(sync));
}
// TODO: Support materialized view
properties.put("analysis.type", "HISTOGRAM");
RESULT = new AnalyzeStmt(tbl, cols, properties);
:}
;

Expand Down Expand Up @@ -5730,6 +5750,53 @@ ident_list ::=
:}
;

with_analysis_properties ::=
KW_SYNC
{:
RESULT = new HashMap<String, String>() {{
put("sync", "true");
}};
:}
| KW_INCREMENTAL
{:
RESULT = new HashMap<String, String>() {{
put("incremental", "true");
}};
:}
| KW_SAMPLE KW_PERCENT INTEGER_LITERAL:samplePercent
{:
RESULT = new HashMap<String, String>() {{
put("sample.percent", String.valueOf(samplePercent.intValue()));
}};
:}
| KW_SAMPLE KW_ROWS INTEGER_LITERAL:sampleRows
{:
RESULT = new HashMap<String, String>() {{
put("sample.rows", String.valueOf(sampleRows.intValue()));
}};
:}
| KW_BUCKETS INTEGER_LITERAL:numBuckets
{:
RESULT = new HashMap<String, String>() {{
put("num.buckets", String.valueOf(numBuckets.intValue()));
}};
:}
;

opt_with_analysis_properties ::=
/* empty */
{:
RESULT = Lists.newArrayList();
:}
| opt_with_analysis_properties:withAnalysisProperties
KW_WITH with_analysis_properties:property
{:
withAnalysisProperties.add(property);
RESULT = withAnalysisProperties;
:}
;


expr_list ::=
expr:e
{:
Expand Down Expand Up @@ -7368,6 +7435,8 @@ keyword ::=
{: RESULT = id; :}
| KW_EXPIRED: id
{: RESULT = id; :}
| KW_SAMPLE:id
{: RESULT = id; :}
;

// Identifier that contain keyword
Expand Down
Loading