From 8a1878a57acaea4cbe7023c922ccbc31828cc7e5 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Mon, 9 Sep 2019 01:05:42 -0400 Subject: [PATCH] exec: don't template asc vs desc in mj This saves 7mb of generated code for 2-3% slowdown. Release note: None --- .../execgen/cmd/execgen/mergejoiner_gen.go | 5 ++- pkg/sql/exec/mergejoiner_tmpl.go | 31 ++++--------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/pkg/sql/exec/execgen/cmd/execgen/mergejoiner_gen.go b/pkg/sql/exec/execgen/cmd/execgen/mergejoiner_gen.go index 1dd370fc47fa..772b8eba425e 100644 --- a/pkg/sql/exec/execgen/cmd/execgen/mergejoiner_gen.go +++ b/pkg/sql/exec/execgen/cmd/execgen/mergejoiner_gen.go @@ -88,7 +88,6 @@ func genMergeJoinOps(wr io.Writer, jti joinTypeInfo) error { s = strings.Replace(s, "_HAS_NULLS", "$.HasNulls", -1) s = strings.Replace(s, "_HAS_SELECTION", "$.HasSelection", -1) s = strings.Replace(s, "_SEL_PERMUTATION", "$.SelPermutation", -1) - s = strings.Replace(s, "_ASC_DIRECTION", "$.AscDirection", -1) leftUnmatchedGroupSwitch := makeFunctionRegex("_LEFT_UNMATCHED_GROUP_SWITCH", 1) s = leftUnmatchedGroupSwitch.ReplaceAllString(s, `{{template "leftUnmatchedGroupSwitch" buildDict "Global" $ "JoinType" $1}}`) @@ -111,8 +110,8 @@ func genMergeJoinOps(wr io.Writer, jti joinTypeInfo) error { processNotLastGroupInColumnSwitch := makeFunctionRegex("_PROCESS_NOT_LAST_GROUP_IN_COLUMN_SWITCH", 1) s = processNotLastGroupInColumnSwitch.ReplaceAllString(s, `{{template "processNotLastGroupInColumnSwitch" buildDict "Global" $ "JoinType" $1}}`) - probeSwitch := makeFunctionRegex("_PROBE_SWITCH", 6) - s = probeSwitch.ReplaceAllString(s, `{{template "probeSwitch" buildDict "Global" $ "JoinType" $1 "FilterInfo" $2 "SelPermutation" $3 "lHasNulls" $4 "rHasNulls" $5 "AscDirection" $6}}`) + probeSwitch := makeFunctionRegex("_PROBE_SWITCH", 5) + s = probeSwitch.ReplaceAllString(s, `{{template "probeSwitch" buildDict "Global" $ "JoinType" $1 "FilterInfo" $2 "SelPermutation" $3 "lHasNulls" $4 "rHasNulls" $5}}`) sourceFinishedSwitch := makeFunctionRegex("_SOURCE_FINISHED_SWITCH", 1) s = sourceFinishedSwitch.ReplaceAllString(s, `{{template "sourceFinishedSwitch" buildDict "Global" $ "JoinType" $1}}`) diff --git a/pkg/sql/exec/mergejoiner_tmpl.go b/pkg/sql/exec/mergejoiner_tmpl.go index 8e4981f99927..023d652b5e89 100644 --- a/pkg/sql/exec/mergejoiner_tmpl.go +++ b/pkg/sql/exec/mergejoiner_tmpl.go @@ -121,7 +121,6 @@ func _PROBE_SWITCH( _SEL_PERMUTATION selPermutation, _L_HAS_NULLS bool, _R_HAS_NULLS bool, - _ASC_DIRECTION bool, ) { // */}} // {{define "probeSwitch"}} // {{ $sel := $.SelPermutation }} @@ -270,11 +269,9 @@ func _PROBE_SWITCH( } } else { // mismatch var incrementLeft bool - // {{ if _ASC_DIRECTION }} _ASSIGN_LT("incrementLeft", "lVal", "rVal") - // {{ else }} - _ASSIGN_GT("incrementLeft", "lVal", "rVal") - // {{ end }} + // Switch the direction of increment if we're sorted descendingly. + incrementLeft = incrementLeft == (o.left.directions[eqColIdx] == distsqlpb.Ordering_Column_ASC) if incrementLeft { curLIdx++ // {{ if _L_HAS_NULLS }} @@ -588,31 +585,15 @@ EqLoop: colType := o.left.sourceTypes[int(o.left.eqCols[eqColIdx])] if lVec.MaybeHasNulls() { if rVec.MaybeHasNulls() { - if o.left.directions[eqColIdx] == distsqlpb.Ordering_Column_ASC { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, true, true, true) - } else { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, true, true, false) - } + _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, true, true) } else { - if o.left.directions[eqColIdx] == distsqlpb.Ordering_Column_ASC { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, true, false, true) - } else { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, true, false, false) - } + _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, true, false) } } else { if rVec.MaybeHasNulls() { - if o.left.directions[eqColIdx] == distsqlpb.Ordering_Column_ASC { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, false, true, true) - } else { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, false, true, false) - } + _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, false, true) } else { - if o.left.directions[eqColIdx] == distsqlpb.Ordering_Column_ASC { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, false, false, true) - } else { - _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, false, false, false) - } + _PROBE_SWITCH(_JOIN_TYPE, _FILTER_INFO, _SEL_ARG, false, false) } } // Look at the groups associated with the next equality column by moving