Skip to content

Commit 29346af

Browse files
committed
Always show SAMPLE BY in CREATE TABLE EXPLAIN output
Previously, SAMPLE BY was only shown when it was a function (not an identifier) and when different from ORDER BY. ClickHouse's actual EXPLAIN AST output always shows SAMPLE BY when present. This fixes 27 statements across 19 tests including: - 02559_add_parts - 00578_merge_table_sampling - 02380_analyzer_join_sample - 03227_test_sample_n - And 15 more SAMPLE BY related tests
1 parent 730f9d2 commit 29346af

20 files changed

Lines changed: 19 additions & 97 deletions

File tree

internal/explain/statements.go

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -282,24 +282,9 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
282282
if len(n.PrimaryKey) > 0 {
283283
storageChildren++
284284
}
285-
// SAMPLE BY is only shown in EXPLAIN AST when it's a function (not a simple identifier)
286-
// and when it's different from ORDER BY
285+
// SAMPLE BY is always shown in EXPLAIN AST when present
287286
if n.SampleBy != nil {
288-
if _, isIdent := n.SampleBy.(*ast.Identifier); !isIdent {
289-
// Check if SAMPLE BY equals ORDER BY - if so, don't show it
290-
showSampleBy := true
291-
if len(n.OrderBy) == 1 {
292-
var orderBySb, sampleBySb strings.Builder
293-
Node(&orderBySb, n.OrderBy[0], 0)
294-
Node(&sampleBySb, n.SampleBy, 0)
295-
if orderBySb.String() == sampleBySb.String() {
296-
showSampleBy = false
297-
}
298-
}
299-
if showSampleBy {
300-
storageChildren++
301-
}
302-
}
287+
storageChildren++
303288
}
304289
if n.TTL != nil {
305290
storageChildren++
@@ -395,24 +380,9 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
395380
}
396381
}
397382
}
398-
// SAMPLE BY is only shown in EXPLAIN AST when it's a function (not a simple identifier)
399-
// and when it's different from ORDER BY
383+
// SAMPLE BY is always shown in EXPLAIN AST when present
400384
if n.SampleBy != nil {
401-
if _, isIdent := n.SampleBy.(*ast.Identifier); !isIdent {
402-
// Check if SAMPLE BY equals ORDER BY - if so, don't show it
403-
showSampleBy := true
404-
if len(n.OrderBy) == 1 {
405-
var orderBySb, sampleBySb strings.Builder
406-
Node(&orderBySb, n.OrderBy[0], 0)
407-
Node(&sampleBySb, n.SampleBy, 0)
408-
if orderBySb.String() == sampleBySb.String() {
409-
showSampleBy = false
410-
}
411-
}
412-
if showSampleBy {
413-
Node(sb, n.SampleBy, storageChildDepth)
414-
}
415-
}
385+
Node(sb, n.SampleBy, storageChildDepth)
416386
}
417387
if n.TTL != nil {
418388
fmt.Fprintf(sb, "%s ExpressionList (children 1)\n", storageIndent)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt22": true,
4-
"stmt4": true
3+
"stmt22": true
54
}
65
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true,
4-
"stmt9": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt2":true,"stmt7":true}}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true,
4-
"stmt74": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt11":true}}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)