Skip to content

Commit

Permalink
Explain Statement plan improvement (#14928)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Co-authored-by: Andres Taylor <[email protected]>
  • Loading branch information
harshit-gangal and systay authored Jan 29, 2024
1 parent 2f28985 commit 38573f0
Show file tree
Hide file tree
Showing 27 changed files with 3,739 additions and 3,746 deletions.
11 changes: 11 additions & 0 deletions changelog/19.0/19.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- **[Deprecations and Deletions](#deprecations-and-deletions)**
- [VTTablet Flags](#vttablet-flags)
- [MySQL binary in vitess/lite Docker image](#mysql-binary-in-lite-image)
- [Explain Statement Format](#explain-stmt-format)
- **[Breaking Changes](#breaking-changes)**
- [ExecuteFetchAsDBA rejects multi-statement SQL](#execute-fetch-as-dba-reject-multi)
- **[New Stats](#new-stats)**
Expand All @@ -18,6 +19,7 @@
- [Multi Table Delete Support](#multi-table-delete)
- [`SHOW VSCHEMA KEYSPACES` Query](#show-vschema-keyspaces)
- [`FOREIGN_KEY_CHECKS` is now a Vitess Aware Variable](#fk-checks-vitess-aware)
- [Explain Statement](#explain-statement)
- [Partial Multi-shard Commit Warnings](#partial-multi-shard-commit-warnings)
- **[Vttestserver](#vttestserver)**
- [`--vtcombo-bind-host` flag](#vtcombo-bind-host)
Expand Down Expand Up @@ -64,6 +66,11 @@ Below is an example of a kubernetes yaml file before and after upgrading to an o
mysql80Compatible: mysql:8.0.30 # or even mysql:8.0.34 for instance
```
#### <a id="explain-stmt-format"/>Explain Statement Format
Explain statement format `vitess` and `vexplain` were deprecated in v16 and removed in v19 version.
Use [VExplain Statement](https://vitess.io/docs/19.0/user-guides/sql/vexplain/) for understanding Vitess plans.

### <a id="breaking-changes"/>Breaking Changes

#### <a id="execute-fetch-as-dba-reject-multi"/>ExecuteFetchAsDBA rejects multi-statement SQL
Expand Down Expand Up @@ -131,6 +138,10 @@ mysql> show vschema keyspaces;

When VTGate receives a query to change the `FOREIGN_KEY_CHECKS` value for a session, instead of sending the value down to MySQL, VTGate now keeps track of the value and changes the queries by adding `SET_VAR(FOREIGN_KEY_CHECKS=On/Off)` style query optimizer hints wherever required.

#### <a id="explain-statement"/>Explain Statement

`Explain` statement can handle routed table queries now. `Explain` is unsupported when the tables involved in the query refers more than one keyspace. Users should use [VExplain Statement](https://vitess.io/docs/19.0/user-guides/sql/vexplain/) in those cases.

#### <a id="partial-multi-shard-commit-warnings"/>Partial Multi-shard Commit Warnings

When using `multi` transaction mode (the default), it is possible for Vitess to successfully commit to one shard, but fail to commit to a subsequent shard, thus breaking the atomicity of a multi-shard transaction.
Expand Down
26 changes: 20 additions & 6 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1815,10 +1815,6 @@ func (ty ExplainType) ToString() string {
return TreeStr
case JSONType:
return JSONStr
case VitessType:
return VitessStr
case VTExplainType:
return VTExplainStr
case TraditionalType:
return TraditionalStr
case AnalyzeType:
Expand Down Expand Up @@ -2154,8 +2150,8 @@ func (s SelectExprs) AllAggregation() bool {
return true
}

// RemoveKeyspace removes the Qualifier.Qualifier on all ColNames in the AST
func RemoveKeyspace(in SQLNode) {
// RemoveKeyspaceInCol removes the Qualifier.Qualifier on all ColNames in the AST
func RemoveKeyspaceInCol(in SQLNode) {
// Walk will only return an error if we return an error from the inner func. safe to ignore here
_ = Walk(func(node SQLNode) (kontinue bool, err error) {
if col, ok := node.(*ColName); ok && col.Qualifier.Qualifier.NotEmpty() {
Expand All @@ -2179,6 +2175,24 @@ func RemoveKeyspaceInTables(in SQLNode) {
})
}

// RemoveKeyspace removes the Qualifier.Qualifier on all ColNames and Qualifier on all TableNames in the AST
func RemoveKeyspace(in SQLNode) {
Rewrite(in, nil, func(cursor *Cursor) bool {
switch expr := cursor.Node().(type) {
case *ColName:
if expr.Qualifier.Qualifier.NotEmpty() {
expr.Qualifier.Qualifier = NewIdentifierCS("")
}
case TableName:
if expr.Qualifier.NotEmpty() {
expr.Qualifier = NewIdentifierCS("")
cursor.Replace(expr)
}
}
return true
})
}

func convertStringToInt(integer string) int {
val, _ := strconv.Atoi(integer)
return val
Expand Down
4 changes: 0 additions & 4 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,8 @@ const (
EmptyStr = ""
TreeStr = "tree"
JSONStr = "json"
VitessStr = "vitess"
TraditionalStr = "traditional"
AnalyzeStr = "analyze"
VTExplainStr = "vtexplain"
QueriesStr = "queries"
AllVExplainStr = "all"
PlanStr = "plan"
Expand Down Expand Up @@ -810,8 +808,6 @@ const (
EmptyType ExplainType = iota
TreeType
JSONType
VitessType
VTExplainType
TraditionalType
AnalyzeType
)
Expand Down
15 changes: 2 additions & 13 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ import (
"sync"
"testing"

"vitess.io/vitess/go/test/utils"

"github.com/google/go-cmp/cmp"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/utils"
)

var (
Expand Down Expand Up @@ -2524,16 +2523,6 @@ var (
input: "explain format = tree select * from t",
}, {
input: "explain format = json select * from t",
}, {
input: "explain format = vtexplain select * from t",
}, {
input: "explain format = vitess select * from t",
}, {
input: "describe format = vitess select * from t",
output: "explain format = vitess select * from t",
}, {
input: "describe format = vtexplain select * from t",
output: "explain format = vtexplain select * from t",
}, {
input: "explain delete from t",
}, {
Expand Down
Loading

0 comments on commit 38573f0

Please sign in to comment.