-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add a special plan type for impossible queries #4510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,17 @@ func (qre *QueryExecutor) Execute() (reply *sqltypes.Result, err error) { | |
| return qre.execDDL() | ||
| case planbuilder.PlanNextval: | ||
| return qre.execNextval() | ||
| case planbuilder.PlanSelectImpossible: | ||
| if qre.plan.Fields != nil { | ||
|
||
| return &sqltypes.Result{ | ||
| Fields: qre.plan.Fields, | ||
| RowsAffected: 0, | ||
| InsertID: 0, | ||
| Rows: nil, | ||
| Extras: nil, | ||
| }, nil | ||
| } | ||
| break | ||
| } | ||
|
|
||
| if qre.transactionID != 0 { | ||
|
|
@@ -137,7 +148,7 @@ func (qre *QueryExecutor) Execute() (reply *sqltypes.Result, err error) { | |
| return qre.execUpsertPK(conn) | ||
| case planbuilder.PlanSet: | ||
| return qre.txFetch(conn, qre.plan.FullQuery, qre.bindVars, nil, nil, true, true) | ||
| case planbuilder.PlanPassSelect, planbuilder.PlanSelectLock: | ||
| case planbuilder.PlanPassSelect, planbuilder.PlanSelectLock, planbuilder.PlanSelectImpossible: | ||
| return qre.execDirect(conn) | ||
| default: | ||
| // handled above: | ||
|
|
@@ -151,7 +162,7 @@ func (qre *QueryExecutor) Execute() (reply *sqltypes.Result, err error) { | |
| } | ||
| } else { | ||
| switch qre.plan.PlanID { | ||
| case planbuilder.PlanPassSelect: | ||
| case planbuilder.PlanPassSelect, planbuilder.PlanSelectImpossible: | ||
| return qre.execSelect() | ||
| case planbuilder.PlanSelectLock: | ||
| return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "%s disallowed outside transaction", qre.plan.PlanID.String()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1242,6 +1242,31 @@ func TestQueryExecutorPlanPassSelect(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestQueryExecutorPlanSelectImpossible(t *testing.T) { | ||
|
||
| db := setUpQueryExecutorTest(t) | ||
| defer db.Close() | ||
| query := "select * from test_table where 1 != 1" | ||
| want := &sqltypes.Result{ | ||
| Fields: getTestTableFields(), | ||
| } | ||
| db.AddQuery(query, want) | ||
| db.AddQuery("select * from test_table where 1 != 1", &sqltypes.Result{ | ||
| Fields: getTestTableFields(), | ||
| }) | ||
| ctx := context.Background() | ||
| tsv := newTestTabletServer(ctx, noFlags, db) | ||
| qre := newTestQueryExecutor(ctx, tsv, query, 0) | ||
| defer tsv.StopService() | ||
| checkPlanID(t, planbuilder.PlanSelectImpossible, qre.plan.PlanID) | ||
| got, err := qre.Execute() | ||
| if err != nil { | ||
| t.Fatalf("qre.Execute() = %v, want nil", err) | ||
| } | ||
| if !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("got: %v, want: %v", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestQueryExecutorPlanPassSelectSqlSelectLimit(t *testing.T) { | ||
| db := setUpQueryExecutorTest(t) | ||
| defer db.Close() | ||
|
|
@@ -1732,7 +1757,7 @@ func TestQueryExecutorTableAclDualTableExempt(t *testing.T) { | |
| query := "select * from test_table where 1 != 1" | ||
| qre := newTestQueryExecutor(ctx, tsv, query, 0) | ||
| defer tsv.StopService() | ||
| checkPlanID(t, planbuilder.PlanPassSelect, qre.plan.PlanID) | ||
| checkPlanID(t, planbuilder.PlanSelectImpossible, qre.plan.PlanID) | ||
| // query should fail because nobody has read access to test_table | ||
| _, err := qre.Execute() | ||
| if code := vterrors.Code(err); code != vtrpcpb.Code_PERMISSION_DENIED { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backing out the fix in this PR makes another query show up here, which is nice to see.