File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,7 @@ func (d CommentDirectives) IsSet(key string) bool {
261
261
return false
262
262
}
263
263
264
+ // SkipQueryPlanCacheDirective returns true if skip query plan cache directive is set to true in query.
264
265
func SkipQueryPlanCacheDirective (stmt Statement ) (skipQuerPlanCacheDirective bool ) {
265
266
switch stmt := stmt .(type ) {
266
267
case * Select :
Original file line number Diff line number Diff line change @@ -346,3 +346,30 @@ func TestExtractCommentDirectives(t *testing.T) {
346
346
t .Errorf ("d.IsSet(six) should be false" )
347
347
}
348
348
}
349
+
350
+ func TestSkipQueryPlanCacheDirective (t * testing.T ) {
351
+ stmt , _ := Parse ("insert /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ into user(id) values (1), (2)" )
352
+ if ! SkipQueryPlanCacheDirective (stmt ) {
353
+ t .Errorf ("d.SkipQueryPlanCacheDirective(stmt) should be true" )
354
+ }
355
+
356
+ stmt , _ = Parse ("insert into user(id) values (1), (2)" )
357
+ if SkipQueryPlanCacheDirective (stmt ) {
358
+ t .Errorf ("d.SkipQueryPlanCacheDirective(stmt) should be false" )
359
+ }
360
+
361
+ stmt , _ = Parse ("update /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ users set name=1" )
362
+ if ! SkipQueryPlanCacheDirective (stmt ) {
363
+ t .Errorf ("d.SkipQueryPlanCacheDirective(stmt) should be true" )
364
+ }
365
+
366
+ stmt , _ = Parse ("select /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ * from users" )
367
+ if ! SkipQueryPlanCacheDirective (stmt ) {
368
+ t .Errorf ("d.SkipQueryPlanCacheDirective(stmt) should be true" )
369
+ }
370
+
371
+ stmt , _ = Parse ("delete /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ from users" )
372
+ if ! SkipQueryPlanCacheDirective (stmt ) {
373
+ t .Errorf ("d.SkipQueryPlanCacheDirective(stmt) should be true" )
374
+ }
375
+ }
You can’t perform that action at this time.
0 commit comments