Skip to content
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

txn: support multi-table join in nt-dml #39139

Merged
merged 8 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,15 @@ func GetTablePartitionCounter() TablePartitionUsageCounter {
// NonTransactionalStmtCounter records the usages of non-transactional statements.
type NonTransactionalStmtCounter struct {
DeleteCount int64 `json:"delete"`
UpdateCount int64 `json:"update"`
InsertCount int64 `json:"insert"`
}

// Sub returns the difference of two counters.
func (n NonTransactionalStmtCounter) Sub(rhs NonTransactionalStmtCounter) NonTransactionalStmtCounter {
return NonTransactionalStmtCounter{
DeleteCount: n.DeleteCount - rhs.DeleteCount,
UpdateCount: n.UpdateCount - rhs.UpdateCount,
InsertCount: n.InsertCount - rhs.InsertCount,
}
}
Expand All @@ -347,6 +349,7 @@ func (n NonTransactionalStmtCounter) Sub(rhs NonTransactionalStmtCounter) NonTra
func GetNonTransactionalStmtCounter() NonTransactionalStmtCounter {
return NonTransactionalStmtCounter{
DeleteCount: readCounter(NonTransactionalDMLCount.With(prometheus.Labels{LblType: "delete"})),
UpdateCount: readCounter(NonTransactionalDMLCount.With(prometheus.Labels{LblType: "update"})),
InsertCount: readCounter(NonTransactionalDMLCount.With(prometheus.Labels{LblType: "insert"})),
}
}
Expand Down
20 changes: 9 additions & 11 deletions parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2222,16 +2222,15 @@ func (n *InsertStmt) SetWhereExpr(e ExprNode) {
}

// TableSource implements ShardableDMLStmt interface.
func (n *InsertStmt) TableSource() (*TableSource, bool) {
func (n *InsertStmt) TableRefsJoin() (*Join, bool) {
if n.Select == nil {
return nil, false
}
s, ok := n.Select.(*SelectStmt)
if !ok {
return nil, false
}
table, ok := s.From.TableRefs.Left.(*TableSource)
return table, ok
return s.From.TableRefs, true
}

// DeleteStmt is a statement to delete rows from table.
Expand Down Expand Up @@ -2411,9 +2410,9 @@ func (n *DeleteStmt) SetWhereExpr(e ExprNode) {
}

// TableSource implements ShardableDMLStmt interface.
func (n *DeleteStmt) TableSource() (*TableSource, bool) {
table, ok := n.TableRefs.TableRefs.Left.(*TableSource)
return table, ok
func (n *DeleteStmt) TableRefsJoin() (*Join, bool) {
table := n.TableRefs.TableRefs
return table, true
ekexium marked this conversation as resolved.
Show resolved Hide resolved
}

const (
Expand All @@ -2426,8 +2425,8 @@ type ShardableDMLStmt = interface {
StmtNode
WhereExpr() ExprNode
SetWhereExpr(ExprNode)
// TableSource returns the *only* target table source in the statement.
TableSource() (table *TableSource, ok bool)
// TableRefsJoin returns the table refs in the statement.
TableRefsJoin() (refs *Join, ok bool)
}

var _ ShardableDMLStmt = &DeleteStmt{}
Expand Down Expand Up @@ -2650,9 +2649,8 @@ func (n *UpdateStmt) SetWhereExpr(e ExprNode) {
}

// TableSource implements ShardableDMLStmt interface.
func (n *UpdateStmt) TableSource() (*TableSource, bool) {
table, ok := n.TableRefs.TableRefs.Left.(*TableSource)
return table, ok
func (n *UpdateStmt) TableRefsJoin() (*Join, bool) {
return n.TableRefs.TableRefs, true
}

// Limit is the limit clause.
Expand Down
Loading