Skip to content

sql: Define more columns in pg_catalog.pg_statistic_ext#93274

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
e-mbrown:eb/statext
Dec 20, 2022
Merged

sql: Define more columns in pg_catalog.pg_statistic_ext#93274
craig[bot] merged 1 commit intocockroachdb:masterfrom
e-mbrown:eb/statext

Conversation

@e-mbrown
Copy link
Copy Markdown
Contributor

@e-mbrown e-mbrown commented Dec 8, 2022

Epic: CRDB-23454
Fixes: #88108
Fixes: #93430

This commit makes sure the stxnamespace, stxkind and stxstattarget columns are defined in pg_statistics_ext.

Release note: The stxnamespace, stxkind and
stxstattarget columns are now defined in
pg_statistics_ext. Also pg_statistics_ext
no longer crashes when stxname is null.

@e-mbrown e-mbrown requested review from a team and knz December 8, 2022 19:56
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

pls also take a review from @rafiss

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @e-mbrown)


-- commits line 7 at r1:
looks to me like a bug fix worthy of a release note.


pkg/sql/pg_catalog.go line 3465 at r1 (raw file):

		for _, row := range rows {
			tableID := tree.MustBeDInt(row[0])
			name := tree.MustBeDString(row[1])

Using MustBeDString for the name forces a heap allocation when you convert it back to a Datum below.
You could simply refer to row[1] in the addRow call below instead.


pkg/sql/pg_catalog.go line 3488 at r1 (raw file):

				schemaOid(statSchema),        // stxnamespace
				tree.DNull,                   // stxowner
				tree.NewDInt(-1),             // stxstattarget

You can allocate this DInt just once out of the loop.

@e-mbrown e-mbrown requested a review from rafiss December 8, 2022 20:11
@e-mbrown e-mbrown force-pushed the eb/statext branch 2 times, most recently from 6058fc2 to 0ad6ab3 Compare December 8, 2022 21:11
Copy link
Copy Markdown
Contributor Author

@e-mbrown e-mbrown 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 @knz and @rafiss)


-- commits line 7 at r1:

Previously, knz (Raphael 'kena' Poss) wrote…

looks to me like a bug fix worthy of a release note.

Done.


pkg/sql/pg_catalog.go line 3465 at r1 (raw file):

Previously, knz (Raphael 'kena' Poss) wrote…

Using MustBeDString for the name forces a heap allocation when you convert it back to a Datum below.
You could simply refer to row[1] in the addRow call below instead.

Done.


pkg/sql/pg_catalog.go line 3488 at r1 (raw file):

Previously, knz (Raphael 'kena' Poss) wrote…

You can allocate this DInt just once out of the loop.

Done.

Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

lgtm, with one nit!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @e-mbrown and @knz)


pkg/sql/pg_catalog.go line 3453 at r2 (raw file):

	schema: vtable.PgCatalogStatisticExt,
	populate: func(ctx context.Context, p *planner, db catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
		query := `SELECT "tableID", name, "columnIDs", "statisticID", '{d}'::CHAR[] FROM system.table_statistics;`

nit: the {d} value should be cast to "char"[]

also, can you add a comment explaining what d means here (based on the PG docs)

@jordanlewis
Copy link
Copy Markdown
Member

Hey @e-mbrown, coincidentally (unrelated to this PR!) I noticed this issue: #93430. Would you mind adding a fix for it while you're editing pg_statistic_ext?

Thanks!

`pg_catalog.pg_statistic_ext` is now
populated with more data.

Release note (bug fix): The `stxnamespace`, `stxkind` and
`stxstattarget` columns are now defined in
`pg_statistics_ext`.
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

nice fix! i'm adding a backport label as well

Reviewed 1 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @e-mbrown and @knz)

@e-mbrown
Copy link
Copy Markdown
Contributor Author

bors r=rafiss

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 20, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 20, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 20, 2022

Build succeeded:

@craig craig bot merged commit 56d249d into cockroachdb:master Dec 20, 2022
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Dec 20, 2022

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 5fb4c60 to blathers/backport-release-22.1-93274: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.1.x failed. See errors above.


error creating merge commit from 5fb4c60 to blathers/backport-release-22.2-93274: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

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: pg_statistic_ext crashes with statistics with no names sql: pg_catalog.pg_statistic_ext is incompletely defined

5 participants