Skip to content
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
33 changes: 25 additions & 8 deletions internal/explain/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
if len(n.Parameters) > 0 {
children++ // parameters ExpressionList
}
// Only count WindowDefinition as a child for inline window specs (not named references)
// When it's just a reference like "OVER w", it's shown in the SELECT's WINDOW clause instead
// Inline specs include OVER () - empty window, and OVER (ORDER BY x) - window with spec
// Named refs have n.Over.Name set and no inline definition
hasInlineWindowSpec := n.Over != nil && n.Over.Name == ""
if hasInlineWindowSpec {
// Only count WindowDefinition as a child for inline window specs that have content
// Empty OVER () doesn't produce a WindowDefinition in ClickHouse EXPLAIN AST
// Named refs like "OVER w" are shown in the SELECT's WINDOW clause instead
hasNonEmptyWindowSpec := n.Over != nil && n.Over.Name == "" && windowSpecHasContent(n.Over)
if hasNonEmptyWindowSpec {
children++ // WindowDefinition for OVER clause
}
// Normalize function name
Expand Down Expand Up @@ -72,12 +71,30 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
}
// Window definition (for window functions with inline OVER clause)
// WindowDefinition is a sibling to ExpressionList, so use the same indent
// Only output for inline specs, not named references like "OVER w"
if hasInlineWindowSpec {
// Only output for non-empty inline specs, not named references like "OVER w"
if hasNonEmptyWindowSpec {
explainWindowSpec(sb, n.Over, indent+" ", depth+1)
}
}

// windowSpecHasContent returns true if the window spec has any content
// (PartitionBy, OrderBy, or Frame with offset). Empty OVER () returns false.
func windowSpecHasContent(w *ast.WindowSpec) bool {
if w == nil {
return false
}
if len(w.PartitionBy) > 0 {
return true
}
if len(w.OrderBy) > 0 {
return true
}
if w.Frame != nil && w.Frame.StartBound != nil && w.Frame.StartBound.Offset != nil {
return true
}
return false
}

