Skip to content

Commit 4a0dad5

Browse files
Rafael Chaconbramp
authored andcommitted
Adds skip query planc cache from directive to tablets
* Given that directives change how sql comments are interpreted by vitess, refactor them from vtgate plan builder to sqlparser. Signed-off-by: Rafael Chacon <[email protected]>
1 parent 789ee6d commit 4a0dad5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

comments.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ import (
2222
"unicode"
2323
)
2424

25+
const (
26+
// DirectiveMultiShardAutocommit is the query comment directive to allow
27+
// single round trip autocommit with a multi-shard statement.
28+
DirectiveMultiShardAutocommit = "MULTI_SHARD_AUTOCOMMIT"
29+
// DirectiveSkipQueryPlanCache skips query plan cache when set.
30+
DirectiveSkipQueryPlanCache = "SKIP_QUERY_PLAN_CACHE"
31+
)
32+
2533
func isNonSpace(r rune) bool {
2634
return !unicode.IsSpace(r)
2735
}
@@ -252,3 +260,31 @@ func (d CommentDirectives) IsSet(key string) bool {
252260
}
253261
return false
254262
}
263+
264+
func SkipQueryPlanCacheDirective(stmt Statement) (skipQuerPlanCacheDirective bool) {
265+
switch stmt := stmt.(type) {
266+
case *Select:
267+
directives := ExtractCommentDirectives(stmt.Comments)
268+
if directives.IsSet(DirectiveSkipQueryPlanCache) {
269+
skipQuerPlanCacheDirective = true
270+
}
271+
case *Insert:
272+
directives := ExtractCommentDirectives(stmt.Comments)
273+
if directives.IsSet(DirectiveSkipQueryPlanCache) {
274+
skipQuerPlanCacheDirective = true
275+
}
276+
case *Update:
277+
directives := ExtractCommentDirectives(stmt.Comments)
278+
if directives.IsSet(DirectiveSkipQueryPlanCache) {
279+
skipQuerPlanCacheDirective = true
280+
}
281+
case *Delete:
282+
directives := ExtractCommentDirectives(stmt.Comments)
283+
if directives.IsSet(DirectiveSkipQueryPlanCache) {
284+
skipQuerPlanCacheDirective = true
285+
}
286+
default:
287+
skipQuerPlanCacheDirective = false
288+
}
289+
return skipQuerPlanCacheDirective
290+
}

0 commit comments

Comments
 (0)