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

sql: fix a bug with ordinality planning #39086

Merged
merged 1 commit into from
Jul 25, 2019
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
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