Skip to content

sql: move notifying StatsRefresh of new table to post-commit hook#47718

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/dont-notify-stats-until-table-creation-occurs
Apr 24, 2020
Merged

sql: move notifying StatsRefresh of new table to post-commit hook#47718
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/dont-notify-stats-until-table-creation-occurs

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

Prior to this change, the StatsRefresher was being notified of a new table
during the execution of the createTable node, before the creating transaction
had committed. Prior to #46170, the StatsRefresher was likely to block on the
intent of the creating transaction. After that change, the StatsRefresher might
not discover the new table because the creating transaction is much more likely
to get pushed further into the future, past the read of the stats refresher.

Release note (bug fix): Fix rare bug where stats were not automatically
generated for a new table.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner
Copy link
Copy Markdown
Contributor Author

@andreimatei this still needs testing but can you validate the approach?

cc @rytaft

@ajwerner
Copy link
Copy Markdown
Contributor Author

Fixes #46268.

Copy link
Copy Markdown
Collaborator

@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.

Thanks!

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

Copy link
Copy Markdown
Contributor

@andreimatei andreimatei 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! 0 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/conn_executor.go, line 2321 at r1 (raw file):

}

// notifyStatsRefresherOfNewTables is call in the post commit hook to inform

is called


pkg/sql/conn_executor.go, line 2321 at r1 (raw file):

}

// notifyStatsRefresherOfNewTables is call in the post commit hook to inform

I don't really know what the "post commit hook" is. I'd just say that it's called on txn commit.


pkg/sql/conn_executor.go, line 2326 at r1 (raw file):

func (ex *connExecutor) notifyStatsRefresherOfNewTables(ctx context.Context) {
	for _, desc := range ex.extraTxnState.tables.getNewTables() {
		// The CREATE STATISTICS run for an async CTAS query is initiated by the

nit: I'd take the opportunity to clarify this comment, appending a "so we don't do it here".

Prior to this change, the StatsRefresher was being notified of a new table
during the execution of the createTable node, before the creating transaction
had committed. Prior to cockroachdb#46170, the StatsRefresher was likely to block on the
intent of the creating transaction. After that change, the StatsRefresher might
not discover the new table because the creating transaction is much more likely
to get pushed further into the future, past the read of the stats refresher.

Release note (bug fix): Fix rare bug where stats were not automatically
generated for a new table.
@ajwerner ajwerner force-pushed the ajwerner/dont-notify-stats-until-table-creation-occurs branch from 680cd25 to 1030de5 Compare April 24, 2020 06:10
@ajwerner ajwerner marked this pull request as ready for review April 24, 2020 06:12
Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

I checked and this seems to get exercised a reasonable amount already. LMK if you want a test somewhere and what you have in mind.

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


pkg/sql/conn_executor.go, line 2321 at r1 (raw file):

Previously, andreimatei (Andrei Matei) wrote…

is called

Done.


pkg/sql/conn_executor.go, line 2321 at r1 (raw file):

Previously, andreimatei (Andrei Matei) wrote…

I don't really know what the "post commit hook" is. I'd just say that it's called on txn commit.

Done.

Copy link
Copy Markdown
Contributor

@andreimatei andreimatei 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! 0 of 0 LGTMs obtained (waiting on @andreimatei and @rytaft)

Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r=andreimatei

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

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 24, 2020

Build succeeded

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.

4 participants