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: clean up of scanNode and some other things #49724

Merged
merged 3 commits into from
Jun 2, 2020

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented May 29, 2020

sql: unify PlanningCtx constructors into one

Release note: None

sql: remove separate scanVisilibity struct

This commit removes sql.scanVisibility in favor of protobuf-generated
execinfrapb.ScanVisibility. It also introduces prettier aliases for
the two values into execinfra package that are now used throughout the
code.

Release note: None

sql: clean up of scan node and a few other things

This commit does the following cleanups of scanNode:

  1. refactors scanNode.initCols method to be standalone (it will
    probably be reused later by distsql spec exec factory).
  2. removes numBackfillColumns, specifiedIndexReverse, and
    isSecondaryIndex fields since they are no longer used.
  3. refactors the code to remove valNeededForCols field which was
    always consecutive numbers in range [0, len(n.cols)-1].
  4. refactors getIndexIdx method to not depend on scanNode.

Additionally, this commit removes planDependencies business
from planTop since optimizer now handles CREATE VIEW and handles
the plan dependencies on its own (and CREATE VIEW was the single
user of that struct in the plan top).

Also, it removes (which seems like) unnecessary call to planColumns
when creating distinct spec and an unused parameter from
createTableReaders method.

Addresses: #47474.

Release note: None

@yuzefovich yuzefovich requested review from asubiotto, a team and dt and removed request for a team May 29, 2020 23:41
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich removed the request for review from dt May 29, 2020 23:41
Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

Reviewed 15 of 15 files at r1, 15 of 15 files at r2, 7 of 7 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/apply_join.go, line 264 at r1 (raw file):

	planCtx := params.p.extendedEvalCtx.ExecCfg.DistSQLPlanner.newLocalPlanningCtx(params.ctx, evalCtx)
	// Always plan local.
	planCtx.isLocal = true

I don't think newLocalPlanningCtx sets this field. Maybe it should?


pkg/sql/conn_executor_exec.go, line 866 at r1 (raw file):

	var planCtx *PlanningCtx
	if distribute {
		planCtx = ex.server.cfg.DistSQLPlanner.NewPlanningCtx(ctx, evalCtx, planner.txn, distribute)

NewPlanningCtx calls newLocalPlanningCtx. We should be able to remove this if distribute check here and everywhere and have NewPlanningCtx behave identically to the old behavior


pkg/sql/distsql_physical_planner.go, line 3253 at r1 (raw file):

	ctx context.Context, evalCtx *extendedEvalContext, txn *kv.Txn, distribute bool,
) *PlanningCtx {
	planCtx := dsp.newLocalPlanningCtx(ctx, evalCtx)

How about if !distribute { return?


pkg/sql/distsql_running_test.go, line 158 at r1 (raw file):

		evalCtx := p.ExtendedEvalContext()
		// We need distribute = true so that we executing the plan involves marshaling

nit: so that we executing the plan


pkg/sql/opt_exec_factory.go, line 2098 at r2 (raw file):

// identified by their ordinal position in the table schema.
func makeScanColumnsConfig(table cat.Table, cols exec.TableColumnOrdinalSet) scanColumnsConfig {
	// Set visibility=publicAndNotPublicColumns, since all columns in the "cols"

nit: update comment further?


pkg/sql/scan.go, line 362 at r2 (raw file):

	// Register the dependency to the planner, if requested.
	if planDeps != nil {

cc @RaduBerinde

@RaduBerinde
Copy link
Member


pkg/sql/scan.go, line 362 at r2 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

cc @RaduBerinde

Yes, this is no longer needed.

Copy link
Member Author

@yuzefovich yuzefovich 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 @asubiotto)


pkg/sql/apply_join.go, line 264 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

I don't think newLocalPlanningCtx sets this field. Maybe it should?

It does set the field.


pkg/sql/conn_executor_exec.go, line 866 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

NewPlanningCtx calls newLocalPlanningCtx. We should be able to remove this if distribute check here and everywhere and have NewPlanningCtx behave identically to the old behavior

Yeah, I didn't refactor code all the way, done.


pkg/sql/distsql_physical_planner.go, line 3253 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

How about if !distribute { return?

Done.


pkg/sql/opt_exec_factory.go, line 2098 at r2 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

nit: update comment further?

Done.


pkg/sql/scan.go, line 362 at r2 (raw file):

Previously, RaduBerinde wrote…

Yes, this is no longer needed.

Done.

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 23 of 23 files at r4, 17 of 17 files at r5, 7 of 7 files at r6.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

This commit removes `sql.scanVisibility` in favor of protobuf-generated
`execinfrapb.ScanVisibility`. It also introduces prettier aliases for
the two values into `execinfra` package that are now used throughout the
code.

Release note: None
This commit does the following cleanups of `scanNode`:
1. refactors `scanNode.initCols` method to be standalone (it will
probably be reused later by distsql spec exec factory).
2. removes `numBackfillColumns`, `specifiedIndexReverse`, and
`isSecondaryIndex` fields since they are no longer used.
3. refactors the code to remove `valNeededForCols` field which was
always consecutive numbers in range `[0, len(n.cols)-1]`.
4. refactors `getIndexIdx` method to not depend on `scanNode`.

Additionally, this commit removes `planDependencies` business
from `planTop` since optimizer now handles CREATE VIEW and handles
the plan dependencies on its own (and CREATE VIEW was the single
user of that struct in the plan top).

Also, it removes (which seems like) unnecessary call to `planColumns`
when creating distinct spec and an unused parameter from
`createTableReaders` method.

Release note: None
@yuzefovich
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 2, 2020

Build succeeded

@craig craig bot merged commit 3b2245f into cockroachdb:master Jun 2, 2020
@yuzefovich yuzefovich deleted the scan-cleanup branch June 2, 2020 16:40
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