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

opt: fix internal error when aggregating on a virtual table #44692

Merged
merged 1 commit into from
Feb 4, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/sql/opt/optbuilder/groupby.go
Expand Up @@ -817,6 +817,10 @@ func (b *Builder) allowImplicitGroupingColumn(colID opt.ColumnID, g *groupby) bo
// Get all the PK columns.
tab := md.Table(colMeta.Table)
var pkCols opt.ColSet
if tab.IndexCount() == 0 {
// Virtual tables have no indexes.
return false
}
primaryIndex := tab.Index(cat.PrimaryIndex)
for i := 0; i < primaryIndex.KeyColumnCount(); i++ {
pkCols.Add(colMeta.Table.ColumnID(primaryIndex.Column(i).Ordinal))
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/opt/optbuilder/testdata/aggregate
Expand Up @@ -3734,6 +3734,12 @@ project
├── variable: k [type=int]
└── variable: a [type=int]

# Verify that we handle tables with no primary index (#44659).
build
SELECT table_schema FROM information_schema.columns GROUP BY table_name
----
error (42803): column "table_schema" must appear in the GROUP BY clause or be used in an aggregate function

# Tests with aliases (see #28059).
build
SELECT x + 1 AS z FROM abxy GROUP BY z
Expand Down