From 51b97daadbfc9c6deba5f3081f88b0dad6c0bdf8 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Mon, 22 Nov 2021 07:12:02 +0100 Subject: [PATCH] feat: turn off the cost check before using hash joins. we'll just rely on the hint for now Signed-off-by: Andres Taylor --- go/vt/vtgate/planbuilder/gen4_planner.go | 2 -- go/vt/vtgate/planbuilder/querytree_transformers.go | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/go/vt/vtgate/planbuilder/gen4_planner.go b/go/vt/vtgate/planbuilder/gen4_planner.go index 096c0ea789d..ca6cd6b9713 100644 --- a/go/vt/vtgate/planbuilder/gen4_planner.go +++ b/go/vt/vtgate/planbuilder/gen4_planner.go @@ -27,8 +27,6 @@ import ( var _ selectPlanner = gen4Planner -const MinHashJoinCost = 5 - func gen4Planner(query string) func(sqlparser.Statement, *sqlparser.ReservedVars, ContextVSchema) (engine.Primitive, error) { return func(stmt sqlparser.Statement, reservedVars *sqlparser.ReservedVars, vschema ContextVSchema) (engine.Primitive, error) { selStatement, ok := stmt.(sqlparser.SelectStatement) diff --git a/go/vt/vtgate/planbuilder/querytree_transformers.go b/go/vt/vtgate/planbuilder/querytree_transformers.go index edf7ca10044..1292812a200 100644 --- a/go/vt/vtgate/planbuilder/querytree_transformers.go +++ b/go/vt/vtgate/planbuilder/querytree_transformers.go @@ -539,7 +539,8 @@ func transformJoinPlan(ctx *planningContext, n *joinTree) (logicalPlan, error) { // Hash joins are only supporting equality join predicates, which is why the join predicate // has to be an EqualOp. func canHashJoin(ctx *planningContext, n *joinTree) (canHash bool, lhs, rhs joinColumnInfo, err error) { - if len(n.predicatesToRemoveFromHashJoin) != 1 || n.rhs.cost() <= MinHashJoinCost || n.leftJoin || + if len(n.predicatesToRemoveFromHashJoin) != 1 || + n.leftJoin || !sqlparser.ExtractCommentDirectives(ctx.semTable.Comments).IsSet(sqlparser.DirectiveAllowHashJoin) { return }