Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
39086: sql: fix a bug with ordinality planning r=yuzefovich a=yuzefovich

Ordinality node appends an Int column so that it can write to it.
Previously, plan.ResultTypes were appended to before adding a
single group stage which internally used updated ResultTypes to
set up inputs to the ordinality processor. Now this behavior is
fixed and adding a single group stage takes care of updating
ResultTypes accordingly.

Fixes: cockroachdb#38995.

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Jul 25, 2019
2 parents e0b2300 + dc4f2fc commit 5945619
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/distsql_physical_planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2739,11 +2739,11 @@ func (dsp *DistSQLPlanner) createPlanForOrdinality(
}

plan.PlanToStreamColMap = append(plan.PlanToStreamColMap, len(plan.ResultTypes))
plan.ResultTypes = append(plan.ResultTypes, *types.Int)
outputTypes := append(plan.ResultTypes, *types.Int)

// WITH ORDINALITY never gets distributed so that the gateway node can
// always number each row in order.
plan.AddSingleGroupStage(dsp.nodeDesc.NodeID, ordinalitySpec, distsqlpb.PostProcessSpec{}, plan.ResultTypes)
plan.AddSingleGroupStage(dsp.nodeDesc.NodeID, ordinalitySpec, distsqlpb.PostProcessSpec{}, outputTypes)

return plan, nil
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/vectorize
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,17 @@ SELECT count(*), count(a), sum_int(a), min(a), max(a), sum(b), avg(b) FROM empty
query IIIIIRR
SELECT count(*), count(a), sum_int(a), min(a), max(a), sum(b), avg(b) FROM empty GROUP BY a
----


statement ok
CREATE TABLE t_38995 (a INT PRIMARY KEY)

statement ok
INSERT INTO t_38995 VALUES (1), (2), (3)

query II
SELECT a, ordinality*2 FROM t_38995 WITH ORDINALITY
----
1 2
2 4
3 6

0 comments on commit 5945619

Please sign in to comment.