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 "no user specified" errors in statement bundles #80405

Merged
merged 1 commit into from
Apr 24, 2022

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Apr 22, 2022

A regression was introduced in #71246 that caused errors when running
internal queries to populate files in statement bundles. As a result,
critical information was missing from the env.sql, schema.sql, and
stats*.sql files. This commit fixes the issue by using the internal
executor factory to create an internal executor with the current
session's session data.

Fixes #80396

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

// explainBundleUserSessionsDataOverride is an InternalExecutorOverride which
// overrides the users to the RootUser.
var explainBundleUserSessionDataOverride = sessiondata.InternalExecutorOverride{
User: security.MakeSQLUsernameFromPreNormalizedString(security.RootUser)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it safe to use a root user override here? If not, what is a better alternative?

Copy link
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.

Reviewed all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @rafiss, and @RichardJCai)


pkg/sql/explain_bundle.go, line 438 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

Is it safe to use a root user override here? If not, what is a better alternative?

This looks suspicious. Why can't this use the identity of the user requesting the bundle?

Copy link
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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @rafiss, and @RichardJCai)


pkg/sql/explain_bundle.go, line 438 at r1 (raw file):

Previously, knz (kena) wrote…

This looks suspicious. Why can't this use the identity of the user requesting the bundle?

As in, make stmtEnvCollector take the requester's username as argument or something like that.

@rafiss
Copy link
Collaborator

rafiss commented Apr 22, 2022

a node user is insufficient - it does not have
privileges on user-defined relations which is needed for the
SHOW CREATE queries that populate schema.sql.

was this fixed by #79098 ?

A regression was introduced in cockroachdb#71246 that caused errors when running
internal queries to populate files in statement bundles. As a result,
critical information was missing from the `env.sql`, `schema.sql`, and
`stats*.sql` files. This commit fixes the issue by using the internal
executor factory to create an internal executor with the current
session's session data.

Fixes cockroachdb#80396

Release note: None
@mgartner
Copy link
Collaborator Author

How about this second attempt that doesn't use an override at all?

@knz
Copy link
Contributor

knz commented Apr 22, 2022

is it already common practice to instantiate InternalExecutors on-the-fly? Is this an expensive operation?

(Asking for a friend - if we don't need to keep a predefined instance around, I would cut down on the server code)

@mgartner
Copy link
Collaborator Author

mgartner commented Apr 22, 2022

is it already common practice to instantiate InternalExecutors on-the-fly? Is this an expensive operation?

I copied this pattern from:

ie := ef.planner.extendedEvalCtx.ExecCfg.InternalExecutorFactory(
ef.planner.EvalContext().Context,
ef.planner.SessionData(),
)

It seems fairly prolific given that planner.QueryRowEx, which is used in numerous places, creates a new internal executor:
ie := p.ExecCfg().InternalExecutorFactory(ctx, p.SessionData())

@knz
Copy link
Contributor

knz commented Apr 22, 2022

Amazing. TIL. Thanks for explaining.

@mgartner
Copy link
Collaborator Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Apr 24, 2022

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.

sql: statement bundles are missing schema, environment, or table statistics
4 participants