github.com/team-ide/go-dialect@v1.9.20/vitess/sqlparser/ast_format_fast.go (about)

     1  // Code generated by ASTFmtGen. DO NOT EDIT.
     2  /*
     3  Copyright 2021 The Vitess Authors.
     4  
     5  Licensed under the Apache License, Version 2.0 (the "License");
     6  you may not use this file except in compliance with the License.
     7  You may obtain a copy of the License at
     8  
     9      http://www.apache.org/licenses/LICENSE-2.0
    10  
    11  Unless required by applicable law or agreed to in writing, software
    12  distributed under the License is distributed on an "AS IS" BASIS,
    13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  See the License for the specific language governing permissions and
    15  limitations under the License.
    16  */
    17  
    18  package sqlparser
    19  
    20  import (
    21  	"strings"
    22  
    23  	"github.com/team-ide/go-dialect/vitess/sqltypes"
    24  )
    25  
    26  // formatFast formats the node.
    27  func (node *Select) formatFast(buf *TrackedBuffer) {
    28  	if node.With != nil {
    29  		node.With.formatFast(buf)
    30  	}
    31  	buf.WriteString("select ")
    32  	node.Comments.formatFast(buf)
    33  
    34  	if node.Distinct {
    35  		buf.WriteString(DistinctStr)
    36  	}
    37  	if node.Cache != nil {
    38  		if *node.Cache {
    39  			buf.WriteString(SQLCacheStr)
    40  		} else {
    41  			buf.WriteString(SQLNoCacheStr)
    42  		}
    43  	}
    44  	if node.StraightJoinHint {
    45  		buf.WriteString(StraightJoinHint)
    46  	}
    47  	if node.SQLCalcFoundRows {
    48  		buf.WriteString(SQLCalcFoundRowsStr)
    49  	}
    50  
    51  	node.SelectExprs.formatFast(buf)
    52  	buf.WriteString(" from ")
    53  
    54  	prefix := ""
    55  	for _, expr := range node.From {
    56  		buf.WriteString(prefix)
    57  		expr.formatFast(buf)
    58  		prefix = ", "
    59  	}
    60  
    61  	node.Where.formatFast(buf)
    62  
    63  	node.GroupBy.formatFast(buf)
    64  
    65  	node.Having.formatFast(buf)
    66  
    67  	node.OrderBy.formatFast(buf)
    68  
    69  	node.Limit.formatFast(buf)
    70  	buf.WriteString(node.Lock.ToString())
    71  	node.Into.formatFast(buf)
    72  
    73  }
    74  
    75  // formatFast formats the node.
    76  func (node *Union) formatFast(buf *TrackedBuffer) {
    77  	if requiresParen(node.Left) {
    78  		buf.WriteByte('(')
    79  		node.Left.formatFast(buf)
    80  		buf.WriteByte(')')
    81  	} else {
    82  		node.Left.formatFast(buf)
    83  	}
    84  
    85  	buf.WriteString(" ")
    86  	if node.Distinct {
    87  		buf.WriteString(UnionStr)
    88  	} else {
    89  		buf.WriteString(UnionAllStr)
    90  	}
    91  	buf.WriteString(" ")
    92  
    93  	if requiresParen(node.Right) {
    94  		buf.WriteByte('(')
    95  		node.Right.formatFast(buf)
    96  		buf.WriteByte(')')
    97  	} else {
    98  		node.Right.formatFast(buf)
    99  	}
   100  
   101  	node.OrderBy.formatFast(buf)
   102  	node.Limit.formatFast(buf)
   103  	buf.WriteString(node.Lock.ToString())
   104  }
   105  
   106  // formatFast formats the node.
   107  func (node *VStream) formatFast(buf *TrackedBuffer) {
   108  	buf.WriteString("vstream ")
   109  	node.Comments.formatFast(buf)
   110  	node.SelectExpr.formatFast(buf)
   111  	buf.WriteString(" from ")
   112  	node.Table.formatFast(buf)
   113  
   114  }
   115  
   116  // formatFast formats the node.
   117  func (node *Stream) formatFast(buf *TrackedBuffer) {
   118  	buf.WriteString("stream ")
   119  	node.Comments.formatFast(buf)
   120  	node.SelectExpr.formatFast(buf)
   121  	buf.WriteString(" from ")
   122  	node.Table.formatFast(buf)
   123  
   124  }
   125  
   126  // formatFast formats the node.
   127  func (node *Insert) formatFast(buf *TrackedBuffer) {
   128  	switch node.Action {
   129  	case InsertAct:
   130  		buf.WriteString(InsertStr)
   131  		buf.WriteByte(' ')
   132  
   133  		node.Comments.formatFast(buf)
   134  		buf.WriteString(node.Ignore.ToString())
   135  		buf.WriteString("into ")
   136  
   137  		node.Table.formatFast(buf)
   138  
   139  		node.Partitions.formatFast(buf)
   140  
   141  		node.Columns.formatFast(buf)
   142  		buf.WriteByte(' ')
   143  
   144  		node.Rows.formatFast(buf)
   145  
   146  		node.OnDup.formatFast(buf)
   147  
   148  	case ReplaceAct:
   149  		buf.WriteString(ReplaceStr)
   150  		buf.WriteByte(' ')
   151  
   152  		node.Comments.formatFast(buf)
   153  		buf.WriteString(node.Ignore.ToString())
   154  		buf.WriteString("into ")
   155  
   156  		node.Table.formatFast(buf)
   157  
   158  		node.Partitions.formatFast(buf)
   159  
   160  		node.Columns.formatFast(buf)
   161  		buf.WriteByte(' ')
   162  
   163  		node.Rows.formatFast(buf)
   164  
   165  		node.OnDup.formatFast(buf)
   166  
   167  	default:
   168  		buf.WriteString("Unkown Insert Action")
   169  		buf.WriteByte(' ')
   170  
   171  		node.Comments.formatFast(buf)
   172  		buf.WriteString(node.Ignore.ToString())
   173  		buf.WriteString("into ")
   174  
   175  		node.Table.formatFast(buf)
   176  
   177  		node.Partitions.formatFast(buf)
   178  
   179  		node.Columns.formatFast(buf)
   180  		buf.WriteByte(' ')
   181  
   182  		node.Rows.formatFast(buf)
   183  
   184  		node.OnDup.formatFast(buf)
   185  
   186  	}
   187  
   188  }
   189  
   190  // formatFast formats the node.
   191  func (node *With) formatFast(buf *TrackedBuffer) {
   192  	buf.WriteString("with ")
   193  
   194  	if node.Recursive {
   195  		buf.WriteString("recursive ")
   196  	}
   197  	ctesLength := len(node.ctes)
   198  	for i := 0; i < ctesLength-1; i++ {
   199  		node.ctes[i].formatFast(buf)
   200  		buf.WriteString(", ")
   201  	}
   202  	node.ctes[ctesLength-1].formatFast(buf)
   203  }
   204  
   205  // formatFast formats the node.
   206  func (node *CommonTableExpr) formatFast(buf *TrackedBuffer) {
   207  	node.TableID.formatFast(buf)
   208  	node.Columns.formatFast(buf)
   209  	buf.WriteString(" as ")
   210  	node.Subquery.formatFast(buf)
   211  	buf.WriteByte(' ')
   212  }
   213  
   214  // formatFast formats the node.
   215  func (node *Update) formatFast(buf *TrackedBuffer) {
   216  	if node.With != nil {
   217  		node.With.formatFast(buf)
   218  	}
   219  	buf.WriteString("update ")
   220  	node.Comments.formatFast(buf)
   221  	buf.WriteString(node.Ignore.ToString())
   222  	node.TableExprs.formatFast(buf)
   223  	buf.WriteString(" set ")
   224  
   225  	node.Exprs.formatFast(buf)
   226  
   227  	node.Where.formatFast(buf)
   228  
   229  	node.OrderBy.formatFast(buf)
   230  
   231  	node.Limit.formatFast(buf)
   232  
   233  }
   234  
   235  // formatFast formats the node.
   236  func (node *Delete) formatFast(buf *TrackedBuffer) {
   237  	if node.With != nil {
   238  		node.With.formatFast(buf)
   239  	}
   240  	buf.WriteString("delete ")
   241  	node.Comments.formatFast(buf)
   242  	if node.Ignore {
   243  		buf.WriteString("ignore ")
   244  	}
   245  	if node.Targets != nil {
   246  		node.Targets.formatFast(buf)
   247  		buf.WriteByte(' ')
   248  	}
   249  	buf.WriteString("from ")
   250  	node.TableExprs.formatFast(buf)
   251  	node.Partitions.formatFast(buf)
   252  	node.Where.formatFast(buf)
   253  	node.OrderBy.formatFast(buf)
   254  	node.Limit.formatFast(buf)
   255  }
   256  
   257  // formatFast formats the node.
   258  func (node *Set) formatFast(buf *TrackedBuffer) {
   259  	buf.WriteString("set ")
   260  	node.Comments.formatFast(buf)
   261  	node.Exprs.formatFast(buf)
   262  }
   263  
   264  // formatFast formats the node.
   265  func (node *SetTransaction) formatFast(buf *TrackedBuffer) {
   266  	if node.Scope == ImplicitScope {
   267  		buf.WriteString("set ")
   268  		node.Comments.formatFast(buf)
   269  		buf.WriteString("transaction ")
   270  	} else {
   271  		buf.WriteString("set ")
   272  		node.Comments.formatFast(buf)
   273  		buf.WriteString(node.Scope.ToString())
   274  		buf.WriteString(" transaction ")
   275  	}
   276  
   277  	for i, char := range node.Characteristics {
   278  		if i > 0 {
   279  			buf.WriteString(", ")
   280  		}
   281  		char.formatFast(buf)
   282  	}
   283  }
   284  
   285  // formatFast formats the node.
   286  func (node *DropDatabase) formatFast(buf *TrackedBuffer) {
   287  	exists := ""
   288  	if node.IfExists {
   289  		exists = "if exists "
   290  	}
   291  	buf.WriteString(DropStr)
   292  	buf.WriteByte(' ')
   293  	node.Comments.formatFast(buf)
   294  	buf.WriteString("database ")
   295  	buf.WriteString(exists)
   296  	node.DBName.formatFast(buf)
   297  }
   298  
   299  // formatFast formats the node.
   300  func (node *Flush) formatFast(buf *TrackedBuffer) {
   301  	buf.WriteString(FlushStr)
   302  	if node.IsLocal {
   303  		buf.WriteString(" local")
   304  	}
   305  	if len(node.FlushOptions) != 0 {
   306  		prefix := " "
   307  		for _, option := range node.FlushOptions {
   308  			buf.WriteString(prefix)
   309  			buf.WriteString(option)
   310  			prefix = ", "
   311  		}
   312  	} else {
   313  		buf.WriteString(" tables")
   314  		if len(node.TableNames) != 0 {
   315  			buf.WriteByte(' ')
   316  			node.TableNames.formatFast(buf)
   317  		}
   318  		if node.ForExport {
   319  			buf.WriteString(" for export")
   320  		}
   321  		if node.WithLock {
   322  			buf.WriteString(" with read lock")
   323  		}
   324  	}
   325  }
   326  
   327  // formatFast formats the node.
   328  func (node *AlterVschema) formatFast(buf *TrackedBuffer) {
   329  	switch node.Action {
   330  	case CreateVindexDDLAction:
   331  		buf.WriteString("alter vschema create vindex ")
   332  		node.Table.formatFast(buf)
   333  		buf.WriteByte(' ')
   334  		node.VindexSpec.formatFast(buf)
   335  	case DropVindexDDLAction:
   336  		buf.WriteString("alter vschema drop vindex ")
   337  		node.Table.formatFast(buf)
   338  	case AddVschemaTableDDLAction:
   339  		buf.WriteString("alter vschema add table ")
   340  		node.Table.formatFast(buf)
   341  	case DropVschemaTableDDLAction:
   342  		buf.WriteString("alter vschema drop table ")
   343  		node.Table.formatFast(buf)
   344  	case AddColVindexDDLAction:
   345  		buf.WriteString("alter vschema on ")
   346  		node.Table.formatFast(buf)
   347  		buf.WriteString(" add vindex ")
   348  		node.VindexSpec.Name.formatFast(buf)
   349  		buf.WriteString(" (")
   350  		for i, col := range node.VindexCols {
   351  			if i != 0 {
   352  				buf.WriteString(", ")
   353  				col.formatFast(buf)
   354  			} else {
   355  				col.formatFast(buf)
   356  			}
   357  		}
   358  		buf.WriteByte(')')
   359  		if node.VindexSpec.Type.String() != "" {
   360  			buf.WriteByte(' ')
   361  			node.VindexSpec.formatFast(buf)
   362  		}
   363  	case DropColVindexDDLAction:
   364  		buf.WriteString("alter vschema on ")
   365  		node.Table.formatFast(buf)
   366  		buf.WriteString(" drop vindex ")
   367  		node.VindexSpec.Name.formatFast(buf)
   368  	case AddSequenceDDLAction:
   369  		buf.WriteString("alter vschema add sequence ")
   370  		node.Table.formatFast(buf)
   371  	case AddAutoIncDDLAction:
   372  		buf.WriteString("alter vschema on ")
   373  		node.Table.formatFast(buf)
   374  		buf.WriteString(" add auto_increment ")
   375  		node.AutoIncSpec.formatFast(buf)
   376  	default:
   377  		buf.WriteString(node.Action.ToString())
   378  		buf.WriteString(" table ")
   379  		node.Table.formatFast(buf)
   380  	}
   381  }
   382  
   383  // formatFast formats the node.
   384  func (node *AlterMigration) formatFast(buf *TrackedBuffer) {
   385  	buf.WriteString("alter vitess_migration")
   386  	if node.UUID != "" {
   387  		buf.WriteString(" '")
   388  		buf.WriteString(node.UUID)
   389  		buf.WriteByte('\'')
   390  	}
   391  	var alterType string
   392  	switch node.Type {
   393  	case RetryMigrationType:
   394  		alterType = "retry"
   395  	case CleanupMigrationType:
   396  		alterType = "cleanup"
   397  	case CompleteMigrationType:
   398  		alterType = "complete"
   399  	case CancelMigrationType:
   400  		alterType = "cancel"
   401  	case CancelAllMigrationType:
   402  		alterType = "cancel all"
   403  	}
   404  	buf.WriteByte(' ')
   405  	buf.WriteString(alterType)
   406  }
   407  
   408  // formatFast formats the node.
   409  func (node *RevertMigration) formatFast(buf *TrackedBuffer) {
   410  	buf.WriteString("revert ")
   411  	node.Comments.formatFast(buf)
   412  	buf.WriteString("vitess_migration '")
   413  	buf.WriteString(node.UUID)
   414  	buf.WriteByte('\'')
   415  }
   416  
   417  // formatFast formats the node.
   418  func (node *ShowMigrationLogs) formatFast(buf *TrackedBuffer) {
   419  	buf.WriteString("show vitess_migration '")
   420  	buf.WriteString(node.UUID)
   421  	buf.WriteString("' logs")
   422  }
   423  
   424  // formatFast formats the node.
   425  func (node *OptLike) formatFast(buf *TrackedBuffer) {
   426  	buf.WriteString("like ")
   427  	node.LikeTable.formatFast(buf)
   428  }
   429  
   430  // formatFast formats the node.
   431  func (node *PartitionSpec) formatFast(buf *TrackedBuffer) {
   432  	switch node.Action {
   433  	case ReorganizeAction:
   434  		buf.WriteString(ReorganizeStr)
   435  		buf.WriteByte(' ')
   436  		for i, n := range node.Names {
   437  			if i != 0 {
   438  				buf.WriteString(", ")
   439  			}
   440  			n.formatFast(buf)
   441  		}
   442  		buf.WriteString(" into (")
   443  		for i, pd := range node.Definitions {
   444  			if i != 0 {
   445  				buf.WriteString(", ")
   446  			}
   447  			pd.formatFast(buf)
   448  		}
   449  		buf.WriteByte(')')
   450  	case AddAction:
   451  		buf.WriteString(AddStr)
   452  		buf.WriteString(" (")
   453  		node.Definitions[0].formatFast(buf)
   454  		buf.WriteByte(')')
   455  	case DropAction:
   456  		buf.WriteString(DropPartitionStr)
   457  		buf.WriteByte(' ')
   458  		for i, n := range node.Names {
   459  			if i != 0 {
   460  				buf.WriteString(", ")
   461  			}
   462  			n.formatFast(buf)
   463  		}
   464  	case DiscardAction:
   465  		buf.WriteString(DiscardStr)
   466  		buf.WriteByte(' ')
   467  		if node.IsAll {
   468  			buf.WriteString("all")
   469  		} else {
   470  			prefix := ""
   471  			for _, n := range node.Names {
   472  				buf.WriteString(prefix)
   473  				n.formatFast(buf)
   474  				prefix = ", "
   475  			}
   476  		}
   477  		buf.WriteString(" tablespace")
   478  	case ImportAction:
   479  		buf.WriteString(ImportStr)
   480  		buf.WriteByte(' ')
   481  		if node.IsAll {
   482  			buf.WriteString("all")
   483  		} else {
   484  			prefix := ""
   485  			for _, n := range node.Names {
   486  				buf.WriteString(prefix)
   487  				n.formatFast(buf)
   488  				prefix = ", "
   489  			}
   490  		}
   491  		buf.WriteString(" tablespace")
   492  	case TruncateAction:
   493  		buf.WriteString(TruncatePartitionStr)
   494  		buf.WriteByte(' ')
   495  		if node.IsAll {
   496  			buf.WriteString("all")
   497  		} else {
   498  			prefix := ""
   499  			for _, n := range node.Names {
   500  				buf.WriteString(prefix)
   501  				n.formatFast(buf)
   502  				prefix = ", "
   503  			}
   504  		}
   505  	case CoalesceAction:
   506  		buf.WriteString(CoalesceStr)
   507  		buf.WriteByte(' ')
   508  		node.Number.formatFast(buf)
   509  	case ExchangeAction:
   510  		buf.WriteString(ExchangeStr)
   511  		buf.WriteByte(' ')
   512  		node.Names[0].formatFast(buf)
   513  		buf.WriteString(" with table ")
   514  		node.TableName.formatFast(buf)
   515  		if node.WithoutValidation {
   516  			buf.WriteString(" without validation")
   517  		}
   518  	case AnalyzeAction:
   519  		buf.WriteString(AnalyzePartitionStr)
   520  		buf.WriteByte(' ')
   521  		if node.IsAll {
   522  			buf.WriteString("all")
   523  		} else {
   524  			prefix := ""
   525  			for _, n := range node.Names {
   526  				buf.WriteString(prefix)
   527  				n.formatFast(buf)
   528  				prefix = ", "
   529  			}
   530  		}
   531  	case CheckAction:
   532  		buf.WriteString(CheckStr)
   533  		buf.WriteByte(' ')
   534  		if node.IsAll {
   535  			buf.WriteString("all")
   536  		} else {
   537  			prefix := ""
   538  			for _, n := range node.Names {
   539  				buf.WriteString(prefix)
   540  				n.formatFast(buf)
   541  				prefix = ", "
   542  			}
   543  		}
   544  	case OptimizeAction:
   545  		buf.WriteString(OptimizeStr)
   546  		buf.WriteByte(' ')
   547  		if node.IsAll {
   548  			buf.WriteString("all")
   549  		} else {
   550  			prefix := ""
   551  			for _, n := range node.Names {
   552  				buf.WriteString(prefix)
   553  				n.formatFast(buf)
   554  				prefix = ", "
   555  			}
   556  		}
   557  	case RebuildAction:
   558  		buf.WriteString(RebuildStr)
   559  		buf.WriteByte(' ')
   560  		if node.IsAll {
   561  			buf.WriteString("all")
   562  		} else {
   563  			prefix := ""
   564  			for _, n := range node.Names {
   565  				buf.WriteString(prefix)
   566  				n.formatFast(buf)
   567  				prefix = ", "
   568  			}
   569  		}
   570  	case RepairAction:
   571  		buf.WriteString(RepairStr)
   572  		buf.WriteByte(' ')
   573  		if node.IsAll {
   574  			buf.WriteString("all")
   575  		} else {
   576  			prefix := ""
   577  			for _, n := range node.Names {
   578  				buf.WriteString(prefix)
   579  				n.formatFast(buf)
   580  				prefix = ", "
   581  			}
   582  		}
   583  	case RemoveAction:
   584  		buf.WriteString(RemoveStr)
   585  	case UpgradeAction:
   586  		buf.WriteString(UpgradeStr)
   587  	default:
   588  		panic("unimplemented")
   589  	}
   590  }
   591  
   592  // formatFast formats the node
   593  func (node *PartitionDefinition) formatFast(buf *TrackedBuffer) {
   594  	if !node.Maxvalue {
   595  		buf.WriteString("partition ")
   596  		node.Name.formatFast(buf)
   597  		buf.WriteString(" values less than (")
   598  		node.Limit.formatFast(buf)
   599  		buf.WriteByte(')')
   600  	} else {
   601  		buf.WriteString("partition ")
   602  		node.Name.formatFast(buf)
   603  		buf.WriteString(" values less than (maxvalue)")
   604  	}
   605  }
   606  
   607  // formatFast formats the node.
   608  func (node *PartitionOption) formatFast(buf *TrackedBuffer) {
   609  	buf.WriteString("partition by")
   610  	if node.isHASH {
   611  		if node.Linear != "" {
   612  			buf.WriteByte(' ')
   613  			buf.WriteString(node.Linear)
   614  		}
   615  		buf.WriteString(" hash")
   616  		if node.Expr != nil {
   617  			buf.WriteString(" (")
   618  			node.Expr.formatFast(buf)
   619  			buf.WriteByte(')')
   620  		}
   621  	}
   622  	if node.isKEY {
   623  		if node.Linear != "" {
   624  			buf.WriteByte(' ')
   625  			buf.WriteString(node.Linear)
   626  		}
   627  		buf.WriteString(" key")
   628  		if node.KeyAlgorithm != "" {
   629  			buf.WriteString(" algorithm = ")
   630  			buf.WriteString(node.KeyAlgorithm)
   631  		}
   632  		if node.KeyColList != nil {
   633  			buf.WriteByte(' ')
   634  			node.KeyColList.formatFast(buf)
   635  		}
   636  	}
   637  	if node.RangeOrList != "" {
   638  		buf.WriteByte(' ')
   639  		buf.WriteString(node.RangeOrList)
   640  		buf.WriteByte(' ')
   641  		node.ExprOrCol.formatFast(buf)
   642  	}
   643  	if node.Partitions != "" {
   644  		buf.WriteString(" partitions ")
   645  		buf.WriteString(node.Partitions)
   646  	}
   647  	if node.SubPartition != nil {
   648  		buf.WriteByte(' ')
   649  		node.SubPartition.formatFast(buf)
   650  	}
   651  	if node.Definitions != nil {
   652  		buf.WriteString(" (")
   653  		for i, pd := range node.Definitions {
   654  			if i != 0 {
   655  				buf.WriteString(", ")
   656  			}
   657  			pd.formatFast(buf)
   658  		}
   659  		buf.WriteString(")")
   660  	}
   661  }
   662  
   663  // formatFast formats the node.
   664  func (node *SubPartition) formatFast(buf *TrackedBuffer) {
   665  	buf.WriteString("subpartition by")
   666  	if node.isHASH {
   667  		if node.Linear != "" {
   668  			buf.WriteByte(' ')
   669  			buf.WriteString(node.Linear)
   670  		}
   671  		buf.WriteString(" hash")
   672  		if node.Expr != nil {
   673  			buf.WriteString(" (")
   674  			node.Expr.formatFast(buf)
   675  			buf.WriteByte(')')
   676  		}
   677  	}
   678  	if node.isKEY {
   679  		if node.Linear != "" {
   680  			buf.WriteByte(' ')
   681  			buf.WriteString(node.Linear)
   682  		}
   683  		buf.WriteString(" key")
   684  		if node.KeyAlgorithm != "" {
   685  			buf.WriteString(" algorithm = ")
   686  			buf.WriteString(node.KeyAlgorithm)
   687  		}
   688  		if node.KeyColList != nil {
   689  			buf.WriteString(" (")
   690  			node.KeyColList.formatFast(buf)
   691  			buf.WriteByte(')')
   692  		}
   693  	}
   694  	if node.SubPartitions != "" {
   695  		buf.WriteString(" subpartitions ")
   696  		buf.WriteString(node.SubPartitions)
   697  	}
   698  }
   699  
   700  // formatFast formats the node.
   701  func (node *ExprOrColumns) formatFast(buf *TrackedBuffer) {
   702  	if node.Expr != nil {
   703  		buf.WriteByte('(')
   704  		node.Expr.formatFast(buf)
   705  		buf.WriteByte(')')
   706  	}
   707  	if node.ColumnList != nil {
   708  		buf.WriteString("columns ")
   709  		node.ColumnList.formatFast(buf)
   710  	}
   711  }
   712  
   713  // formatFast formats the node.
   714  func (ts *TableSpec) formatFast(buf *TrackedBuffer) {
   715  	buf.WriteString("(\n")
   716  	for i, col := range ts.Columns {
   717  		if i == 0 {
   718  			buf.WriteByte('\t')
   719  			col.formatFast(buf)
   720  		} else {
   721  			buf.WriteString(",\n\t")
   722  			col.formatFast(buf)
   723  		}
   724  	}
   725  	for _, idx := range ts.Indexes {
   726  		buf.WriteString(",\n\t")
   727  		idx.formatFast(buf)
   728  	}
   729  	for _, c := range ts.Constraints {
   730  		buf.WriteString(",\n\t")
   731  		c.formatFast(buf)
   732  	}
   733  
   734  	buf.WriteString("\n)")
   735  	for i, opt := range ts.Options {
   736  		if i != 0 {
   737  			buf.WriteString(",\n ")
   738  		}
   739  		buf.WriteByte(' ')
   740  		buf.WriteString(opt.Name)
   741  		if opt.String != "" {
   742  			buf.WriteByte(' ')
   743  			buf.WriteString(opt.String)
   744  		} else if opt.Value != nil {
   745  			buf.WriteByte(' ')
   746  			opt.Value.formatFast(buf)
   747  		} else {
   748  			buf.WriteString(" (")
   749  			opt.Tables.formatFast(buf)
   750  			buf.WriteByte(')')
   751  		}
   752  	}
   753  	if ts.PartitionOption != nil {
   754  		buf.WriteByte(' ')
   755  		ts.PartitionOption.formatFast(buf)
   756  	}
   757  }
   758  
   759  // formatFast formats the node.
   760  func (col *ColumnDefinition) formatFast(buf *TrackedBuffer) {
   761  	col.Name.formatFast(buf)
   762  	buf.WriteByte(' ')
   763  	(&col.Type).formatFast(buf)
   764  }
   765  
   766  // formatFast returns a canonical string representation of the type and all relevant options
   767  func (ct *ColumnType) formatFast(buf *TrackedBuffer) {
   768  	buf.WriteString(ct.Type)
   769  
   770  	if ct.Length != nil && ct.Scale != nil {
   771  		buf.WriteByte('(')
   772  		ct.Length.formatFast(buf)
   773  		buf.WriteByte(',')
   774  		ct.Scale.formatFast(buf)
   775  		buf.WriteByte(')')
   776  
   777  	} else if ct.Length != nil {
   778  		buf.WriteByte('(')
   779  		ct.Length.formatFast(buf)
   780  		buf.WriteByte(')')
   781  	}
   782  
   783  	if ct.EnumValues != nil {
   784  		buf.WriteByte('(')
   785  		buf.WriteString(strings.Join(ct.EnumValues, ", "))
   786  		buf.WriteByte(')')
   787  	}
   788  
   789  	if ct.Unsigned {
   790  		buf.WriteByte(' ')
   791  		buf.WriteString(keywordStrings[UNSIGNED])
   792  	}
   793  	if ct.Zerofill {
   794  		buf.WriteByte(' ')
   795  		buf.WriteString(keywordStrings[ZEROFILL])
   796  	}
   797  	if ct.Charset != "" {
   798  		buf.WriteByte(' ')
   799  		buf.WriteString(keywordStrings[CHARACTER])
   800  		buf.WriteByte(' ')
   801  		buf.WriteString(keywordStrings[SET])
   802  		buf.WriteByte(' ')
   803  		buf.WriteString(ct.Charset)
   804  	}
   805  	if ct.Options != nil && ct.Options.Collate != "" {
   806  		buf.WriteByte(' ')
   807  		buf.WriteString(keywordStrings[COLLATE])
   808  		buf.WriteByte(' ')
   809  		buf.WriteString(ct.Options.Collate)
   810  	}
   811  	if ct.Options.Null != nil && ct.Options.As == nil {
   812  		if *ct.Options.Null {
   813  			buf.WriteByte(' ')
   814  			buf.WriteString(keywordStrings[NULL])
   815  		} else {
   816  			buf.WriteByte(' ')
   817  			buf.WriteString(keywordStrings[NOT])
   818  			buf.WriteByte(' ')
   819  			buf.WriteString(keywordStrings[NULL])
   820  		}
   821  	}
   822  	if ct.Options.Default != nil {
   823  		buf.WriteByte(' ')
   824  		buf.WriteString(keywordStrings[DEFAULT])
   825  		if defaultRequiresParens(ct) {
   826  			buf.WriteString(" (")
   827  			ct.Options.Default.formatFast(buf)
   828  			buf.WriteByte(')')
   829  		} else {
   830  			buf.WriteByte(' ')
   831  			ct.Options.Default.formatFast(buf)
   832  		}
   833  	}
   834  	if ct.Options.OnUpdate != nil {
   835  		buf.WriteByte(' ')
   836  		buf.WriteString(keywordStrings[ON])
   837  		buf.WriteByte(' ')
   838  		buf.WriteString(keywordStrings[UPDATE])
   839  		buf.WriteByte(' ')
   840  		ct.Options.OnUpdate.formatFast(buf)
   841  	}
   842  	if ct.Options.As != nil {
   843  		buf.WriteByte(' ')
   844  		buf.WriteString(keywordStrings[AS])
   845  		buf.WriteString(" (")
   846  		ct.Options.As.formatFast(buf)
   847  		buf.WriteByte(')')
   848  
   849  		if ct.Options.Storage == VirtualStorage {
   850  			buf.WriteByte(' ')
   851  			buf.WriteString(keywordStrings[VIRTUAL])
   852  		} else if ct.Options.Storage == StoredStorage {
   853  			buf.WriteByte(' ')
   854  			buf.WriteString(keywordStrings[STORED])
   855  		}
   856  		if ct.Options.Null != nil {
   857  			if *ct.Options.Null {
   858  				buf.WriteByte(' ')
   859  				buf.WriteString(keywordStrings[NULL])
   860  			} else {
   861  				buf.WriteByte(' ')
   862  				buf.WriteString(keywordStrings[NOT])
   863  				buf.WriteByte(' ')
   864  				buf.WriteString(keywordStrings[NULL])
   865  			}
   866  		}
   867  	}
   868  	if ct.Options.Autoincrement {
   869  		buf.WriteByte(' ')
   870  		buf.WriteString(keywordStrings[AUTO_INCREMENT])
   871  	}
   872  	if ct.Options.Comment != nil {
   873  		buf.WriteByte(' ')
   874  		buf.WriteString(keywordStrings[COMMENT_KEYWORD])
   875  		buf.WriteByte(' ')
   876  		ct.Options.Comment.formatFast(buf)
   877  	}
   878  	if ct.Options.KeyOpt == colKeyPrimary {
   879  		buf.WriteByte(' ')
   880  		buf.WriteString(keywordStrings[PRIMARY])
   881  		buf.WriteByte(' ')
   882  		buf.WriteString(keywordStrings[KEY])
   883  	}
   884  	if ct.Options.KeyOpt == colKeyUnique {
   885  		buf.WriteByte(' ')
   886  		buf.WriteString(keywordStrings[UNIQUE])
   887  	}
   888  	if ct.Options.KeyOpt == colKeyUniqueKey {
   889  		buf.WriteByte(' ')
   890  		buf.WriteString(keywordStrings[UNIQUE])
   891  		buf.WriteByte(' ')
   892  		buf.WriteString(keywordStrings[KEY])
   893  	}
   894  	if ct.Options.KeyOpt == colKeySpatialKey {
   895  		buf.WriteByte(' ')
   896  		buf.WriteString(keywordStrings[SPATIAL])
   897  		buf.WriteByte(' ')
   898  		buf.WriteString(keywordStrings[KEY])
   899  	}
   900  	if ct.Options.KeyOpt == colKeyFulltextKey {
   901  		buf.WriteByte(' ')
   902  		buf.WriteString(keywordStrings[FULLTEXT])
   903  		buf.WriteByte(' ')
   904  		buf.WriteString(keywordStrings[KEY])
   905  	}
   906  	if ct.Options.KeyOpt == colKey {
   907  		buf.WriteByte(' ')
   908  		buf.WriteString(keywordStrings[KEY])
   909  	}
   910  	if ct.Options.Reference != nil {
   911  		buf.WriteByte(' ')
   912  		ct.Options.Reference.formatFast(buf)
   913  	}
   914  }
   915  
   916  // formatFast formats the node.
   917  func (idx *IndexDefinition) formatFast(buf *TrackedBuffer) {
   918  	idx.Info.formatFast(buf)
   919  	buf.WriteString(" (")
   920  	for i, col := range idx.Columns {
   921  		if i != 0 {
   922  			buf.WriteString(", ")
   923  			col.Column.formatFast(buf)
   924  		} else {
   925  			col.Column.formatFast(buf)
   926  		}
   927  		if col.Length != nil {
   928  			buf.WriteByte('(')
   929  			col.Length.formatFast(buf)
   930  			buf.WriteByte(')')
   931  		}
   932  		if col.Direction == DescOrder {
   933  			buf.WriteString(" desc")
   934  		}
   935  	}
   936  	buf.WriteByte(')')
   937  
   938  	for _, opt := range idx.Options {
   939  		buf.WriteByte(' ')
   940  		buf.WriteString(opt.Name)
   941  		if opt.String != "" {
   942  			buf.WriteByte(' ')
   943  			buf.WriteString(opt.String)
   944  		} else {
   945  			buf.WriteByte(' ')
   946  			opt.Value.formatFast(buf)
   947  		}
   948  	}
   949  }
   950  
   951  // formatFast formats the node.
   952  func (ii *IndexInfo) formatFast(buf *TrackedBuffer) {
   953  	if !ii.ConstraintName.IsEmpty() {
   954  		buf.WriteString("constraint ")
   955  		ii.ConstraintName.formatFast(buf)
   956  		buf.WriteByte(' ')
   957  	}
   958  	if ii.Primary {
   959  		buf.WriteString(ii.Type)
   960  	} else {
   961  		buf.WriteString(ii.Type)
   962  		if !ii.Name.IsEmpty() {
   963  			buf.WriteByte(' ')
   964  			ii.Name.formatFast(buf)
   965  		}
   966  	}
   967  }
   968  
   969  // formatFast formats the node.
   970  func (node *AutoIncSpec) formatFast(buf *TrackedBuffer) {
   971  	node.Column.formatFast(buf)
   972  	buf.WriteByte(' ')
   973  	buf.WriteString("using ")
   974  	node.Sequence.formatFast(buf)
   975  }
   976  
   977  // formatFast formats the node. The "CREATE VINDEX" preamble was formatted in
   978  // the containing DDL node Format, so this just prints the type, any
   979  // parameters, and optionally the owner
   980  func (node *VindexSpec) formatFast(buf *TrackedBuffer) {
   981  	buf.WriteString("using ")
   982  	node.Type.formatFast(buf)
   983  
   984  	numParams := len(node.Params)
   985  	if numParams != 0 {
   986  		buf.WriteString(" with ")
   987  		for i, p := range node.Params {
   988  			if i != 0 {
   989  				buf.WriteString(", ")
   990  			}
   991  			p.formatFast(buf)
   992  		}
   993  	}
   994  }
   995  
   996  // formatFast formats the node.
   997  func (node VindexParam) formatFast(buf *TrackedBuffer) {
   998  	buf.WriteString(node.Key.String())
   999  	buf.WriteByte('=')
  1000  	buf.WriteString(node.Val)
  1001  }
  1002  
  1003  // formatFast formats the node.
  1004  func (c *ConstraintDefinition) formatFast(buf *TrackedBuffer) {
  1005  	if !c.Name.IsEmpty() {
  1006  		buf.WriteString("constraint ")
  1007  		c.Name.formatFast(buf)
  1008  		buf.WriteByte(' ')
  1009  	}
  1010  	c.Details.Format(buf)
  1011  }
  1012  
  1013  // formatFast formats the node.
  1014  func (a ReferenceAction) formatFast(buf *TrackedBuffer) {
  1015  	switch a {
  1016  	case Restrict:
  1017  		buf.WriteString("restrict")
  1018  	case Cascade:
  1019  		buf.WriteString("cascade")
  1020  	case NoAction:
  1021  		buf.WriteString("no action")
  1022  	case SetNull:
  1023  		buf.WriteString("set null")
  1024  	case SetDefault:
  1025  		buf.WriteString("set default")
  1026  	}
  1027  }
  1028  
  1029  // formatFast formats the node.
  1030  func (f *ForeignKeyDefinition) formatFast(buf *TrackedBuffer) {
  1031  	buf.WriteString("foreign key ")
  1032  	f.IndexName.formatFast(buf)
  1033  	f.Source.formatFast(buf)
  1034  	buf.WriteByte(' ')
  1035  	f.ReferenceDefinition.formatFast(buf)
  1036  }
  1037  
  1038  // formatFast formats the node.
  1039  func (ref *ReferenceDefinition) formatFast(buf *TrackedBuffer) {
  1040  	buf.WriteString("references ")
  1041  	ref.ReferencedTable.formatFast(buf)
  1042  	buf.WriteByte(' ')
  1043  	ref.ReferencedColumns.formatFast(buf)
  1044  	if ref.OnDelete != DefaultAction {
  1045  		buf.WriteString(" on delete ")
  1046  		ref.OnDelete.formatFast(buf)
  1047  	}
  1048  	if ref.OnUpdate != DefaultAction {
  1049  		buf.WriteString(" on update ")
  1050  		ref.OnUpdate.formatFast(buf)
  1051  	}
  1052  }
  1053  
  1054  // formatFast formats the node.
  1055  func (c *CheckConstraintDefinition) formatFast(buf *TrackedBuffer) {
  1056  	buf.WriteString("check (")
  1057  	c.Expr.formatFast(buf)
  1058  	buf.WriteByte(')')
  1059  	if !c.Enforced {
  1060  		buf.WriteString(" not enforced")
  1061  	}
  1062  }
  1063  
  1064  // formatFast formats the node.
  1065  func (node *Show) formatFast(buf *TrackedBuffer) {
  1066  	node.Internal.formatFast(buf)
  1067  }
  1068  
  1069  // formatFast formats the node.
  1070  func (node *ShowLegacy) formatFast(buf *TrackedBuffer) {
  1071  	nodeType := strings.ToLower(node.Type)
  1072  	if (nodeType == "tables" || nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys" || nodeType == "indexes" ||
  1073  		nodeType == "databases" || nodeType == "schemas" || nodeType == "keyspaces" || nodeType == "vitess_keyspaces" || nodeType == "vitess_replication_status" ||
  1074  		nodeType == "vitess_shards" || nodeType == "vitess_tablets") && node.ShowTablesOpt != nil {
  1075  		opt := node.ShowTablesOpt
  1076  		if node.Extended != "" {
  1077  			buf.WriteString("show ")
  1078  			buf.WriteString(node.Extended)
  1079  			buf.WriteString(nodeType)
  1080  		} else {
  1081  			buf.WriteString("show ")
  1082  			buf.WriteString(opt.Full)
  1083  			buf.WriteString(nodeType)
  1084  		}
  1085  		if (nodeType == "columns" || nodeType == "fields") && node.HasOnTable() {
  1086  			buf.WriteString(" from ")
  1087  			node.OnTable.formatFast(buf)
  1088  		}
  1089  		if (nodeType == "index" || nodeType == "keys" || nodeType == "indexes") && node.HasOnTable() {
  1090  			buf.WriteString(" from ")
  1091  			node.OnTable.formatFast(buf)
  1092  		}
  1093  		if opt.DbName != "" {
  1094  			buf.WriteString(" from ")
  1095  			buf.WriteString(opt.DbName)
  1096  		}
  1097  		opt.Filter.formatFast(buf)
  1098  		return
  1099  	}
  1100  	if node.Scope == ImplicitScope {
  1101  		buf.WriteString("show ")
  1102  		buf.WriteString(nodeType)
  1103  	} else {
  1104  		buf.WriteString("show ")
  1105  		buf.WriteString(node.Scope.ToString())
  1106  		buf.WriteByte(' ')
  1107  		buf.WriteString(nodeType)
  1108  	}
  1109  	if node.HasOnTable() {
  1110  		buf.WriteString(" on ")
  1111  		node.OnTable.formatFast(buf)
  1112  	}
  1113  	if nodeType == "collation" && node.ShowCollationFilterOpt != nil {
  1114  		buf.WriteString(" where ")
  1115  		node.ShowCollationFilterOpt.formatFast(buf)
  1116  	}
  1117  	if nodeType == "charset" && node.ShowTablesOpt != nil {
  1118  		node.ShowTablesOpt.Filter.formatFast(buf)
  1119  	}
  1120  	if node.HasTable() {
  1121  		buf.WriteByte(' ')
  1122  		node.Table.formatFast(buf)
  1123  	}
  1124  }
  1125  
  1126  // formatFast formats the node.
  1127  func (node *ShowFilter) formatFast(buf *TrackedBuffer) {
  1128  	if node == nil {
  1129  		return
  1130  	}
  1131  	if node.Like != "" {
  1132  		buf.WriteString(" like ")
  1133  		sqltypes.BufEncodeStringSQL(buf.Builder, node.Like)
  1134  	} else {
  1135  		buf.WriteString(" where ")
  1136  		node.Filter.formatFast(buf)
  1137  	}
  1138  }
  1139  
  1140  // formatFast formats the node.
  1141  func (node *Use) formatFast(buf *TrackedBuffer) {
  1142  	if node.DBName.v != "" {
  1143  		buf.WriteString("use ")
  1144  		node.DBName.formatFast(buf)
  1145  	} else {
  1146  		buf.WriteString("use")
  1147  	}
  1148  }
  1149  
  1150  // formatFast formats the node.
  1151  func (node *Commit) formatFast(buf *TrackedBuffer) {
  1152  	buf.WriteString("commit")
  1153  }
  1154  
  1155  // formatFast formats the node.
  1156  func (node *Begin) formatFast(buf *TrackedBuffer) {
  1157  	buf.WriteString("begin")
  1158  }
  1159  
  1160  // formatFast formats the node.
  1161  func (node *Rollback) formatFast(buf *TrackedBuffer) {
  1162  	buf.WriteString("rollback")
  1163  }
  1164  
  1165  // formatFast formats the node.
  1166  func (node *SRollback) formatFast(buf *TrackedBuffer) {
  1167  	buf.WriteString("rollback to ")
  1168  	node.Name.formatFast(buf)
  1169  }
  1170  
  1171  // formatFast formats the node.
  1172  func (node *Savepoint) formatFast(buf *TrackedBuffer) {
  1173  	buf.WriteString("savepoint ")
  1174  	node.Name.formatFast(buf)
  1175  }
  1176  
  1177  // formatFast formats the node.
  1178  func (node *Release) formatFast(buf *TrackedBuffer) {
  1179  	buf.WriteString("release savepoint ")
  1180  	node.Name.formatFast(buf)
  1181  }
  1182  
  1183  // formatFast formats the node.
  1184  func (node *ExplainStmt) formatFast(buf *TrackedBuffer) {
  1185  	format := ""
  1186  	switch node.Type {
  1187  	case EmptyType:
  1188  	case AnalyzeType:
  1189  		format = AnalyzeStr + " "
  1190  	default:
  1191  		format = "format = " + node.Type.ToString() + " "
  1192  	}
  1193  	buf.WriteString("explain ")
  1194  	buf.WriteString(format)
  1195  	node.Statement.formatFast(buf)
  1196  }
  1197  
  1198  // formatFast formats the node.
  1199  func (node *ExplainTab) formatFast(buf *TrackedBuffer) {
  1200  	buf.WriteString("explain ")
  1201  	node.Table.formatFast(buf)
  1202  	if node.Wild != "" {
  1203  		buf.WriteByte(' ')
  1204  		buf.WriteString(node.Wild)
  1205  	}
  1206  }
  1207  
  1208  // formatFast formats the node.
  1209  func (node *CallProc) formatFast(buf *TrackedBuffer) {
  1210  	buf.WriteString("call ")
  1211  	node.Name.formatFast(buf)
  1212  	buf.WriteByte('(')
  1213  	node.Params.formatFast(buf)
  1214  	buf.WriteByte(')')
  1215  }
  1216  
  1217  // formatFast formats the node.
  1218  func (node *OtherRead) formatFast(buf *TrackedBuffer) {
  1219  	buf.WriteString("otherread")
  1220  }
  1221  
  1222  // formatFast formats the node.
  1223  func (node *OtherAdmin) formatFast(buf *TrackedBuffer) {
  1224  	buf.WriteString("otheradmin")
  1225  }
  1226  
  1227  // formatFast formats the node.
  1228  func (node Comments) formatFast(buf *TrackedBuffer) {
  1229  	for _, c := range node {
  1230  		buf.WriteString(c)
  1231  		buf.WriteByte(' ')
  1232  	}
  1233  }
  1234  
  1235  // formatFast formats the node.
  1236  func (node SelectExprs) formatFast(buf *TrackedBuffer) {
  1237  	var prefix string
  1238  	for _, n := range node {
  1239  		buf.WriteString(prefix)
  1240  		n.formatFast(buf)
  1241  		prefix = ", "
  1242  	}
  1243  }
  1244  
  1245  // formatFast formats the node.
  1246  func (node *StarExpr) formatFast(buf *TrackedBuffer) {
  1247  	if !node.TableName.IsEmpty() {
  1248  		node.TableName.formatFast(buf)
  1249  		buf.WriteByte('.')
  1250  	}
  1251  	buf.WriteByte('*')
  1252  }
  1253  
  1254  // formatFast formats the node.
  1255  func (node *AliasedExpr) formatFast(buf *TrackedBuffer) {
  1256  	node.Expr.formatFast(buf)
  1257  	if !node.As.IsEmpty() {
  1258  		buf.WriteString(" as ")
  1259  		node.As.formatFast(buf)
  1260  	}
  1261  }
  1262  
  1263  // formatFast formats the node.
  1264  func (node *Nextval) formatFast(buf *TrackedBuffer) {
  1265  	buf.WriteString("next ")
  1266  	node.Expr.formatFast(buf)
  1267  	buf.WriteString(" values")
  1268  }
  1269  
  1270  // formatFast formats the node.
  1271  func (node Columns) formatFast(buf *TrackedBuffer) {
  1272  	if node == nil {
  1273  		return
  1274  	}
  1275  	prefix := "("
  1276  	for _, n := range node {
  1277  		buf.WriteString(prefix)
  1278  		n.formatFast(buf)
  1279  		prefix = ", "
  1280  	}
  1281  	buf.WriteString(")")
  1282  }
  1283  
  1284  // formatFast formats the node
  1285  func (node Partitions) formatFast(buf *TrackedBuffer) {
  1286  	if node == nil {
  1287  		return
  1288  	}
  1289  	prefix := " partition ("
  1290  	for _, n := range node {
  1291  		buf.WriteString(prefix)
  1292  		n.formatFast(buf)
  1293  		prefix = ", "
  1294  	}
  1295  	buf.WriteString(")")
  1296  }
  1297  
  1298  // formatFast formats the node.
  1299  func (node TableExprs) formatFast(buf *TrackedBuffer) {
  1300  	var prefix string
  1301  	for _, n := range node {
  1302  		buf.WriteString(prefix)
  1303  		n.formatFast(buf)
  1304  		prefix = ", "
  1305  	}
  1306  }
  1307  
  1308  // formatFast formats the node.
  1309  func (node *AliasedTableExpr) formatFast(buf *TrackedBuffer) {
  1310  	node.Expr.formatFast(buf)
  1311  	node.Partitions.formatFast(buf)
  1312  	if !node.As.IsEmpty() {
  1313  		buf.WriteString(" as ")
  1314  		node.As.formatFast(buf)
  1315  		if len(node.Columns) != 0 {
  1316  			node.Columns.formatFast(buf)
  1317  		}
  1318  	}
  1319  	if node.Hints != nil {
  1320  		// Hint node provides the space padding.
  1321  		node.Hints.formatFast(buf)
  1322  	}
  1323  }
  1324  
  1325  // formatFast formats the node.
  1326  func (node TableNames) formatFast(buf *TrackedBuffer) {
  1327  	var prefix string
  1328  	for _, n := range node {
  1329  		buf.WriteString(prefix)
  1330  		n.formatFast(buf)
  1331  		prefix = ", "
  1332  	}
  1333  }
  1334  
  1335  // formatFast formats the node.
  1336  func (node TableName) formatFast(buf *TrackedBuffer) {
  1337  	if node.IsEmpty() {
  1338  		return
  1339  	}
  1340  	if !node.Qualifier.IsEmpty() {
  1341  		node.Qualifier.formatFast(buf)
  1342  		buf.WriteByte('.')
  1343  	}
  1344  	node.Name.formatFast(buf)
  1345  }
  1346  
  1347  // formatFast formats the node.
  1348  func (node *ParenTableExpr) formatFast(buf *TrackedBuffer) {
  1349  	buf.WriteByte('(')
  1350  	node.Exprs.formatFast(buf)
  1351  	buf.WriteByte(')')
  1352  }
  1353  
  1354  // formatFast formats the node.
  1355  func (node *JoinCondition) formatFast(buf *TrackedBuffer) {
  1356  	if node == nil {
  1357  		return
  1358  	}
  1359  	if node.On != nil {
  1360  		buf.WriteString(" on ")
  1361  		node.On.formatFast(buf)
  1362  	}
  1363  	if node.Using != nil {
  1364  		buf.WriteString(" using ")
  1365  		node.Using.formatFast(buf)
  1366  	}
  1367  }
  1368  
  1369  // formatFast formats the node.
  1370  func (node *JoinTableExpr) formatFast(buf *TrackedBuffer) {
  1371  	node.LeftExpr.formatFast(buf)
  1372  	buf.WriteByte(' ')
  1373  	buf.WriteString(node.Join.ToString())
  1374  	buf.WriteByte(' ')
  1375  	node.RightExpr.formatFast(buf)
  1376  	node.Condition.formatFast(buf)
  1377  }
  1378  
  1379  // formatFast formats the node.
  1380  func (node *IndexHints) formatFast(buf *TrackedBuffer) {
  1381  	buf.WriteByte(' ')
  1382  	buf.WriteString(node.Type.ToString())
  1383  	buf.WriteString("index ")
  1384  	if len(node.Indexes) == 0 {
  1385  		buf.WriteString("()")
  1386  	} else {
  1387  		prefix := "("
  1388  		for _, n := range node.Indexes {
  1389  			buf.WriteString(prefix)
  1390  			n.formatFast(buf)
  1391  			prefix = ", "
  1392  		}
  1393  		buf.WriteByte(')')
  1394  	}
  1395  }
  1396  
  1397  // formatFast formats the node.
  1398  func (node *Where) formatFast(buf *TrackedBuffer) {
  1399  	if node == nil || node.Expr == nil {
  1400  		return
  1401  	}
  1402  	buf.WriteByte(' ')
  1403  	buf.WriteString(node.Type.ToString())
  1404  	buf.WriteByte(' ')
  1405  	node.Expr.formatFast(buf)
  1406  }
  1407  
  1408  // formatFast formats the node.
  1409  func (node Exprs) formatFast(buf *TrackedBuffer) {
  1410  	var prefix string
  1411  	for _, n := range node {
  1412  		buf.WriteString(prefix)
  1413  		n.formatFast(buf)
  1414  		prefix = ", "
  1415  	}
  1416  }
  1417  
  1418  // formatFast formats the node.
  1419  func (node *AndExpr) formatFast(buf *TrackedBuffer) {
  1420  	buf.printExpr(node, node.Left, true)
  1421  	buf.WriteString(" and ")
  1422  	buf.printExpr(node, node.Right, false)
  1423  }
  1424  
  1425  // formatFast formats the node.
  1426  func (node *OrExpr) formatFast(buf *TrackedBuffer) {
  1427  	buf.printExpr(node, node.Left, true)
  1428  	buf.WriteString(" or ")
  1429  	buf.printExpr(node, node.Right, false)
  1430  }
  1431  
  1432  // formatFast formats the node.
  1433  func (node *XorExpr) formatFast(buf *TrackedBuffer) {
  1434  	buf.printExpr(node, node.Left, true)
  1435  	buf.WriteString(" xor ")
  1436  	buf.printExpr(node, node.Right, false)
  1437  }
  1438  
  1439  // formatFast formats the node.
  1440  func (node *NotExpr) formatFast(buf *TrackedBuffer) {
  1441  	buf.WriteString("not ")
  1442  	buf.printExpr(node, node.Expr, true)
  1443  }
  1444  
  1445  // formatFast formats the node.
  1446  func (node *ComparisonExpr) formatFast(buf *TrackedBuffer) {
  1447  	buf.printExpr(node, node.Left, true)
  1448  	buf.WriteByte(' ')
  1449  	buf.WriteString(node.Operator.ToString())
  1450  	buf.WriteByte(' ')
  1451  	buf.printExpr(node, node.Right, false)
  1452  	if node.Escape != nil {
  1453  		buf.WriteString(" escape ")
  1454  		buf.printExpr(node, node.Escape, true)
  1455  	}
  1456  }
  1457  
  1458  // formatFast formats the node.
  1459  func (node *BetweenExpr) formatFast(buf *TrackedBuffer) {
  1460  	if node.IsBetween {
  1461  		buf.printExpr(node, node.Left, true)
  1462  		buf.WriteString(" between ")
  1463  		buf.printExpr(node, node.From, true)
  1464  		buf.WriteString(" and ")
  1465  		buf.printExpr(node, node.To, false)
  1466  	} else {
  1467  		buf.printExpr(node, node.Left, true)
  1468  		buf.WriteString(" not between ")
  1469  		buf.printExpr(node, node.From, true)
  1470  		buf.WriteString(" and ")
  1471  		buf.printExpr(node, node.To, false)
  1472  	}
  1473  }
  1474  
  1475  // formatFast formats the node.
  1476  func (node *IsExpr) formatFast(buf *TrackedBuffer) {
  1477  	buf.printExpr(node, node.Left, true)
  1478  	buf.WriteByte(' ')
  1479  	buf.WriteString(node.Right.ToString())
  1480  }
  1481  
  1482  // formatFast formats the node.
  1483  func (node *ExistsExpr) formatFast(buf *TrackedBuffer) {
  1484  	buf.WriteString("exists ")
  1485  	buf.printExpr(node, node.Subquery, true)
  1486  }
  1487  
  1488  // formatFast formats the node.
  1489  func (node *Literal) formatFast(buf *TrackedBuffer) {
  1490  	switch node.Type {
  1491  	case StrVal:
  1492  		sqltypes.MakeTrusted(sqltypes.VarBinary, node.Bytes()).EncodeSQL(buf)
  1493  	case IntVal, FloatVal, DecimalVal, HexNum:
  1494  		buf.WriteString(node.Val)
  1495  	case HexVal:
  1496  		buf.WriteString("X'")
  1497  		buf.WriteString(node.Val)
  1498  		buf.WriteByte('\'')
  1499  	case BitVal:
  1500  		buf.WriteString("B'")
  1501  		buf.WriteString(node.Val)
  1502  		buf.WriteByte('\'')
  1503  	default:
  1504  		panic("unexpected")
  1505  	}
  1506  }
  1507  
  1508  // formatFast formats the node.
  1509  func (node Argument) formatFast(buf *TrackedBuffer) {
  1510  	buf.WriteArg(":", string(node))
  1511  }
  1512  
  1513  // formatFast formats the node.
  1514  func (node *NullVal) formatFast(buf *TrackedBuffer) {
  1515  	buf.WriteString("null")
  1516  }
  1517  
  1518  // formatFast formats the node.
  1519  func (node BoolVal) formatFast(buf *TrackedBuffer) {
  1520  	if node {
  1521  		buf.WriteString("true")
  1522  	} else {
  1523  		buf.WriteString("false")
  1524  	}
  1525  }
  1526  
  1527  // formatFast formats the node.
  1528  func (node *ColName) formatFast(buf *TrackedBuffer) {
  1529  	if !node.Qualifier.IsEmpty() {
  1530  		node.Qualifier.formatFast(buf)
  1531  		buf.WriteByte('.')
  1532  	}
  1533  	node.Name.formatFast(buf)
  1534  }
  1535  
  1536  // formatFast formats the node.
  1537  func (node ValTuple) formatFast(buf *TrackedBuffer) {
  1538  	buf.WriteByte('(')
  1539  	Exprs(node).formatFast(buf)
  1540  	buf.WriteByte(')')
  1541  }
  1542  
  1543  // formatFast formats the node.
  1544  func (node *Subquery) formatFast(buf *TrackedBuffer) {
  1545  	buf.WriteByte('(')
  1546  	node.Select.formatFast(buf)
  1547  	buf.WriteByte(')')
  1548  }
  1549  
  1550  // formatFast formats the node.
  1551  func (node *DerivedTable) formatFast(buf *TrackedBuffer) {
  1552  	buf.WriteByte('(')
  1553  	node.Select.formatFast(buf)
  1554  	buf.WriteByte(')')
  1555  }
  1556  
  1557  // formatFast formats the node.
  1558  func (node ListArg) formatFast(buf *TrackedBuffer) {
  1559  	buf.WriteArg("::", string(node))
  1560  }
  1561  
  1562  // formatFast formats the node.
  1563  func (node *BinaryExpr) formatFast(buf *TrackedBuffer) {
  1564  	buf.printExpr(node, node.Left, true)
  1565  	buf.WriteByte(' ')
  1566  	buf.WriteString(node.Operator.ToString())
  1567  	buf.WriteByte(' ')
  1568  	buf.printExpr(node, node.Right, false)
  1569  }
  1570  
  1571  // formatFast formats the node.
  1572  func (node *UnaryExpr) formatFast(buf *TrackedBuffer) {
  1573  	if _, unary := node.Expr.(*UnaryExpr); unary {
  1574  		// They have same precedence so parenthesis is not required.
  1575  		buf.WriteString(node.Operator.ToString())
  1576  		buf.WriteByte(' ')
  1577  		buf.printExpr(node, node.Expr, true)
  1578  		return
  1579  	}
  1580  	buf.WriteString(node.Operator.ToString())
  1581  	buf.printExpr(node, node.Expr, true)
  1582  }
  1583  
  1584  // formatFast formats the node.
  1585  func (node *IntroducerExpr) formatFast(buf *TrackedBuffer) {
  1586  	buf.WriteString(node.CharacterSet)
  1587  	buf.WriteByte(' ')
  1588  	buf.printExpr(node, node.Expr, true)
  1589  }
  1590  
  1591  // formatFast formats the node.
  1592  func (node *IntervalExpr) formatFast(buf *TrackedBuffer) {
  1593  	buf.WriteString("interval ")
  1594  	buf.printExpr(node, node.Expr, true)
  1595  	buf.WriteByte(' ')
  1596  	buf.WriteString(node.Unit)
  1597  }
  1598  
  1599  // formatFast formats the node.
  1600  func (node *TimestampFuncExpr) formatFast(buf *TrackedBuffer) {
  1601  	buf.WriteString(node.Name)
  1602  	buf.WriteByte('(')
  1603  	buf.WriteString(node.Unit)
  1604  	buf.WriteString(", ")
  1605  	buf.printExpr(node, node.Expr1, true)
  1606  	buf.WriteString(", ")
  1607  	buf.printExpr(node, node.Expr2, true)
  1608  	buf.WriteByte(')')
  1609  }
  1610  
  1611  // formatFast formats the node.
  1612  func (node *ExtractFuncExpr) formatFast(buf *TrackedBuffer) {
  1613  	buf.WriteString("extract(")
  1614  	buf.WriteString(node.IntervalTypes.ToString())
  1615  	buf.WriteString(" from ")
  1616  	buf.printExpr(node, node.Expr, true)
  1617  	buf.WriteByte(')')
  1618  }
  1619  
  1620  // formatFast formats the node.
  1621  func (node *CurTimeFuncExpr) formatFast(buf *TrackedBuffer) {
  1622  	if node.Fsp != nil {
  1623  		buf.WriteString(node.Name.String())
  1624  		buf.WriteByte('(')
  1625  		buf.printExpr(node, node.Fsp, true)
  1626  		buf.WriteByte(')')
  1627  	} else {
  1628  		buf.WriteString(node.Name.String())
  1629  		buf.WriteString("()")
  1630  	}
  1631  }
  1632  
  1633  // formatFast formats the node.
  1634  func (node *CollateExpr) formatFast(buf *TrackedBuffer) {
  1635  	buf.printExpr(node, node.Expr, true)
  1636  	buf.WriteString(" collate ")
  1637  	buf.WriteString(node.Collation)
  1638  }
  1639  
  1640  // formatFast formats the node.
  1641  func (node *FuncExpr) formatFast(buf *TrackedBuffer) {
  1642  	var distinct string
  1643  	if node.Distinct {
  1644  		distinct = "distinct "
  1645  	}
  1646  	if !node.Qualifier.IsEmpty() {
  1647  		node.Qualifier.formatFast(buf)
  1648  		buf.WriteByte('.')
  1649  	}
  1650  	// Function names should not be back-quoted even
  1651  	// if they match a reserved word, only if they contain illegal characters
  1652  	funcName := node.Name.String()
  1653  
  1654  	if containEscapableChars(funcName, NoAt) {
  1655  		writeEscapedString(buf, funcName)
  1656  	} else {
  1657  		buf.WriteString(funcName)
  1658  	}
  1659  	buf.WriteByte('(')
  1660  	buf.WriteString(distinct)
  1661  	node.Exprs.formatFast(buf)
  1662  	buf.WriteByte(')')
  1663  }
  1664  
  1665  // formatFast formats the node
  1666  func (node *GroupConcatExpr) formatFast(buf *TrackedBuffer) {
  1667  	if node.Distinct {
  1668  		buf.WriteString("group_concat(")
  1669  		buf.WriteString(DistinctStr)
  1670  		node.Exprs.formatFast(buf)
  1671  		node.OrderBy.formatFast(buf)
  1672  		buf.WriteString(node.Separator)
  1673  		node.Limit.formatFast(buf)
  1674  		buf.WriteByte(')')
  1675  	} else {
  1676  		buf.WriteString("group_concat(")
  1677  		node.Exprs.formatFast(buf)
  1678  		node.OrderBy.formatFast(buf)
  1679  		buf.WriteString(node.Separator)
  1680  		node.Limit.formatFast(buf)
  1681  		buf.WriteByte(')')
  1682  	}
  1683  }
  1684  
  1685  // formatFast formats the node.
  1686  func (node *ValuesFuncExpr) formatFast(buf *TrackedBuffer) {
  1687  	buf.WriteString("values(")
  1688  	buf.printExpr(node, node.Name, true)
  1689  	buf.WriteByte(')')
  1690  }
  1691  
  1692  // formatFast formats the node.
  1693  func (node *SubstrExpr) formatFast(buf *TrackedBuffer) {
  1694  	if node.To == nil {
  1695  		buf.WriteString("substr(")
  1696  		buf.printExpr(node, node.Name, true)
  1697  		buf.WriteString(", ")
  1698  		buf.printExpr(node, node.From, true)
  1699  		buf.WriteByte(')')
  1700  	} else {
  1701  		buf.WriteString("substr(")
  1702  		buf.printExpr(node, node.Name, true)
  1703  		buf.WriteString(", ")
  1704  		buf.printExpr(node, node.From, true)
  1705  		buf.WriteString(", ")
  1706  		buf.printExpr(node, node.To, true)
  1707  		buf.WriteByte(')')
  1708  	}
  1709  }
  1710  
  1711  // formatFast formats the node.
  1712  func (node *ConvertExpr) formatFast(buf *TrackedBuffer) {
  1713  	buf.WriteString("convert(")
  1714  	buf.printExpr(node, node.Expr, true)
  1715  	buf.WriteString(", ")
  1716  	node.Type.formatFast(buf)
  1717  	buf.WriteByte(')')
  1718  }
  1719  
  1720  // formatFast formats the node.
  1721  func (node *ConvertUsingExpr) formatFast(buf *TrackedBuffer) {
  1722  	buf.WriteString("convert(")
  1723  	buf.printExpr(node, node.Expr, true)
  1724  	buf.WriteString(" using ")
  1725  	buf.WriteString(node.Type)
  1726  	buf.WriteByte(')')
  1727  }
  1728  
  1729  // formatFast formats the node.
  1730  func (node *ConvertType) formatFast(buf *TrackedBuffer) {
  1731  	buf.WriteString(node.Type)
  1732  	if node.Length != nil {
  1733  		buf.WriteByte('(')
  1734  		node.Length.formatFast(buf)
  1735  		if node.Scale != nil {
  1736  			buf.WriteString(", ")
  1737  			node.Scale.formatFast(buf)
  1738  		}
  1739  		buf.WriteByte(')')
  1740  	}
  1741  	if node.Charset != "" {
  1742  		buf.WriteString(node.Operator.ToString())
  1743  		buf.WriteByte(' ')
  1744  		buf.WriteString(node.Charset)
  1745  	}
  1746  }
  1747  
  1748  // formatFast formats the node
  1749  func (node *MatchExpr) formatFast(buf *TrackedBuffer) {
  1750  	buf.WriteString("match(")
  1751  	node.Columns.formatFast(buf)
  1752  	buf.WriteString(") against (")
  1753  	buf.printExpr(node, node.Expr, true)
  1754  	buf.WriteString(node.Option.ToString())
  1755  	buf.WriteByte(')')
  1756  }
  1757  
  1758  // formatFast formats the node.
  1759  func (node *CaseExpr) formatFast(buf *TrackedBuffer) {
  1760  	buf.WriteString("case ")
  1761  	if node.Expr != nil {
  1762  		buf.printExpr(node, node.Expr, true)
  1763  		buf.WriteByte(' ')
  1764  	}
  1765  	for _, when := range node.Whens {
  1766  		when.formatFast(buf)
  1767  		buf.WriteByte(' ')
  1768  	}
  1769  	if node.Else != nil {
  1770  		buf.WriteString("else ")
  1771  		buf.printExpr(node, node.Else, true)
  1772  		buf.WriteByte(' ')
  1773  	}
  1774  	buf.WriteString("end")
  1775  }
  1776  
  1777  // formatFast formats the node.
  1778  func (node *Default) formatFast(buf *TrackedBuffer) {
  1779  	buf.WriteString("default")
  1780  	if node.ColName != "" {
  1781  		buf.WriteString("(")
  1782  		formatID(buf, node.ColName, NoAt)
  1783  		buf.WriteString(")")
  1784  	}
  1785  }
  1786  
  1787  // formatFast formats the node.
  1788  func (node *When) formatFast(buf *TrackedBuffer) {
  1789  	buf.WriteString("when ")
  1790  	node.Cond.formatFast(buf)
  1791  	buf.WriteString(" then ")
  1792  	node.Val.formatFast(buf)
  1793  }
  1794  
  1795  // formatFast formats the node.
  1796  func (node GroupBy) formatFast(buf *TrackedBuffer) {
  1797  	prefix := " group by "
  1798  	for _, n := range node {
  1799  		buf.WriteString(prefix)
  1800  		n.formatFast(buf)
  1801  		prefix = ", "
  1802  	}
  1803  }
  1804  
  1805  // formatFast formats the node.
  1806  func (node OrderBy) formatFast(buf *TrackedBuffer) {
  1807  	prefix := " order by "
  1808  	for _, n := range node {
  1809  		buf.WriteString(prefix)
  1810  		n.formatFast(buf)
  1811  		prefix = ", "
  1812  	}
  1813  }
  1814  
  1815  // formatFast formats the node.
  1816  func (node *Order) formatFast(buf *TrackedBuffer) {
  1817  	if node, ok := node.Expr.(*NullVal); ok {
  1818  		buf.printExpr(node, node, true)
  1819  		return
  1820  	}
  1821  	if node, ok := node.Expr.(*FuncExpr); ok {
  1822  		if node.Name.Lowered() == "rand" {
  1823  			buf.printExpr(node, node, true)
  1824  			return
  1825  		}
  1826  	}
  1827  
  1828  	node.Expr.formatFast(buf)
  1829  	buf.WriteByte(' ')
  1830  	buf.WriteString(node.Direction.ToString())
  1831  }
  1832  
  1833  // formatFast formats the node.
  1834  func (node *Limit) formatFast(buf *TrackedBuffer) {
  1835  	if node == nil {
  1836  		return
  1837  	}
  1838  	buf.WriteString(" limit ")
  1839  	if node.Offset != nil {
  1840  		node.Offset.formatFast(buf)
  1841  		buf.WriteString(", ")
  1842  	}
  1843  	node.Rowcount.formatFast(buf)
  1844  }
  1845  
  1846  // formatFast formats the node.
  1847  func (node Values) formatFast(buf *TrackedBuffer) {
  1848  	prefix := "values "
  1849  	for _, n := range node {
  1850  		buf.WriteString(prefix)
  1851  		n.formatFast(buf)
  1852  		prefix = ", "
  1853  	}
  1854  }
  1855  
  1856  // formatFast formats the node.
  1857  func (node UpdateExprs) formatFast(buf *TrackedBuffer) {
  1858  	var prefix string
  1859  	for _, n := range node {
  1860  		buf.WriteString(prefix)
  1861  		n.formatFast(buf)
  1862  		prefix = ", "
  1863  	}
  1864  }
  1865  
  1866  // formatFast formats the node.
  1867  func (node *UpdateExpr) formatFast(buf *TrackedBuffer) {
  1868  	node.Name.formatFast(buf)
  1869  	buf.WriteString(" = ")
  1870  	node.Expr.formatFast(buf)
  1871  }
  1872  
  1873  // formatFast formats the node.
  1874  func (node SetExprs) formatFast(buf *TrackedBuffer) {
  1875  	var prefix string
  1876  	for _, n := range node {
  1877  		buf.WriteString(prefix)
  1878  		n.formatFast(buf)
  1879  		prefix = ", "
  1880  	}
  1881  }
  1882  
  1883  // formatFast formats the node.
  1884  func (node *SetExpr) formatFast(buf *TrackedBuffer) {
  1885  	if node.Scope != ImplicitScope {
  1886  		buf.WriteString(node.Scope.ToString())
  1887  		buf.WriteString(" ")
  1888  	}
  1889  	// We don't have to backtick set variable names.
  1890  	switch {
  1891  	case node.Name.EqualString("charset") || node.Name.EqualString("names"):
  1892  		buf.WriteString(node.Name.String())
  1893  		buf.WriteByte(' ')
  1894  		node.Expr.formatFast(buf)
  1895  	case node.Name.EqualString(TransactionStr):
  1896  		literal := node.Expr.(*Literal)
  1897  		buf.WriteString(node.Name.String())
  1898  		buf.WriteByte(' ')
  1899  		buf.WriteString(strings.ToLower(string(literal.Val)))
  1900  	default:
  1901  		node.Name.formatFast(buf)
  1902  		buf.WriteString(" = ")
  1903  		node.Expr.formatFast(buf)
  1904  	}
  1905  }
  1906  
  1907  // formatFast formats the node.
  1908  func (node OnDup) formatFast(buf *TrackedBuffer) {
  1909  	if node == nil {
  1910  		return
  1911  	}
  1912  	buf.WriteString(" on duplicate key update ")
  1913  	UpdateExprs(node).formatFast(buf)
  1914  }
  1915  
  1916  // formatFast formats the node.
  1917  func (node ColIdent) formatFast(buf *TrackedBuffer) {
  1918  	for i := NoAt; i < node.at; i++ {
  1919  		buf.WriteByte('@')
  1920  	}
  1921  	formatID(buf, node.val, node.at)
  1922  }
  1923  
  1924  // formatFast formats the node.
  1925  func (node TableIdent) formatFast(buf *TrackedBuffer) {
  1926  	formatID(buf, node.v, NoAt)
  1927  }
  1928  
  1929  // formatFast formats the node.
  1930  func (node IsolationLevel) formatFast(buf *TrackedBuffer) {
  1931  	buf.WriteString("isolation level ")
  1932  	switch node {
  1933  	case ReadUncommitted:
  1934  		buf.WriteString(ReadUncommittedStr)
  1935  	case ReadCommitted:
  1936  		buf.WriteString(ReadCommittedStr)
  1937  	case RepeatableRead:
  1938  		buf.WriteString(RepeatableReadStr)
  1939  	case Serializable:
  1940  		buf.WriteString(SerializableStr)
  1941  	default:
  1942  		buf.WriteString("Unknown Isolation level value")
  1943  	}
  1944  }
  1945  
  1946  // formatFast formats the node.
  1947  func (node AccessMode) formatFast(buf *TrackedBuffer) {
  1948  	if node == ReadOnly {
  1949  		buf.WriteString(TxReadOnly)
  1950  	} else {
  1951  		buf.WriteString(TxReadWrite)
  1952  	}
  1953  }
  1954  
  1955  // formatFast formats the node.
  1956  func (node *Load) formatFast(buf *TrackedBuffer) {
  1957  	buf.WriteString("AST node missing for Load type")
  1958  }
  1959  
  1960  // formatFast formats the node.
  1961  func (node *ShowBasic) formatFast(buf *TrackedBuffer) {
  1962  	buf.WriteString("show")
  1963  	if node.Full {
  1964  		buf.WriteString(" full")
  1965  	}
  1966  	buf.WriteString(node.Command.ToString())
  1967  	if !node.Tbl.IsEmpty() {
  1968  		buf.WriteString(" from ")
  1969  		node.Tbl.formatFast(buf)
  1970  	}
  1971  	if !node.DbName.IsEmpty() {
  1972  		buf.WriteString(" from ")
  1973  		node.DbName.formatFast(buf)
  1974  	}
  1975  	node.Filter.formatFast(buf)
  1976  }
  1977  
  1978  // formatFast formats the node.
  1979  func (node *ShowCreate) formatFast(buf *TrackedBuffer) {
  1980  	buf.WriteString("show")
  1981  	buf.WriteString(node.Command.ToString())
  1982  	buf.WriteByte(' ')
  1983  	node.Op.formatFast(buf)
  1984  }
  1985  
  1986  // formatFast formats the node.
  1987  func (node *SelectInto) formatFast(buf *TrackedBuffer) {
  1988  	if node == nil {
  1989  		return
  1990  	}
  1991  	buf.WriteString(node.Type.ToString())
  1992  	buf.WriteString(node.FileName)
  1993  	if node.Charset != "" {
  1994  		buf.WriteString(" character set ")
  1995  		buf.WriteString(node.Charset)
  1996  	}
  1997  	buf.WriteString(node.FormatOption)
  1998  	buf.WriteString(node.ExportOption)
  1999  	buf.WriteString(node.Manifest)
  2000  	buf.WriteString(node.Overwrite)
  2001  }
  2002  
  2003  // formatFast formats the node.
  2004  func (node *CreateDatabase) formatFast(buf *TrackedBuffer) {
  2005  	buf.WriteString("create database ")
  2006  	node.Comments.formatFast(buf)
  2007  	if node.IfNotExists {
  2008  		buf.WriteString("if not exists ")
  2009  	}
  2010  	node.DBName.formatFast(buf)
  2011  	if node.CreateOptions != nil {
  2012  		for _, createOption := range node.CreateOptions {
  2013  			if createOption.IsDefault {
  2014  				buf.WriteString(" default")
  2015  			}
  2016  			buf.WriteString(createOption.Type.ToString())
  2017  			buf.WriteString(" " + createOption.Value)
  2018  		}
  2019  	}
  2020  }
  2021  
  2022  // formatFast formats the node.
  2023  func (node *AlterDatabase) formatFast(buf *TrackedBuffer) {
  2024  	buf.WriteString("alter database")
  2025  	if !node.DBName.IsEmpty() {
  2026  		buf.WriteByte(' ')
  2027  		node.DBName.formatFast(buf)
  2028  	}
  2029  	if node.UpdateDataDirectory {
  2030  		buf.WriteString(" upgrade data directory name")
  2031  	}
  2032  	if node.AlterOptions != nil {
  2033  		for _, createOption := range node.AlterOptions {
  2034  			if createOption.IsDefault {
  2035  				buf.WriteString(" default")
  2036  			}
  2037  			buf.WriteString(createOption.Type.ToString())
  2038  			buf.WriteString(" " + createOption.Value)
  2039  		}
  2040  	}
  2041  }
  2042  
  2043  // formatFast formats the node.
  2044  func (node *CreateTable) formatFast(buf *TrackedBuffer) {
  2045  	buf.WriteString("create ")
  2046  	node.Comments.formatFast(buf)
  2047  	if node.Temp {
  2048  		buf.WriteString("temporary ")
  2049  	}
  2050  	buf.WriteString("table ")
  2051  
  2052  	if node.IfNotExists {
  2053  		buf.WriteString("if not exists ")
  2054  	}
  2055  	node.Table.formatFast(buf)
  2056  
  2057  	if node.OptLike != nil {
  2058  		buf.WriteByte(' ')
  2059  		node.OptLike.formatFast(buf)
  2060  	}
  2061  	if node.TableSpec != nil {
  2062  		buf.WriteByte(' ')
  2063  		node.TableSpec.formatFast(buf)
  2064  	}
  2065  }
  2066  
  2067  // formatFast formats the node.
  2068  func (node *CreateView) formatFast(buf *TrackedBuffer) {
  2069  	buf.WriteString("create")
  2070  	if node.IsReplace {
  2071  		buf.WriteString(" or replace")
  2072  	}
  2073  	if node.Algorithm != "" {
  2074  		buf.WriteString(" algorithm = ")
  2075  		buf.WriteString(node.Algorithm)
  2076  	}
  2077  	if node.Definer != "" {
  2078  		buf.WriteString(" definer = ")
  2079  		buf.WriteString(node.Definer)
  2080  	}
  2081  	if node.Security != "" {
  2082  		buf.WriteString(" sql security ")
  2083  		buf.WriteString(node.Security)
  2084  	}
  2085  	buf.WriteString(" view ")
  2086  	node.ViewName.formatFast(buf)
  2087  	node.Columns.formatFast(buf)
  2088  	buf.WriteString(" as ")
  2089  	node.Select.formatFast(buf)
  2090  	if node.CheckOption != "" {
  2091  		buf.WriteString(" with ")
  2092  		buf.WriteString(node.CheckOption)
  2093  		buf.WriteString(" check option")
  2094  	}
  2095  }
  2096  
  2097  // formatFast formats the LockTables node.
  2098  func (node *LockTables) formatFast(buf *TrackedBuffer) {
  2099  	buf.WriteString("lock tables ")
  2100  	node.Tables[0].Table.formatFast(buf)
  2101  	buf.WriteByte(' ')
  2102  	buf.WriteString(node.Tables[0].Lock.ToString())
  2103  	for i := 1; i < len(node.Tables); i++ {
  2104  		buf.WriteString(", ")
  2105  		node.Tables[i].Table.formatFast(buf)
  2106  		buf.WriteByte(' ')
  2107  		buf.WriteString(node.Tables[i].Lock.ToString())
  2108  	}
  2109  }
  2110  
  2111  // formatFast formats the UnlockTables node.
  2112  func (node *UnlockTables) formatFast(buf *TrackedBuffer) {
  2113  	buf.WriteString("unlock tables")
  2114  }
  2115  
  2116  // formatFast formats the node.
  2117  func (node *AlterView) formatFast(buf *TrackedBuffer) {
  2118  	buf.WriteString("alter")
  2119  	if node.Algorithm != "" {
  2120  		buf.WriteString(" algorithm = ")
  2121  		buf.WriteString(node.Algorithm)
  2122  	}
  2123  	if node.Definer != "" {
  2124  		buf.WriteString(" definer = ")
  2125  		buf.WriteString(node.Definer)
  2126  	}
  2127  	if node.Security != "" {
  2128  		buf.WriteString(" sql security ")
  2129  		buf.WriteString(node.Security)
  2130  	}
  2131  	buf.WriteString(" view ")
  2132  	node.ViewName.formatFast(buf)
  2133  	node.Columns.formatFast(buf)
  2134  	buf.WriteString(" as ")
  2135  	node.Select.formatFast(buf)
  2136  	if node.CheckOption != "" {
  2137  		buf.WriteString(" with ")
  2138  		buf.WriteString(node.CheckOption)
  2139  		buf.WriteString(" check option")
  2140  	}
  2141  }
  2142  
  2143  // formatFast formats the node.
  2144  func (node *DropTable) formatFast(buf *TrackedBuffer) {
  2145  	temp := ""
  2146  	if node.Temp {
  2147  		temp = "temporary "
  2148  	}
  2149  	exists := ""
  2150  	if node.IfExists {
  2151  		exists = " if exists"
  2152  	}
  2153  	buf.WriteString("drop ")
  2154  	node.Comments.formatFast(buf)
  2155  	buf.WriteString(temp)
  2156  	buf.WriteString("table")
  2157  	buf.WriteString(exists)
  2158  	buf.WriteByte(' ')
  2159  	node.FromTables.formatFast(buf)
  2160  }
  2161  
  2162  // formatFast formats the node.
  2163  func (node *DropView) formatFast(buf *TrackedBuffer) {
  2164  	exists := ""
  2165  	if node.IfExists {
  2166  		exists = " if exists"
  2167  	}
  2168  	buf.WriteString("drop view")
  2169  	buf.WriteString(exists)
  2170  	buf.WriteByte(' ')
  2171  	node.FromTables.formatFast(buf)
  2172  }
  2173  
  2174  // formatFast formats the AlterTable node.
  2175  func (node *AlterTable) formatFast(buf *TrackedBuffer) {
  2176  	buf.WriteString("alter ")
  2177  	node.Comments.formatFast(buf)
  2178  	buf.WriteString("table ")
  2179  	node.Table.formatFast(buf)
  2180  	prefix := ""
  2181  	for i, option := range node.AlterOptions {
  2182  		if i != 0 {
  2183  			buf.WriteString(",")
  2184  		}
  2185  		buf.WriteByte(' ')
  2186  		option.formatFast(buf)
  2187  		if node.PartitionSpec != nil && node.PartitionSpec.Action != RemoveAction {
  2188  			prefix = ","
  2189  		}
  2190  	}
  2191  	if node.PartitionSpec != nil {
  2192  		buf.WriteString(prefix)
  2193  		buf.WriteByte(' ')
  2194  		node.PartitionSpec.formatFast(buf)
  2195  	}
  2196  }
  2197  
  2198  // formatFast formats the node.
  2199  func (node *AddConstraintDefinition) formatFast(buf *TrackedBuffer) {
  2200  	buf.WriteString("add ")
  2201  	node.ConstraintDefinition.formatFast(buf)
  2202  }
  2203  
  2204  // formatFast formats the node.
  2205  func (node *AddIndexDefinition) formatFast(buf *TrackedBuffer) {
  2206  	buf.WriteString("add ")
  2207  	node.IndexDefinition.formatFast(buf)
  2208  }
  2209  
  2210  // formatFast formats the node.
  2211  func (node *AddColumns) formatFast(buf *TrackedBuffer) {
  2212  
  2213  	if len(node.Columns) == 1 {
  2214  		buf.WriteString("add column ")
  2215  		node.Columns[0].formatFast(buf)
  2216  		if node.First {
  2217  			buf.WriteString(" first")
  2218  		}
  2219  		if node.After != nil {
  2220  			buf.WriteString(" after ")
  2221  			node.After.formatFast(buf)
  2222  		}
  2223  	} else {
  2224  		for i, col := range node.Columns {
  2225  			if i == 0 {
  2226  				buf.WriteString("add column (")
  2227  				col.formatFast(buf)
  2228  			} else {
  2229  				buf.WriteString(", ")
  2230  				col.formatFast(buf)
  2231  			}
  2232  		}
  2233  		buf.WriteString(")")
  2234  	}
  2235  }
  2236  
  2237  // formatFast formats the node.
  2238  func (node AlgorithmValue) formatFast(buf *TrackedBuffer) {
  2239  	buf.WriteString("algorithm = ")
  2240  	buf.WriteString(string(node))
  2241  }
  2242  
  2243  // formatFast formats the node
  2244  func (node *AlterColumn) formatFast(buf *TrackedBuffer) {
  2245  	if node.DropDefault {
  2246  		buf.WriteString("alter column ")
  2247  		node.Column.formatFast(buf)
  2248  		buf.WriteString(" drop default")
  2249  	} else {
  2250  		buf.WriteString("alter column ")
  2251  		node.Column.formatFast(buf)
  2252  		buf.WriteString(" set default")
  2253  		buf.WriteByte(' ')
  2254  		node.DefaultVal.formatFast(buf)
  2255  	}
  2256  }
  2257  
  2258  // formatFast formats the node
  2259  func (node *ChangeColumn) formatFast(buf *TrackedBuffer) {
  2260  	buf.WriteString("change column ")
  2261  	node.OldColumn.formatFast(buf)
  2262  	buf.WriteByte(' ')
  2263  	node.NewColDefinition.formatFast(buf)
  2264  	if node.First {
  2265  		buf.WriteString(" first")
  2266  	}
  2267  	if node.After != nil {
  2268  		buf.WriteString(" after ")
  2269  		node.After.formatFast(buf)
  2270  	}
  2271  }
  2272  
  2273  // formatFast formats the node
  2274  func (node *ModifyColumn) formatFast(buf *TrackedBuffer) {
  2275  	buf.WriteString("modify column ")
  2276  	node.NewColDefinition.formatFast(buf)
  2277  	if node.First {
  2278  		buf.WriteString(" first")
  2279  	}
  2280  	if node.After != nil {
  2281  		buf.WriteString(" after ")
  2282  		node.After.formatFast(buf)
  2283  	}
  2284  }
  2285  
  2286  // formatFast formats the node
  2287  func (node *AlterCharset) formatFast(buf *TrackedBuffer) {
  2288  	buf.WriteString("convert to character set ")
  2289  	buf.WriteString(node.CharacterSet)
  2290  	if node.Collate != "" {
  2291  		buf.WriteString(" collate ")
  2292  		buf.WriteString(node.Collate)
  2293  	}
  2294  }
  2295  
  2296  // formatFast formats the node
  2297  func (node *KeyState) formatFast(buf *TrackedBuffer) {
  2298  	if node.Enable {
  2299  		buf.WriteString("enable keys")
  2300  	} else {
  2301  		buf.WriteString("disable keys")
  2302  	}
  2303  
  2304  }
  2305  
  2306  // formatFast formats the node
  2307  func (node *TablespaceOperation) formatFast(buf *TrackedBuffer) {
  2308  	if node.Import {
  2309  		buf.WriteString("import tablespace")
  2310  	} else {
  2311  		buf.WriteString("discard tablespace")
  2312  	}
  2313  }
  2314  
  2315  // formatFast formats the node
  2316  func (node *DropColumn) formatFast(buf *TrackedBuffer) {
  2317  	buf.WriteString("drop column ")
  2318  	node.Name.formatFast(buf)
  2319  }
  2320  
  2321  // formatFast formats the node
  2322  func (node *DropKey) formatFast(buf *TrackedBuffer) {
  2323  	buf.WriteString("drop ")
  2324  	buf.WriteString(node.Type.ToString())
  2325  	if !node.Name.IsEmpty() {
  2326  		buf.WriteByte(' ')
  2327  		node.Name.formatFast(buf)
  2328  	}
  2329  }
  2330  
  2331  // formatFast formats the node
  2332  func (node *Force) formatFast(buf *TrackedBuffer) {
  2333  	buf.WriteString("force")
  2334  }
  2335  
  2336  // formatFast formats the node
  2337  func (node *LockOption) formatFast(buf *TrackedBuffer) {
  2338  	buf.WriteString("lock ")
  2339  	buf.WriteString(node.Type.ToString())
  2340  }
  2341  
  2342  // formatFast formats the node
  2343  func (node *OrderByOption) formatFast(buf *TrackedBuffer) {
  2344  	buf.WriteString("order by ")
  2345  	prefix := ""
  2346  	for _, n := range node.Cols {
  2347  		buf.WriteString(prefix)
  2348  		n.formatFast(buf)
  2349  		prefix = ", "
  2350  	}
  2351  }
  2352  
  2353  // formatFast formats the node
  2354  func (node *RenameTableName) formatFast(buf *TrackedBuffer) {
  2355  	buf.WriteString("rename ")
  2356  	node.Table.formatFast(buf)
  2357  }
  2358  
  2359  // formatFast formats the node
  2360  func (node *RenameIndex) formatFast(buf *TrackedBuffer) {
  2361  	buf.WriteString("rename index ")
  2362  	node.OldName.formatFast(buf)
  2363  	buf.WriteString(" to ")
  2364  	node.NewName.formatFast(buf)
  2365  }
  2366  
  2367  // formatFast formats the node
  2368  func (node *Validation) formatFast(buf *TrackedBuffer) {
  2369  	if node.With {
  2370  		buf.WriteString("with validation")
  2371  	} else {
  2372  		buf.WriteString("without validation")
  2373  	}
  2374  }
  2375  
  2376  // formatFast formats the node
  2377  func (node TableOptions) formatFast(buf *TrackedBuffer) {
  2378  	for i, option := range node {
  2379  		if i != 0 {
  2380  			buf.WriteString(" ")
  2381  		}
  2382  		buf.WriteString(option.Name)
  2383  		if option.String != "" {
  2384  			buf.WriteByte(' ')
  2385  			buf.WriteString(option.String)
  2386  		} else if option.Value != nil {
  2387  			buf.WriteByte(' ')
  2388  			option.Value.formatFast(buf)
  2389  		} else {
  2390  			buf.WriteString(" (")
  2391  			option.Tables.formatFast(buf)
  2392  			buf.WriteByte(')')
  2393  		}
  2394  	}
  2395  }
  2396  
  2397  // formatFast formats the node
  2398  func (node *TruncateTable) formatFast(buf *TrackedBuffer) {
  2399  	buf.WriteString("truncate table ")
  2400  	node.Table.formatFast(buf)
  2401  }
  2402  
  2403  // formatFast formats the node.
  2404  func (node *RenameTable) formatFast(buf *TrackedBuffer) {
  2405  	buf.WriteString("rename table")
  2406  	prefix := " "
  2407  	for _, pair := range node.TablePairs {
  2408  		buf.WriteString(prefix)
  2409  		pair.FromTable.formatFast(buf)
  2410  		buf.WriteString(" to ")
  2411  		pair.ToTable.formatFast(buf)
  2412  		prefix = ", "
  2413  	}
  2414  }
  2415  
  2416  // formatFast formats the node.
  2417  // If an extracted subquery is still in the AST when we print it,
  2418  // it will be formatted as if the subquery has been extracted, and instead
  2419  // show up like argument comparisons
  2420  func (node *ExtractedSubquery) formatFast(buf *TrackedBuffer) {
  2421  	node.alternative.Format(buf)
  2422  }