func explainLambda(sb *strings.Builder, n *ast.Lambda, indent string, depth int) {
// Lambda is represented as Function lambda with tuple of params and body
fmt.Fprintf(sb, "%sFunction lambda (children %d)\n", indent, 1)
Expand Down
6 changes: 1 addition & 5 deletions parser/testdata/00052_group_by_in/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/00162_shard_global_join/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
7 changes: 1 addition & 6 deletions parser/testdata/00309_formats/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"explain_todo": {
"stmt13": true,
"stmt14": true
}
}
{}
19 changes: 1 addition & 18 deletions parser/testdata/00609_prewhere_and_default/metadata.json
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
{
"explain_todo": {
"stmt10": true,
"stmt11": true,
"stmt12": true,
"stmt18": true,
"stmt19": true,
"stmt20": true,
"stmt21": true,
"stmt22": true,
"stmt23": true,
"stmt24": true,
"stmt6": true,
"stmt7": true,
"stmt8": true,
"stmt9": true
}
}
{}
3 changes: 0 additions & 3 deletions parser/testdata/00765_sql_compatibility_aliases/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"stmt10": true,
"stmt18": true,
"stmt2": true,
"stmt21": true,
"stmt22": true,
"stmt23": true,
"stmt24": true,
"stmt25": true,
"stmt26": true,
"stmt27": true,
Expand Down
7 changes: 1 addition & 6 deletions parser/testdata/00996_limit_with_ties/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"explain_todo": {
"stmt31": true,
"stmt32": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01051_scalar_optimization/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
1 change: 0 additions & 1 deletion parser/testdata/01055_compact_parts_1/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"explain_todo": {
"stmt1": true,
"stmt6": true
}
}
7 changes: 1 addition & 6 deletions parser/testdata/01070_template_empty_file/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"explain_todo": {
"stmt1": true,
"stmt2": true
}
}
{}
5 changes: 1 addition & 4 deletions parser/testdata/01073_crlf_end_of_line/metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"explain_todo": {
"stmt4": true,
"stmt5": true,
"stmt6": true,
"stmt7": true
"stmt6": true
}
}
1 change: 0 additions & 1 deletion parser/testdata/01116_cross_count_asterisks/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"explain_todo": {
"stmt1": true,
"stmt2": true
}
}
6 changes: 1 addition & 5 deletions parser/testdata/01117_chain_finalize_bug/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01212_empty_join_and_totals/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01240_join_get_or_null/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt14": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"explain_todo": {
"stmt52": true,
"stmt86": true,
"stmt88": true
"stmt86": true
}
}
3 changes: 1 addition & 2 deletions parser/testdata/01356_wrong_filter-type_bug/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"explain_todo": {
"stmt2": true,
"stmt5": true
"stmt2": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01478_not_equi-join_on/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
28 changes: 1 addition & 27 deletions parser/testdata/01495_subqueries_in_with_statement/metadata.json
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
{
"explain_todo": {
"stmt12": true,
"stmt13": true,
"stmt14": true,
"stmt15": true,
"stmt18": true,
"stmt19": true,
"stmt20": true,
"stmt21": true,
"stmt22": true,
"stmt23": true,
"stmt24": true,
"stmt25": true,
"stmt26": true,
"stmt27": true,
"stmt28": true,
"stmt29": true,
"stmt30": true,
"stmt31": true,
"stmt4": true,
"stmt5": true,
"stmt6": true,
"stmt7": true,
"stmt8": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
{
"explain_todo": {
"stmt10": true,
"stmt11": true,
"stmt12": true,
"stmt13": true,
"stmt14": true,
"stmt7": true,
"stmt8": true,
"stmt9": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"explain_todo": {
"stmt1": true,
"stmt2": true
}
}
{}
3 changes: 1 addition & 2 deletions parser/testdata/01499_json_named_tuples/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"explain_todo": {
"stmt1": true,
"stmt2": true
"stmt1": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{
"explain_todo": {
"stmt10": true,
"stmt11": true,
"stmt12": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"explain_todo": {
"stmt11": true,
"stmt13": true,
"stmt5": true,
"stmt7": true
"stmt5": true
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"explain_todo": {
"stmt1": true,
"stmt11": true,
"stmt12": true,
"stmt13": true,
"stmt14": true,
"stmt2": true,
"stmt3": true
"stmt2": true
}
}
12 changes: 0 additions & 12 deletions parser/testdata/01591_window_functions/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@
"stmt111": true,
"stmt112": true,
"stmt12": true,
"stmt13": true,
"stmt14": true,
"stmt15": true,
"stmt16": true,
"stmt17": true,
"stmt18": true,
"stmt19": true,
"stmt20": true,
"stmt21": true,
"stmt22": true,
"stmt23": true,
"stmt24": true,
"stmt25": true,
"stmt26": true,
"stmt27": true,
"stmt28": true,
"stmt29": true,
"stmt31": true,
"stmt32": true,
"stmt33": true,
"stmt34": true,
"stmt35": true,
"stmt36": true,
Expand All @@ -49,9 +39,7 @@
"stmt44": true,
"stmt45": true,
"stmt46": true,
"stmt47": true,
"stmt48": true,
"stmt49": true,
"stmt50": true,
"stmt51": true,
"stmt52": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01656_join_defaul_enum/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01660_second_extremes_bug/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt6": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01671_merge_join_and_constants/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt10": true
}
}
{}
7 changes: 1 addition & 6 deletions parser/testdata/01711_cte_subquery_fix/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"explain_todo": {
"stmt2": true,
"stmt5": true
}
}
{}
6 changes: 1 addition & 5 deletions parser/testdata/01733_transform_ubsan/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt1": true
}
}
{}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"stmt12": true,
"stmt14": true,
"stmt18": true,
"stmt5": true,
"stmt6": true,
"stmt9": true
"stmt5": true
}
}
7 changes: 1 addition & 6 deletions parser/testdata/01909_mbtolou/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"explain_todo": {
"stmt5": true,
"stmt6": true
}
}
{}
Loading
Loading