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: add support for ANALYZE <tablename> #49816

Merged
merged 1 commit into from Jun 3, 2020
Merged

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Jun 2, 2020

This commit adds support for ANALYZE <tablename> by adding the
statement as syntactic sugar for the equivalent command
CREATE STATISTICS "" FROM <tablename>. This improves compatibility
with Postgres, and is needed to run the PostGIS tutorial as written.

Note that this commit does not add support for ANALYZE without a
table name. We can add support for that and other variants later if
needed, but it is not necessary for the PostGIS tutorial.

Fixes #49214

Release note (sql change): Added support for ANALYZE <tablename>,
which causes the database to collect statistics on the given table for
use by the optimizer. The functionality of this command is equivalent
to the existing command CREATE STATISTICS "" FROM <tablename>, but
it increases compatibility with Postgres by using the same syntax that
Postgres uses.

@rytaft rytaft requested review from otan and RaduBerinde June 2, 2020 23:39
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan, @RaduBerinde, and @rytaft)


pkg/sql/sem/tree/analyze.go, line 20 at r1 (raw file):

// Format implements the NodeFormatter interface.
func (node *Analyze) Format(ctx *FmtCtx) {
	ctx.WriteString("ANALYZE ")

I think we're missing the corresponding code in pretty.go. We should add some parsing tests with the new statement to parse_test.go, I think that would have exposed this.

This commit adds support for `ANALYZE <tablename>` by adding the
statement as syntactic sugar for the equivalent command
`CREATE STATISTICS "" FROM <tablename>`. This improves compatibility
with Postgres, and is needed to run the PostGIS tutorial as written.

Note that this commit does not add support for `ANALYZE` without a
table name. We can add support for that and other variants later if
needed, but it is not necessary for the PostGIS tutorial.

Fixes cockroachdb#49214

Release note (sql change): Added support for `ANALYZE <tablename>`,
which causes the database to collect statistics on the given table for
use by the optimizer. The functionality of this command is equivalent
to the existing command `CREATE STATISTICS "" FROM <tablename>`, but
it increases compatibility with Postgres by using the same syntax that
Postgres uses.
@rytaft
Copy link
Collaborator Author

rytaft commented Jun 3, 2020


pkg/sql/sem/tree/analyze.go, line 20 at r1 (raw file):

Previously, RaduBerinde wrote…

I think we're missing the corresponding code in pretty.go. We should add some parsing tests with the new statement to parse_test.go, I think that would have exposed this.

Doesn't seem like I need to add anything to pretty.go (CREATE STATISTICS doesn't have anything there either...) but good call about adding to parse_test.go. Added tests there and help_test.go

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @otan and @rytaft)


pkg/sql/sem/tree/analyze.go, line 20 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

Doesn't seem like I need to add anything to pretty.go (CREATE STATISTICS doesn't have anything there either...) but good call about adding to parse_test.go. Added tests there and help_test.go

Ah, I guess there is a "default" that works for simple statements, good to know!

@rytaft rytaft requested a review from a team June 3, 2020 17:51
Copy link
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTRs!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@craig
Copy link
Contributor

craig bot commented Jun 3, 2020

Build succeeded

@craig craig bot merged commit d8d001b into cockroachdb:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql, stats: support ANALYZE
4 participants