Skip to content

Commit

Permalink
This commit adds the disable_hoist_projection_in_join_limitation sess…
Browse files Browse the repository at this point in the history
…ion flag.

Release note: none
  • Loading branch information
Mark Sirek committed Aug 11, 2022
1 parent 9be7cf5 commit 6b3574f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,10 @@ func (m *sessionDataMutator) SetUnconstrainedNonCoveringIndexScanEnabled(val boo
m.data.UnconstrainedNonCoveringIndexScanEnabled = val
}

func (m *sessionDataMutator) SetDisableHoistProjectionInJoinLimitation(val bool) {
m.data.DisableHoistProjectionInJoinLimitation = val
}

func (m *sessionDataMutator) SetTroubleshootingModeEnabled(val bool) {
m.data.TroubleshootingMode = val
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -4686,6 +4686,7 @@ default_transaction_quality_of_service regular
default_transaction_read_only off
default_transaction_use_follower_reads off
default_with_oids off
disable_hoist_projection_in_join_limitation off
disable_partially_distributed_plans off
disable_plan_gists off
disallow_full_table_scans off
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -4171,6 +4171,7 @@ default_transaction_quality_of_service regular NULL
default_transaction_read_only off NULL NULL NULL string
default_transaction_use_follower_reads off NULL NULL NULL string
default_with_oids off NULL NULL NULL string
disable_hoist_projection_in_join_limitation off NULL NULL NULL string
disable_partially_distributed_plans off NULL NULL NULL string
disable_plan_gists off NULL NULL NULL string
disallow_full_table_scans off NULL NULL NULL string
Expand Down Expand Up @@ -4296,6 +4297,7 @@ default_transaction_quality_of_service regular NULL
default_transaction_read_only off NULL user NULL off off
default_transaction_use_follower_reads off NULL user NULL off off
default_with_oids off NULL user NULL off off
disable_hoist_projection_in_join_limitation off NULL user NULL off off
disable_partially_distributed_plans off NULL user NULL off off
disable_plan_gists off NULL user NULL off off
disallow_full_table_scans off NULL user NULL off off
Expand Down Expand Up @@ -4416,6 +4418,7 @@ default_transaction_quality_of_service NULL NULL NULL
default_transaction_read_only NULL NULL NULL NULL NULL
default_transaction_use_follower_reads NULL NULL NULL NULL NULL
default_with_oids NULL NULL NULL NULL NULL
disable_hoist_projection_in_join_limitation NULL NULL NULL NULL NULL
disable_partially_distributed_plans NULL NULL NULL NULL NULL
disable_plan_gists NULL NULL NULL NULL NULL
disallow_full_table_scans NULL NULL NULL NULL NULL
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ default_transaction_quality_of_service regular
default_transaction_read_only off
default_transaction_use_follower_reads off
default_with_oids off
disable_hoist_projection_in_join_limitation off
disable_partially_distributed_plans off
disable_plan_gists off
disallow_full_table_scans off
Expand Down
12 changes: 9 additions & 3 deletions pkg/sql/opt/xform/join_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,9 +1678,15 @@ func (c *CustomFuncs) getfilteredCanonicalScan(
return scanExpr, filters, true
}

// IsCanonicalScanOrSelect returns true if `relation` is a canonical scan or a
// select from a canonical scan.
func (c *CustomFuncs) IsCanonicalScanOrSelect(relation memo.RelExpr) (ok bool) {
// CanHoistProjectInput returns true if a projection of an expression on
// `relation` is allowed to be hoisted above a parent Join. The preconditions
// for this are if `relation` is a canonical scan or a select from a canonical
// scan, or the disable_hoist_projection_in_join_limitation session flag is
// true.
func (c *CustomFuncs) CanHoistProjectInput(relation memo.RelExpr) (ok bool) {
if c.e.evalCtx.SessionData().DisableHoistProjectionInJoinLimitation {
return true
}
_, _, ok = c.getfilteredCanonicalScan(relation)
return ok
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/opt/xform/rules/join.opt
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
(InnerJoin
$left:*
$proj:(Project
$right:* & (IsCanonicalScanOrSelect $right)
$right:* & (CanHoistProjectInput $right)
$projections:* & ^(HasVolatileProjection $projections)
$passthrough:*
)
Expand Down Expand Up @@ -486,7 +486,7 @@
(LeftJoin
$left:*
(Project
$right:* & (IsCanonicalScanOrSelect $right)
$right:* & (CanHoistProjectInput $right)
$projections:* & ^(HasVolatileProjection $projections)
$passthrough:*
)
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/sessiondatapb/local_only_session_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ message LocalOnlySessionData {
// much a non-production setting.
double testing_optimizer_disable_rule_probability = 73;

// disable_hoist_projection_in_join_limitation disables the restrictions
// placed on projection hoisting during query planning in the optimizer.
bool disable_hoist_projection_in_join_limitation = 74;

///////////////////////////////////////////////////////////////////////////
// WARNING: consider whether a session parameter you're adding needs to //
// be propagated to the remote nodes. If so, that parameter should live //
Expand Down
17 changes: 16 additions & 1 deletion pkg/sql/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,6 @@ var varGen = map[string]sessionVar{
},
GlobalDefault: globalFalse,
},

// CockroachDB extension.
`show_primary_key_constraint_on_not_visible_columns`: {
GetStringVal: makePostgresBoolGetStringValFn(`show_primary_key_constraint_on_not_visible_columns`),
Expand Down Expand Up @@ -2120,6 +2119,22 @@ var varGen = map[string]sessionVar{
return formatFloatAsPostgresSetting(0)
},
},
// CockroachDB extension.
`disable_hoist_projection_in_join_limitation`: {
GetStringVal: makePostgresBoolGetStringValFn(`disable_hoist_projection_in_join_limitation`),
Set: func(_ context.Context, m sessionDataMutator, s string) error {
b, err := paramparse.ParseBoolVar("disable_hoist_projection_in_join_limitation", s)
if err != nil {
return err
}
m.SetDisableHoistProjectionInJoinLimitation(b)
return nil
},
Get: func(evalCtx *extendedEvalContext) (string, error) {
return formatBoolAsPostgresSetting(evalCtx.SessionData().DisableHoistProjectionInJoinLimitation), nil
},
GlobalDefault: globalFalse,
},
}

const compatErrMsg = "this parameter is currently recognized only for compatibility and has no effect in CockroachDB."
Expand Down

0 comments on commit 6b3574f

Please sign in to comment.