Skip to content

Commit

Permalink
[parser] *: add alter table read only/write support (pingcap#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored and ti-chi-bot committed Oct 9, 2021
1 parent 7f9281d commit ed62659
Show file tree
Hide file tree
Showing 5 changed files with 4,199 additions and 4,138 deletions.
9 changes: 9 additions & 0 deletions parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,7 @@ const (
AlterTableRenameTable
AlterTableAlterColumn
AlterTableLock
AlterTableWriteable
AlterTableAlgorithm
AlterTableRenameIndex
AlterTableForce
Expand Down Expand Up @@ -2291,6 +2292,7 @@ type AlterTableSpec struct {
Visibility IndexVisibility
TiFlashReplica *TiFlashReplicaSpec
PlacementSpecs []*PlacementSpec
Writeable bool
}

type TiFlashReplicaSpec struct {
Expand Down Expand Up @@ -2497,6 +2499,13 @@ func (n *AlterTableSpec) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("LOCK ")
ctx.WritePlain("= ")
ctx.WriteKeyWord(n.LockType.String())
case AlterTableWriteable:
ctx.WriteKeyWord("READ ")
if n.Writeable {
ctx.WriteKeyWord("WRITE")
} else {
ctx.WriteKeyWord("ONLY")
}
case AlterTableOrderByColumns:
ctx.WriteKeyWord("ORDER BY ")
for i, alterOrderItem := range n.OrderByList {
Expand Down
5 changes: 5 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ const (
TableLockRead
// TableLockReadLocal is not supported.
TableLockReadLocal
// TableLockReadOnly is used to set a table into read-only status,
// when the session exits, it will not release its lock automatically.
TableLockReadOnly
// TableLockWrite means only the session with this lock has write/read permission.
// Only the session that holds the lock can access the table. No other session can access it until the lock is released.
TableLockWrite
Expand All @@ -401,6 +404,8 @@ func (t TableLockType) String() string {
return "READ"
case TableLockReadLocal:
return "READ LOCAL"
case TableLockReadOnly:
return "READ ONLY"
case TableLockWriteLocal:
return "WRITE LOCAL"
case TableLockWrite:
Expand Down
Loading

0 comments on commit ed62659

Please sign in to comment.