github.com/vedadiyan/sqlparser@v1.0.0/pkg/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  	"fmt"
    22  
    23  	"github.com/vedadiyan/sqlparser/pkg/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  	if node.Windows != nil {
    68  		buf.WriteByte(' ')
    69  		node.Windows.formatFast(buf)
    70  	}
    71  
    72  	node.OrderBy.formatFast(buf)
    73  
    74  	node.Limit.formatFast(buf)
    75  	buf.WriteString(node.Lock.ToString())
    76  	node.Into.formatFast(buf)
    77  
    78  }
    79  
    80  // formatFast formats the node.
    81  func (node *CommentOnly) formatFast(buf *TrackedBuffer) {
    82  	for _, comment := range node.Comments {
    83  		buf.WriteString(comment)
    84  	}
    85  }
    86  
    87  // formatFast formats the node.
    88  func (node *Union) formatFast(buf *TrackedBuffer) {
    89  	if requiresParen(node.Left) {
    90  		buf.WriteByte('(')
    91  		node.Left.formatFast(buf)
    92  		buf.WriteByte(')')
    93  	} else {
    94  		node.Left.formatFast(buf)
    95  	}
    96  
    97  	buf.WriteByte(' ')
    98  	if node.Distinct {
    99  		buf.WriteString(UnionStr)
   100  	} else {
   101  		buf.WriteString(UnionAllStr)
   102  	}
   103  	buf.WriteByte(' ')
   104  
   105  	if requiresParen(node.Right) {
   106  		buf.WriteByte('(')
   107  		node.Right.formatFast(buf)
   108  		buf.WriteByte(')')
   109  	} else {
   110  		node.Right.formatFast(buf)
   111  	}
   112  
   113  	node.OrderBy.formatFast(buf)
   114  	node.Limit.formatFast(buf)
   115  	buf.WriteString(node.Lock.ToString())
   116  }
   117  
   118  // formatFast formats the node.
   119  func (node *VStream) formatFast(buf *TrackedBuffer) {
   120  	buf.WriteString("vstream ")
   121  	node.Comments.formatFast(buf)
   122  	node.SelectExpr.formatFast(buf)
   123  	buf.WriteString(" from ")
   124  	node.Table.formatFast(buf)
   125  
   126  }
   127  
   128  // formatFast formats the node.
   129  func (node *Stream) formatFast(buf *TrackedBuffer) {
   130  	buf.WriteString("stream ")
   131  	node.Comments.formatFast(buf)
   132  	node.SelectExpr.formatFast(buf)
   133  	buf.WriteString(" from ")
   134  	node.Table.formatFast(buf)
   135  
   136  }
   137  
   138  // formatFast formats the node.
   139  func (node *Insert) formatFast(buf *TrackedBuffer) {
   140  	switch node.Action {
   141  	case InsertAct:
   142  		buf.WriteString(InsertStr)
   143  		buf.WriteByte(' ')
   144  
   145  		node.Comments.formatFast(buf)
   146  		buf.WriteString(node.Ignore.ToString())
   147  		buf.WriteString("into ")
   148  
   149  		node.Table.formatFast(buf)
   150  
   151  		node.Partitions.formatFast(buf)
   152  
   153  		node.Columns.formatFast(buf)
   154  		buf.WriteByte(' ')
   155  
   156  		node.Rows.formatFast(buf)
   157  
   158  		node.OnDup.formatFast(buf)
   159  
   160  	case ReplaceAct:
   161  		buf.WriteString(ReplaceStr)
   162  		buf.WriteByte(' ')
   163  
   164  		node.Comments.formatFast(buf)
   165  		buf.WriteString(node.Ignore.ToString())
   166  		buf.WriteString("into ")
   167  
   168  		node.Table.formatFast(buf)
   169  
   170  		node.Partitions.formatFast(buf)
   171  
   172  		node.Columns.formatFast(buf)
   173  		buf.WriteByte(' ')
   174  
   175  		node.Rows.formatFast(buf)
   176  
   177  		node.OnDup.formatFast(buf)
   178  
   179  	default:
   180  		buf.WriteString("Unkown Insert Action")
   181  		buf.WriteByte(' ')
   182  
   183  		node.Comments.formatFast(buf)
   184  		buf.WriteString(node.Ignore.ToString())
   185  		buf.WriteString("into ")
   186  
   187  		node.Table.formatFast(buf)
   188  
   189  		node.Partitions.formatFast(buf)
   190  
   191  		node.Columns.formatFast(buf)
   192  		buf.WriteByte(' ')
   193  
   194  		node.Rows.formatFast(buf)
   195  
   196  		node.OnDup.formatFast(buf)
   197  
   198  	}
   199  
   200  }
   201  
   202  // formatFast formats the node.
   203  func (node *With) formatFast(buf *TrackedBuffer) {
   204  	buf.WriteString("with ")
   205  
   206  	if node.Recursive {
   207  		buf.WriteString("recursive ")
   208  	}
   209  	ctesLength := len(node.Ctes)
   210  	for i := 0; i < ctesLength-1; i++ {
   211  		node.Ctes[i].formatFast(buf)
   212  		buf.WriteString(", ")
   213  	}
   214  	node.Ctes[ctesLength-1].formatFast(buf)
   215  }
   216  
   217  // formatFast formats the node.
   218  func (node *CommonTableExpr) formatFast(buf *TrackedBuffer) {
   219  	node.ID.formatFast(buf)
   220  	node.Columns.formatFast(buf)
   221  	buf.WriteString(" as ")
   222  	node.Subquery.formatFast(buf)
   223  	buf.WriteByte(' ')
   224  }
   225  
   226  // formatFast formats the node.
   227  func (node *Update) formatFast(buf *TrackedBuffer) {
   228  	if node.With != nil {
   229  		node.With.formatFast(buf)
   230  	}
   231  	buf.WriteString("update ")
   232  	node.Comments.formatFast(buf)
   233  	buf.WriteString(node.Ignore.ToString())
   234  	node.TableExprs.formatFast(buf)
   235  	buf.WriteString(" set ")
   236  
   237  	node.Exprs.formatFast(buf)
   238  
   239  	node.Where.formatFast(buf)
   240  
   241  	node.OrderBy.formatFast(buf)
   242  
   243  	node.Limit.formatFast(buf)
   244  
   245  }
   246  
   247  // formatFast formats the node.
   248  func (node *Delete) formatFast(buf *TrackedBuffer) {
   249  	if node.With != nil {
   250  		node.With.formatFast(buf)
   251  	}
   252  	buf.WriteString("delete ")
   253  	node.Comments.formatFast(buf)
   254  	if node.Ignore {
   255  		buf.WriteString("ignore ")
   256  	}
   257  	if node.Targets != nil {
   258  		node.Targets.formatFast(buf)
   259  		buf.WriteByte(' ')
   260  	}
   261  	buf.WriteString("from ")
   262  	node.TableExprs.formatFast(buf)
   263  	node.Partitions.formatFast(buf)
   264  	node.Where.formatFast(buf)
   265  	node.OrderBy.formatFast(buf)
   266  	node.Limit.formatFast(buf)
   267  }
   268  
   269  // formatFast formats the node.
   270  func (node *Set) formatFast(buf *TrackedBuffer) {
   271  	buf.WriteString("set ")
   272  	node.Comments.formatFast(buf)
   273  	node.Exprs.formatFast(buf)
   274  }
   275  
   276  // formatFast formats the node.
   277  func (node *DropDatabase) formatFast(buf *TrackedBuffer) {
   278  	exists := ""
   279  	if node.IfExists {
   280  		exists = "if exists "
   281  	}
   282  	buf.WriteString(DropStr)
   283  	buf.WriteByte(' ')
   284  	node.Comments.formatFast(buf)
   285  	buf.WriteString("database ")
   286  	buf.WriteString(exists)
   287  	node.DBName.formatFast(buf)
   288  }
   289  
   290  // formatFast formats the node.
   291  func (node *Flush) formatFast(buf *TrackedBuffer) {
   292  	buf.WriteString(FlushStr)
   293  	if node.IsLocal {
   294  		buf.WriteString(" local")
   295  	}
   296  	if len(node.FlushOptions) != 0 {
   297  		prefix := " "
   298  		for _, option := range node.FlushOptions {
   299  			buf.WriteString(prefix)
   300  			buf.WriteString(option)
   301  			prefix = ", "
   302  		}
   303  	} else {
   304  		buf.WriteString(" tables")
   305  		if len(node.TableNames) != 0 {
   306  			buf.WriteByte(' ')
   307  			node.TableNames.formatFast(buf)
   308  		}
   309  		if node.ForExport {
   310  			buf.WriteString(" for export")
   311  		}
   312  		if node.WithLock {
   313  			buf.WriteString(" with read lock")
   314  		}
   315  	}
   316  }
   317  
   318  // formatFast formats the node.
   319  func (node *AlterVschema) formatFast(buf *TrackedBuffer) {
   320  	switch node.Action {
   321  	case CreateVindexDDLAction:
   322  		buf.WriteString("alter vschema create vindex ")
   323  		node.Table.formatFast(buf)
   324  		buf.WriteByte(' ')
   325  		node.VindexSpec.formatFast(buf)
   326  	case DropVindexDDLAction:
   327  		buf.WriteString("alter vschema drop vindex ")
   328  		node.Table.formatFast(buf)
   329  	case AddVschemaTableDDLAction:
   330  		buf.WriteString("alter vschema add table ")
   331  		node.Table.formatFast(buf)
   332  	case DropVschemaTableDDLAction:
   333  		buf.WriteString("alter vschema drop table ")
   334  		node.Table.formatFast(buf)
   335  	case AddColVindexDDLAction:
   336  		buf.WriteString("alter vschema on ")
   337  		node.Table.formatFast(buf)
   338  		buf.WriteString(" add vindex ")
   339  		node.VindexSpec.Name.formatFast(buf)
   340  		buf.WriteString(" (")
   341  		for i, col := range node.VindexCols {
   342  			if i != 0 {
   343  				buf.WriteString(", ")
   344  				col.formatFast(buf)
   345  			} else {
   346  				col.formatFast(buf)
   347  			}
   348  		}
   349  		buf.WriteByte(')')
   350  		if node.VindexSpec.Type.String() != "" {
   351  			buf.WriteByte(' ')
   352  			node.VindexSpec.formatFast(buf)
   353  		}
   354  	case DropColVindexDDLAction:
   355  		buf.WriteString("alter vschema on ")
   356  		node.Table.formatFast(buf)
   357  		buf.WriteString(" drop vindex ")
   358  		node.VindexSpec.Name.formatFast(buf)
   359  	case AddSequenceDDLAction:
   360  		buf.WriteString("alter vschema add sequence ")
   361  		node.Table.formatFast(buf)
   362  	case AddAutoIncDDLAction:
   363  		buf.WriteString("alter vschema on ")
   364  		node.Table.formatFast(buf)
   365  		buf.WriteString(" add auto_increment ")
   366  		node.AutoIncSpec.formatFast(buf)
   367  	default:
   368  		buf.WriteString(node.Action.ToString())
   369  		buf.WriteString(" table ")
   370  		node.Table.formatFast(buf)
   371  	}
   372  }
   373  
   374  // formatFast formats the node.
   375  func (node *AlterMigration) formatFast(buf *TrackedBuffer) {
   376  	buf.WriteString("alter vitess_migration")
   377  	if node.UUID != "" {
   378  		buf.WriteString(" '")
   379  		buf.WriteString(node.UUID)
   380  		buf.WriteByte('\'')
   381  	}
   382  	var alterType string
   383  	switch node.Type {
   384  	case RetryMigrationType:
   385  		alterType = "retry"
   386  	case CleanupMigrationType:
   387  		alterType = "cleanup"
   388  	case LaunchMigrationType:
   389  		alterType = "launch"
   390  	case LaunchAllMigrationType:
   391  		alterType = "launch all"
   392  	case CompleteMigrationType:
   393  		alterType = "complete"
   394  	case CompleteAllMigrationType:
   395  		alterType = "complete all"
   396  	case CancelMigrationType:
   397  		alterType = "cancel"
   398  	case CancelAllMigrationType:
   399  		alterType = "cancel all"
   400  	case ThrottleMigrationType:
   401  		alterType = "throttle"
   402  	case ThrottleAllMigrationType:
   403  		alterType = "throttle all"
   404  	case UnthrottleMigrationType:
   405  		alterType = "unthrottle"
   406  	case UnthrottleAllMigrationType:
   407  		alterType = "unthrottle all"
   408  	}
   409  	buf.WriteByte(' ')
   410  	buf.WriteString(alterType)
   411  	if node.Expire != "" {
   412  		buf.WriteString(" expire '")
   413  		buf.WriteString(node.Expire)
   414  		buf.WriteByte('\'')
   415  	}
   416  	if node.Ratio != nil {
   417  		buf.WriteString(" ratio ")
   418  		node.Ratio.formatFast(buf)
   419  	}
   420  	if node.Shards != "" {
   421  		buf.WriteString(" vitess_shards '")
   422  		buf.WriteString(node.Shards)
   423  		buf.WriteByte('\'')
   424  	}
   425  }
   426  
   427  // formatFast formats the node.
   428  func (node *RevertMigration) formatFast(buf *TrackedBuffer) {
   429  	buf.WriteString("revert ")
   430  	node.Comments.formatFast(buf)
   431  	buf.WriteString("vitess_migration '")
   432  	buf.WriteString(node.UUID)
   433  	buf.WriteByte('\'')
   434  }
   435  
   436  // formatFast formats the node.
   437  func (node *ShowMigrationLogs) formatFast(buf *TrackedBuffer) {
   438  	buf.WriteString("show vitess_migration '")
   439  	buf.WriteString(node.UUID)
   440  	buf.WriteString("' logs")
   441  }
   442  
   443  // formatFast formats the node.
   444  func (node *ShowThrottledApps) formatFast(buf *TrackedBuffer) {
   445  	buf.WriteString("show vitess_throttled_apps")
   446  }
   447  
   448  // formatFast formats the node.
   449  func (node *ShowThrottlerStatus) formatFast(buf *TrackedBuffer) {
   450  	buf.WriteString("show vitess_throttler status")
   451  }
   452  
   453  // formatFast formats the node.
   454  func (node *OptLike) formatFast(buf *TrackedBuffer) {
   455  	buf.WriteString("like ")
   456  	node.LikeTable.formatFast(buf)
   457  }
   458  
   459  // formatFast formats the node.
   460  func (node *PartitionSpec) formatFast(buf *TrackedBuffer) {
   461  	switch node.Action {
   462  	case ReorganizeAction:
   463  		buf.WriteString(ReorganizeStr)
   464  		buf.WriteByte(' ')
   465  		for i, n := range node.Names {
   466  			if i != 0 {
   467  				buf.WriteString(", ")
   468  			}
   469  			n.formatFast(buf)
   470  		}
   471  		buf.WriteString(" into (")
   472  		for i, pd := range node.Definitions {
   473  			if i != 0 {
   474  				buf.WriteString(", ")
   475  			}
   476  			pd.formatFast(buf)
   477  		}
   478  		buf.WriteByte(')')
   479  	case AddAction:
   480  		buf.WriteString(AddStr)
   481  		buf.WriteString(" (")
   482  		node.Definitions[0].formatFast(buf)
   483  		buf.WriteByte(')')
   484  	case DropAction:
   485  		buf.WriteString(DropPartitionStr)
   486  		buf.WriteByte(' ')
   487  		for i, n := range node.Names {
   488  			if i != 0 {
   489  				buf.WriteString(", ")
   490  			}
   491  			n.formatFast(buf)
   492  		}
   493  	case DiscardAction:
   494  		buf.WriteString(DiscardStr)
   495  		buf.WriteByte(' ')
   496  		if node.IsAll {
   497  			buf.WriteString("all")
   498  		} else {
   499  			prefix := ""
   500  			for _, n := range node.Names {
   501  				buf.WriteString(prefix)
   502  				n.formatFast(buf)
   503  				prefix = ", "
   504  			}
   505  		}
   506  		buf.WriteString(" tablespace")
   507  	case ImportAction:
   508  		buf.WriteString(ImportStr)
   509  		buf.WriteByte(' ')
   510  		if node.IsAll {
   511  			buf.WriteString("all")
   512  		} else {
   513  			prefix := ""
   514  			for _, n := range node.Names {
   515  				buf.WriteString(prefix)
   516  				n.formatFast(buf)
   517  				prefix = ", "
   518  			}
   519  		}
   520  		buf.WriteString(" tablespace")
   521  	case TruncateAction:
   522  		buf.WriteString(TruncatePartitionStr)
   523  		buf.WriteByte(' ')
   524  		if node.IsAll {
   525  			buf.WriteString("all")
   526  		} else {
   527  			prefix := ""
   528  			for _, n := range node.Names {
   529  				buf.WriteString(prefix)
   530  				n.formatFast(buf)
   531  				prefix = ", "
   532  			}
   533  		}
   534  	case CoalesceAction:
   535  		buf.WriteString(CoalesceStr)
   536  		buf.WriteByte(' ')
   537  		node.Number.formatFast(buf)
   538  	case ExchangeAction:
   539  		buf.WriteString(ExchangeStr)
   540  		buf.WriteByte(' ')
   541  		node.Names[0].formatFast(buf)
   542  		buf.WriteString(" with table ")
   543  		node.TableName.formatFast(buf)
   544  		if node.WithoutValidation {
   545  			buf.WriteString(" without validation")
   546  		}
   547  	case AnalyzeAction:
   548  		buf.WriteString(AnalyzePartitionStr)
   549  		buf.WriteByte(' ')
   550  		if node.IsAll {
   551  			buf.WriteString("all")
   552  		} else {
   553  			prefix := ""
   554  			for _, n := range node.Names {
   555  				buf.WriteString(prefix)
   556  				n.formatFast(buf)
   557  				prefix = ", "
   558  			}
   559  		}
   560  	case CheckAction:
   561  		buf.WriteString(CheckStr)
   562  		buf.WriteByte(' ')
   563  		if node.IsAll {
   564  			buf.WriteString("all")
   565  		} else {
   566  			prefix := ""
   567  			for _, n := range node.Names {
   568  				buf.WriteString(prefix)
   569  				n.formatFast(buf)
   570  				prefix = ", "
   571  			}
   572  		}
   573  	case OptimizeAction:
   574  		buf.WriteString(OptimizeStr)
   575  		buf.WriteByte(' ')
   576  		if node.IsAll {
   577  			buf.WriteString("all")
   578  		} else {
   579  			prefix := ""
   580  			for _, n := range node.Names {
   581  				buf.WriteString(prefix)
   582  				n.formatFast(buf)
   583  				prefix = ", "
   584  			}
   585  		}
   586  	case RebuildAction:
   587  		buf.WriteString(RebuildStr)
   588  		buf.WriteByte(' ')
   589  		if node.IsAll {
   590  			buf.WriteString("all")
   591  		} else {
   592  			prefix := ""
   593  			for _, n := range node.Names {
   594  				buf.WriteString(prefix)
   595  				n.formatFast(buf)
   596  				prefix = ", "
   597  			}
   598  		}
   599  	case RepairAction:
   600  		buf.WriteString(RepairStr)
   601  		buf.WriteByte(' ')
   602  		if node.IsAll {
   603  			buf.WriteString("all")
   604  		} else {
   605  			prefix := ""
   606  			for _, n := range node.Names {
   607  				buf.WriteString(prefix)
   608  				n.formatFast(buf)
   609  				prefix = ", "
   610  			}
   611  		}
   612  	case RemoveAction:
   613  		buf.WriteString(RemoveStr)
   614  	case UpgradeAction:
   615  		buf.WriteString(UpgradeStr)
   616  	default:
   617  		panic("unimplemented")
   618  	}
   619  }
   620  
   621  // formatFast formats the node
   622  func (node *PartitionDefinition) formatFast(buf *TrackedBuffer) {
   623  	buf.WriteString("partition ")
   624  	node.Name.formatFast(buf)
   625  	node.Options.formatFast(buf)
   626  }
   627  
   628  // formatFast formats the node
   629  func (node *PartitionDefinitionOptions) formatFast(buf *TrackedBuffer) {
   630  	if node.ValueRange != nil {
   631  		buf.WriteByte(' ')
   632  		node.ValueRange.formatFast(buf)
   633  	}
   634  	if node.Engine != nil {
   635  		buf.WriteByte(' ')
   636  		node.Engine.formatFast(buf)
   637  	}
   638  	if node.Comment != nil {
   639  		buf.WriteString(" comment ")
   640  		node.Comment.formatFast(buf)
   641  	}
   642  	if node.DataDirectory != nil {
   643  		buf.WriteString(" data directory ")
   644  		node.DataDirectory.formatFast(buf)
   645  	}
   646  	if node.IndexDirectory != nil {
   647  		buf.WriteString(" index directory ")
   648  		node.IndexDirectory.formatFast(buf)
   649  	}
   650  	if node.MaxRows != nil {
   651  		buf.WriteString(" max_rows ")
   652  		buf.WriteString(fmt.Sprintf("%d", *node.MaxRows))
   653  	}
   654  	if node.MinRows != nil {
   655  		buf.WriteString(" min_rows ")
   656  		buf.WriteString(fmt.Sprintf("%d", *node.MinRows))
   657  	}
   658  	if node.TableSpace != "" {
   659  		buf.WriteString(" tablespace ")
   660  		buf.WriteString(node.TableSpace)
   661  	}
   662  	if node.SubPartitionDefinitions != nil {
   663  		buf.WriteString(" (")
   664  		node.SubPartitionDefinitions.formatFast(buf)
   665  		buf.WriteByte(')')
   666  	}
   667  }
   668  
   669  // formatFast formats the node
   670  func (node SubPartitionDefinitions) formatFast(buf *TrackedBuffer) {
   671  	var prefix string
   672  	for _, n := range node {
   673  		buf.WriteString(prefix)
   674  		n.formatFast(buf)
   675  		prefix = ", "
   676  	}
   677  }
   678  
   679  // formatFast formats the node
   680  func (node *SubPartitionDefinition) formatFast(buf *TrackedBuffer) {
   681  	buf.WriteString("subpartition ")
   682  	node.Name.formatFast(buf)
   683  	node.Options.formatFast(buf)
   684  }
   685  
   686  // formatFast formats the node
   687  func (node *SubPartitionDefinitionOptions) formatFast(buf *TrackedBuffer) {
   688  	if node.Engine != nil {
   689  		buf.WriteByte(' ')
   690  		node.Engine.formatFast(buf)
   691  	}
   692  	if node.Comment != nil {
   693  		buf.WriteString(" comment ")
   694  		node.Comment.formatFast(buf)
   695  	}
   696  	if node.DataDirectory != nil {
   697  		buf.WriteString(" data directory ")
   698  		node.DataDirectory.formatFast(buf)
   699  	}
   700  	if node.IndexDirectory != nil {
   701  		buf.WriteString(" index directory ")
   702  		node.IndexDirectory.formatFast(buf)
   703  	}
   704  	if node.MaxRows != nil {
   705  		buf.WriteString(" max_rows ")
   706  		buf.WriteString(fmt.Sprintf("%d", *node.MaxRows))
   707  	}
   708  	if node.MinRows != nil {
   709  		buf.WriteString(" min_rows ")
   710  		buf.WriteString(fmt.Sprintf("%d", *node.MinRows))
   711  	}
   712  	if node.TableSpace != "" {
   713  		buf.WriteString(" tablespace ")
   714  		buf.WriteString(node.TableSpace)
   715  	}
   716  }
   717  
   718  // formatFast formats the node
   719  func (node *PartitionValueRange) formatFast(buf *TrackedBuffer) {
   720  	buf.WriteString("values ")
   721  	buf.WriteString(node.Type.ToString())
   722  	if node.Maxvalue {
   723  		buf.WriteString(" maxvalue")
   724  	} else {
   725  		buf.WriteByte(' ')
   726  		node.Range.formatFast(buf)
   727  	}
   728  }
   729  
   730  // formatFast formats the node
   731  func (node *PartitionEngine) formatFast(buf *TrackedBuffer) {
   732  	if node.Storage {
   733  		buf.WriteString("storage ")
   734  	}
   735  	buf.WriteString("engine ")
   736  	buf.WriteString(node.Name)
   737  }
   738  
   739  // formatFast formats the node.
   740  func (node *PartitionOption) formatFast(buf *TrackedBuffer) {
   741  	buf.WriteString("\npartition by")
   742  	if node.IsLinear {
   743  		buf.WriteString(" linear")
   744  	}
   745  
   746  	switch node.Type {
   747  	case HashType:
   748  		buf.WriteString(" hash (")
   749  		node.Expr.formatFast(buf)
   750  		buf.WriteByte(')')
   751  	case KeyType:
   752  		buf.WriteString(" key")
   753  		if node.KeyAlgorithm != 0 {
   754  			buf.WriteString(" algorithm = ")
   755  			buf.WriteString(fmt.Sprintf("%d", node.KeyAlgorithm))
   756  		}
   757  		if len(node.ColList) == 0 {
   758  			buf.WriteString(" ()")
   759  		} else {
   760  			buf.WriteByte(' ')
   761  			node.ColList.formatFast(buf)
   762  		}
   763  	case RangeType, ListType:
   764  		buf.WriteByte(' ')
   765  		buf.WriteString(node.Type.ToString())
   766  		if node.Expr != nil {
   767  			buf.WriteString(" (")
   768  			node.Expr.formatFast(buf)
   769  			buf.WriteByte(')')
   770  		} else {
   771  			buf.WriteString(" columns ")
   772  			node.ColList.formatFast(buf)
   773  		}
   774  	}
   775  
   776  	if node.Partitions != -1 {
   777  		buf.WriteString(" partitions ")
   778  		buf.WriteString(fmt.Sprintf("%d", node.Partitions))
   779  	}
   780  	if node.SubPartition != nil {
   781  		buf.WriteByte(' ')
   782  		node.SubPartition.formatFast(buf)
   783  	}
   784  	if node.Definitions != nil {
   785  		buf.WriteString("\n(")
   786  		for i, pd := range node.Definitions {
   787  			if i != 0 {
   788  				buf.WriteString(",\n ")
   789  			}
   790  			pd.formatFast(buf)
   791  		}
   792  		buf.WriteByte(')')
   793  	}
   794  }
   795  
   796  // formatFast formats the node.
   797  func (node *SubPartition) formatFast(buf *TrackedBuffer) {
   798  	buf.WriteString("subpartition by")
   799  	if node.IsLinear {
   800  		buf.WriteString(" linear")
   801  	}
   802  
   803  	switch node.Type {
   804  	case HashType:
   805  		buf.WriteString(" hash (")
   806  		node.Expr.formatFast(buf)
   807  		buf.WriteByte(')')
   808  	case KeyType:
   809  		buf.WriteString(" key")
   810  		if node.KeyAlgorithm != 0 {
   811  			buf.WriteString(" algorithm = ")
   812  			buf.WriteString(fmt.Sprintf("%d", node.KeyAlgorithm))
   813  		}
   814  		if len(node.ColList) == 0 {
   815  			buf.WriteString(" ()")
   816  		} else {
   817  			buf.WriteByte(' ')
   818  			node.ColList.formatFast(buf)
   819  		}
   820  	}
   821  
   822  	if node.SubPartitions != -1 {
   823  		buf.WriteString(" subpartitions ")
   824  		buf.WriteString(fmt.Sprintf("%d", node.SubPartitions))
   825  	}
   826  }
   827  
   828  // formatFast formats the node.
   829  func (ts *TableSpec) formatFast(buf *TrackedBuffer) {
   830  	buf.WriteString("(\n")
   831  	for i, col := range ts.Columns {
   832  		if i == 0 {
   833  			buf.WriteByte('\t')
   834  			col.formatFast(buf)
   835  		} else {
   836  			buf.WriteString(",\n\t")
   837  			col.formatFast(buf)
   838  		}
   839  	}
   840  	for _, idx := range ts.Indexes {
   841  		buf.WriteString(",\n\t")
   842  		idx.formatFast(buf)
   843  	}
   844  	for _, c := range ts.Constraints {
   845  		buf.WriteString(",\n\t")
   846  		c.formatFast(buf)
   847  	}
   848  
   849  	buf.WriteString("\n)")
   850  	for i, opt := range ts.Options {
   851  		if i != 0 {
   852  			buf.WriteString(",\n ")
   853  		}
   854  		buf.WriteByte(' ')
   855  		buf.WriteString(opt.Name)
   856  		if opt.String != "" {
   857  			if opt.CaseSensitive {
   858  				buf.WriteByte(' ')
   859  				buf.WriteString(opt.String)
   860  			} else {
   861  				buf.WriteByte(' ')
   862  				buf.WriteString(opt.String)
   863  			}
   864  		} else if opt.Value != nil {
   865  			buf.WriteByte(' ')
   866  			opt.Value.formatFast(buf)
   867  		} else {
   868  			buf.WriteString(" (")
   869  			opt.Tables.formatFast(buf)
   870  			buf.WriteByte(')')
   871  		}
   872  	}
   873  	if ts.PartitionOption != nil {
   874  		ts.PartitionOption.formatFast(buf)
   875  	}
   876  }
   877  
   878  // formatFast formats the node.
   879  func (col *ColumnDefinition) formatFast(buf *TrackedBuffer) {
   880  	col.Name.formatFast(buf)
   881  	buf.WriteByte(' ')
   882  	col.Type.formatFast(buf)
   883  }
   884  
   885  // formatFast returns a canonical string representation of the type and all relevant options
   886  func (ct *ColumnType) formatFast(buf *TrackedBuffer) {
   887  	buf.WriteString(ct.Type)
   888  
   889  	if ct.Length != nil && ct.Scale != nil {
   890  		buf.WriteByte('(')
   891  		ct.Length.formatFast(buf)
   892  		buf.WriteByte(',')
   893  		ct.Scale.formatFast(buf)
   894  		buf.WriteByte(')')
   895  
   896  	} else if ct.Length != nil {
   897  		buf.WriteByte('(')
   898  		ct.Length.formatFast(buf)
   899  		buf.WriteByte(')')
   900  	}
   901  
   902  	if ct.EnumValues != nil {
   903  		buf.WriteString("(")
   904  		for i, enum := range ct.EnumValues {
   905  			if i > 0 {
   906  				buf.WriteString(", ")
   907  			}
   908  			buf.WriteString(enum)
   909  		}
   910  		buf.WriteString(")")
   911  	}
   912  
   913  	if ct.Unsigned {
   914  		buf.WriteByte(' ')
   915  		buf.WriteString(keywordStrings[UNSIGNED])
   916  	}
   917  	if ct.Zerofill {
   918  		buf.WriteByte(' ')
   919  		buf.WriteString(keywordStrings[ZEROFILL])
   920  	}
   921  	if ct.Charset.Name != "" {
   922  		buf.WriteByte(' ')
   923  		buf.WriteString(keywordStrings[CHARACTER])
   924  		buf.WriteByte(' ')
   925  		buf.WriteString(keywordStrings[SET])
   926  		buf.WriteByte(' ')
   927  		buf.WriteString(ct.Charset.Name)
   928  	}
   929  	if ct.Charset.Binary {
   930  		buf.WriteByte(' ')
   931  		buf.WriteString(keywordStrings[BINARY])
   932  	}
   933  	if ct.Options != nil {
   934  		if ct.Options.Collate != "" {
   935  			buf.WriteByte(' ')
   936  			buf.WriteString(keywordStrings[COLLATE])
   937  			buf.WriteByte(' ')
   938  			buf.WriteString(ct.Options.Collate)
   939  		}
   940  		if ct.Options.Null != nil && ct.Options.As == nil {
   941  			if *ct.Options.Null {
   942  				buf.WriteByte(' ')
   943  				buf.WriteString(keywordStrings[NULL])
   944  			} else {
   945  				buf.WriteByte(' ')
   946  				buf.WriteString(keywordStrings[NOT])
   947  				buf.WriteByte(' ')
   948  				buf.WriteString(keywordStrings[NULL])
   949  			}
   950  		}
   951  		if ct.Options.Default != nil {
   952  			buf.WriteByte(' ')
   953  			buf.WriteString(keywordStrings[DEFAULT])
   954  			if defaultRequiresParens(ct) {
   955  				buf.WriteString(" (")
   956  				ct.Options.Default.formatFast(buf)
   957  				buf.WriteByte(')')
   958  			} else {
   959  				buf.WriteByte(' ')
   960  				ct.Options.Default.formatFast(buf)
   961  			}
   962  		}
   963  		if ct.Options.OnUpdate != nil {
   964  			buf.WriteByte(' ')
   965  			buf.WriteString(keywordStrings[ON])
   966  			buf.WriteByte(' ')
   967  			buf.WriteString(keywordStrings[UPDATE])
   968  			buf.WriteByte(' ')
   969  			ct.Options.OnUpdate.formatFast(buf)
   970  		}
   971  		if ct.Options.As != nil {
   972  			buf.WriteByte(' ')
   973  			buf.WriteString(keywordStrings[AS])
   974  			buf.WriteString(" (")
   975  			ct.Options.As.formatFast(buf)
   976  			buf.WriteByte(')')
   977  
   978  			if ct.Options.Storage == VirtualStorage {
   979  				buf.WriteByte(' ')
   980  				buf.WriteString(keywordStrings[VIRTUAL])
   981  			} else if ct.Options.Storage == StoredStorage {
   982  				buf.WriteByte(' ')
   983  				buf.WriteString(keywordStrings[STORED])
   984  			}
   985  			if ct.Options.Null != nil {
   986  				if *ct.Options.Null {
   987  					buf.WriteByte(' ')
   988  					buf.WriteString(keywordStrings[NULL])
   989  				} else {
   990  					buf.WriteByte(' ')
   991  					buf.WriteString(keywordStrings[NOT])
   992  					buf.WriteByte(' ')
   993  					buf.WriteString(keywordStrings[NULL])
   994  				}
   995  			}
   996  		}
   997  		if ct.Options.Autoincrement {
   998  			buf.WriteByte(' ')
   999  			buf.WriteString(keywordStrings[AUTO_INCREMENT])
  1000  		}
  1001  		if ct.Options.Comment != nil {
  1002  			buf.WriteByte(' ')
  1003  			buf.WriteString(keywordStrings[COMMENT_KEYWORD])
  1004  			buf.WriteByte(' ')
  1005  			ct.Options.Comment.formatFast(buf)
  1006  		}
  1007  		if ct.Options.Invisible != nil {
  1008  			if *ct.Options.Invisible {
  1009  				buf.WriteByte(' ')
  1010  				buf.WriteString(keywordStrings[INVISIBLE])
  1011  			} else {
  1012  				buf.WriteByte(' ')
  1013  				buf.WriteString(keywordStrings[VISIBLE])
  1014  			}
  1015  		}
  1016  		if ct.Options.Format != UnspecifiedFormat {
  1017  			buf.WriteByte(' ')
  1018  			buf.WriteString(keywordStrings[COLUMN_FORMAT])
  1019  			buf.WriteByte(' ')
  1020  			buf.WriteString(ct.Options.Format.ToString())
  1021  		}
  1022  		if ct.Options.EngineAttribute != nil {
  1023  			buf.WriteByte(' ')
  1024  			buf.WriteString(keywordStrings[ENGINE_ATTRIBUTE])
  1025  			buf.WriteByte(' ')
  1026  			ct.Options.EngineAttribute.formatFast(buf)
  1027  		}
  1028  		if ct.Options.SecondaryEngineAttribute != nil {
  1029  			buf.WriteByte(' ')
  1030  			buf.WriteString(keywordStrings[SECONDARY_ENGINE_ATTRIBUTE])
  1031  			buf.WriteByte(' ')
  1032  			ct.Options.SecondaryEngineAttribute.formatFast(buf)
  1033  		}
  1034  		if ct.Options.KeyOpt == ColKeyPrimary {
  1035  			buf.WriteByte(' ')
  1036  			buf.WriteString(keywordStrings[PRIMARY])
  1037  			buf.WriteByte(' ')
  1038  			buf.WriteString(keywordStrings[KEY])
  1039  		}
  1040  		if ct.Options.KeyOpt == ColKeyUnique {
  1041  			buf.WriteByte(' ')
  1042  			buf.WriteString(keywordStrings[UNIQUE])
  1043  		}
  1044  		if ct.Options.KeyOpt == ColKeyUniqueKey {
  1045  			buf.WriteByte(' ')
  1046  			buf.WriteString(keywordStrings[UNIQUE])
  1047  			buf.WriteByte(' ')
  1048  			buf.WriteString(keywordStrings[KEY])
  1049  		}
  1050  		if ct.Options.KeyOpt == ColKeySpatialKey {
  1051  			buf.WriteByte(' ')
  1052  			buf.WriteString(keywordStrings[SPATIAL])
  1053  			buf.WriteByte(' ')
  1054  			buf.WriteString(keywordStrings[KEY])
  1055  		}
  1056  		if ct.Options.KeyOpt == ColKeyFulltextKey {
  1057  			buf.WriteByte(' ')
  1058  			buf.WriteString(keywordStrings[FULLTEXT])
  1059  			buf.WriteByte(' ')
  1060  			buf.WriteString(keywordStrings[KEY])
  1061  		}
  1062  		if ct.Options.KeyOpt == ColKey {
  1063  			buf.WriteByte(' ')
  1064  			buf.WriteString(keywordStrings[KEY])
  1065  		}
  1066  		if ct.Options.Reference != nil {
  1067  			buf.WriteByte(' ')
  1068  			ct.Options.Reference.formatFast(buf)
  1069  		}
  1070  		if ct.Options.SRID != nil {
  1071  			buf.WriteByte(' ')
  1072  			buf.WriteString(keywordStrings[SRID])
  1073  			buf.WriteByte(' ')
  1074  			ct.Options.SRID.formatFast(buf)
  1075  		}
  1076  	}
  1077  }
  1078  
  1079  // formatFast formats the node.
  1080  func (idx *IndexDefinition) formatFast(buf *TrackedBuffer) {
  1081  	idx.Info.formatFast(buf)
  1082  	buf.WriteString(" (")
  1083  	for i, col := range idx.Columns {
  1084  		if i != 0 {
  1085  			buf.WriteString(", ")
  1086  		}
  1087  		if col.Expression != nil {
  1088  			buf.WriteByte('(')
  1089  			col.Expression.formatFast(buf)
  1090  			buf.WriteByte(')')
  1091  		} else {
  1092  			col.Column.formatFast(buf)
  1093  			if col.Length != nil {
  1094  				buf.WriteByte('(')
  1095  				col.Length.formatFast(buf)
  1096  				buf.WriteByte(')')
  1097  			}
  1098  		}
  1099  		if col.Direction == DescOrder {
  1100  			buf.WriteString(" desc")
  1101  		}
  1102  	}
  1103  	buf.WriteByte(')')
  1104  
  1105  	for _, opt := range idx.Options {
  1106  		buf.WriteByte(' ')
  1107  		buf.WriteString(opt.Name)
  1108  		if opt.String != "" {
  1109  			buf.WriteByte(' ')
  1110  			buf.WriteString(opt.String)
  1111  		} else if opt.Value != nil {
  1112  			buf.WriteByte(' ')
  1113  			opt.Value.formatFast(buf)
  1114  		}
  1115  	}
  1116  }
  1117  
  1118  // formatFast formats the node.
  1119  func (ii *IndexInfo) formatFast(buf *TrackedBuffer) {
  1120  	if !ii.ConstraintName.IsEmpty() {
  1121  		buf.WriteString("constraint ")
  1122  		ii.ConstraintName.formatFast(buf)
  1123  		buf.WriteByte(' ')
  1124  	}
  1125  	if ii.Primary {
  1126  		buf.WriteString(ii.Type)
  1127  	} else {
  1128  		buf.WriteString(ii.Type)
  1129  		if !ii.Name.IsEmpty() {
  1130  			buf.WriteByte(' ')
  1131  			ii.Name.formatFast(buf)
  1132  		}
  1133  	}
  1134  }
  1135  
  1136  // formatFast formats the node.
  1137  func (node *AutoIncSpec) formatFast(buf *TrackedBuffer) {
  1138  	node.Column.formatFast(buf)
  1139  	buf.WriteByte(' ')
  1140  	buf.WriteString("using ")
  1141  	node.Sequence.formatFast(buf)
  1142  }
  1143  
  1144  // formatFast formats the node. The "CREATE VINDEX" preamble was formatted in
  1145  // the containing DDL node Format, so this just prints the type, any
  1146  // parameters, and optionally the owner
  1147  func (node *VindexSpec) formatFast(buf *TrackedBuffer) {
  1148  	buf.WriteString("using ")
  1149  	node.Type.formatFast(buf)
  1150  
  1151  	numParams := len(node.Params)
  1152  	if numParams != 0 {
  1153  		buf.WriteString(" with ")
  1154  		for i, p := range node.Params {
  1155  			if i != 0 {
  1156  				buf.WriteString(", ")
  1157  			}
  1158  			p.formatFast(buf)
  1159  		}
  1160  	}
  1161  }
  1162  
  1163  // formatFast formats the node.
  1164  func (node VindexParam) formatFast(buf *TrackedBuffer) {
  1165  	buf.WriteString(node.Key.String())
  1166  	buf.WriteByte('=')
  1167  	buf.WriteString(node.Val)
  1168  }
  1169  
  1170  // formatFast formats the node.
  1171  func (c *ConstraintDefinition) formatFast(buf *TrackedBuffer) {
  1172  	if !c.Name.IsEmpty() {
  1173  		buf.WriteString("constraint ")
  1174  		c.Name.formatFast(buf)
  1175  		buf.WriteByte(' ')
  1176  	}
  1177  	c.Details.Format(buf)
  1178  }
  1179  
  1180  // formatFast formats the node.
  1181  func (a ReferenceAction) formatFast(buf *TrackedBuffer) {
  1182  	switch a {
  1183  	case Restrict:
  1184  		buf.WriteString("restrict")
  1185  	case Cascade:
  1186  		buf.WriteString("cascade")
  1187  	case NoAction:
  1188  		buf.WriteString("no action")
  1189  	case SetNull:
  1190  		buf.WriteString("set null")
  1191  	case SetDefault:
  1192  		buf.WriteString("set default")
  1193  	}
  1194  }
  1195  
  1196  // formatFast formats the node.
  1197  func (a MatchAction) formatFast(buf *TrackedBuffer) {
  1198  	switch a {
  1199  	case Full:
  1200  		buf.WriteString("full")
  1201  	case Simple:
  1202  		buf.WriteString("simple")
  1203  	case Partial:
  1204  		buf.WriteString("partial")
  1205  	}
  1206  }
  1207  
  1208  // formatFast formats the node.
  1209  func (f *ForeignKeyDefinition) formatFast(buf *TrackedBuffer) {
  1210  	buf.WriteString("foreign key ")
  1211  	f.IndexName.formatFast(buf)
  1212  	f.Source.formatFast(buf)
  1213  	buf.WriteByte(' ')
  1214  	f.ReferenceDefinition.formatFast(buf)
  1215  }
  1216  
  1217  // formatFast formats the node.
  1218  func (ref *ReferenceDefinition) formatFast(buf *TrackedBuffer) {
  1219  	buf.WriteString("references ")
  1220  	ref.ReferencedTable.formatFast(buf)
  1221  	buf.WriteByte(' ')
  1222  	ref.ReferencedColumns.formatFast(buf)
  1223  	if ref.Match != DefaultMatch {
  1224  		buf.WriteString(" match ")
  1225  		ref.Match.formatFast(buf)
  1226  	}
  1227  	if ref.OnDelete != DefaultAction {
  1228  		buf.WriteString(" on delete ")
  1229  		ref.OnDelete.formatFast(buf)
  1230  	}
  1231  	if ref.OnUpdate != DefaultAction {
  1232  		buf.WriteString(" on update ")
  1233  		ref.OnUpdate.formatFast(buf)
  1234  	}
  1235  }
  1236  
  1237  // formatFast formats the node.
  1238  func (c *CheckConstraintDefinition) formatFast(buf *TrackedBuffer) {
  1239  	buf.WriteString("check (")
  1240  	c.Expr.formatFast(buf)
  1241  	buf.WriteByte(')')
  1242  	if !c.Enforced {
  1243  		buf.WriteString(" not enforced")
  1244  	}
  1245  }
  1246  
  1247  // formatFast formats the node.
  1248  func (node *Show) formatFast(buf *TrackedBuffer) {
  1249  	node.Internal.formatFast(buf)
  1250  }
  1251  
  1252  // formatFast formats the node.
  1253  func (node *ShowFilter) formatFast(buf *TrackedBuffer) {
  1254  	if node == nil {
  1255  		return
  1256  	}
  1257  	if node.Like != "" {
  1258  		buf.WriteString(" like ")
  1259  		sqltypes.BufEncodeStringSQL(buf.Builder, node.Like)
  1260  	} else {
  1261  		buf.WriteString(" where ")
  1262  		node.Filter.formatFast(buf)
  1263  	}
  1264  }
  1265  
  1266  // formatFast formats the node.
  1267  func (node *Use) formatFast(buf *TrackedBuffer) {
  1268  	if node.DBName.v != "" {
  1269  		buf.WriteString("use ")
  1270  		node.DBName.formatFast(buf)
  1271  	} else {
  1272  		buf.WriteString("use")
  1273  	}
  1274  }
  1275  
  1276  // formatFast formats the node.
  1277  func (node *Commit) formatFast(buf *TrackedBuffer) {
  1278  	buf.WriteString("commit")
  1279  }
  1280  
  1281  // formatFast formats the node.
  1282  func (node *Begin) formatFast(buf *TrackedBuffer) {
  1283  	if node.TxAccessModes == nil {
  1284  		buf.WriteString("begin")
  1285  		return
  1286  	}
  1287  	buf.WriteString("start transaction")
  1288  	for idx, accessMode := range node.TxAccessModes {
  1289  		if idx == 0 {
  1290  			buf.WriteByte(' ')
  1291  			buf.WriteString(accessMode.ToString())
  1292  			continue
  1293  		}
  1294  		buf.WriteString(", ")
  1295  		buf.WriteString(accessMode.ToString())
  1296  	}
  1297  
  1298  }
  1299  
  1300  // formatFast formats the node.
  1301  func (node *Rollback) formatFast(buf *TrackedBuffer) {
  1302  	buf.WriteString("rollback")
  1303  }
  1304  
  1305  // formatFast formats the node.
  1306  func (node *SRollback) formatFast(buf *TrackedBuffer) {
  1307  	buf.WriteString("rollback to ")
  1308  	node.Name.formatFast(buf)
  1309  }
  1310  
  1311  // formatFast formats the node.
  1312  func (node *Savepoint) formatFast(buf *TrackedBuffer) {
  1313  	buf.WriteString("savepoint ")
  1314  	node.Name.formatFast(buf)
  1315  }
  1316  
  1317  // formatFast formats the node.
  1318  func (node *Release) formatFast(buf *TrackedBuffer) {
  1319  	buf.WriteString("release savepoint ")
  1320  	node.Name.formatFast(buf)
  1321  }
  1322  
  1323  // formatFast formats the node.
  1324  func (node *ExplainStmt) formatFast(buf *TrackedBuffer) {
  1325  	format := ""
  1326  	switch node.Type {
  1327  	case EmptyType:
  1328  	case AnalyzeType:
  1329  		format = AnalyzeStr + " "
  1330  	default:
  1331  		format = "format = " + node.Type.ToString() + " "
  1332  	}
  1333  	buf.WriteString("explain ")
  1334  	node.Comments.formatFast(buf)
  1335  	buf.WriteString(format)
  1336  	node.Statement.formatFast(buf)
  1337  }
  1338  
  1339  // formatFast formats the node.
  1340  func (node *VExplainStmt) formatFast(buf *TrackedBuffer) {
  1341  	buf.WriteString("vexplain ")
  1342  	node.Comments.formatFast(buf)
  1343  	buf.WriteString(node.Type.ToString())
  1344  	buf.WriteByte(' ')
  1345  	node.Statement.formatFast(buf)
  1346  }
  1347  
  1348  // formatFast formats the node.
  1349  func (node *ExplainTab) formatFast(buf *TrackedBuffer) {
  1350  	buf.WriteString("explain ")
  1351  	node.Table.formatFast(buf)
  1352  	if node.Wild != "" {
  1353  		buf.WriteByte(' ')
  1354  		buf.WriteString(node.Wild)
  1355  	}
  1356  }
  1357  
  1358  // formatFast formats the node.
  1359  func (node *PrepareStmt) formatFast(buf *TrackedBuffer) {
  1360  	buf.WriteString("prepare ")
  1361  	node.Comments.formatFast(buf)
  1362  	node.Name.formatFast(buf)
  1363  	buf.WriteString(" from ")
  1364  	if node.Statement != nil {
  1365  		node.Statement.formatFast(buf)
  1366  	}
  1367  }
  1368  
  1369  // formatFast formats the node.
  1370  func (node *ExecuteStmt) formatFast(buf *TrackedBuffer) {
  1371  	buf.WriteString("execute ")
  1372  	node.Comments.formatFast(buf)
  1373  	node.Name.formatFast(buf)
  1374  	if len(node.Arguments) > 0 {
  1375  		buf.WriteString(" using ")
  1376  	}
  1377  	var prefix string
  1378  	for _, n := range node.Arguments {
  1379  		buf.WriteString(prefix)
  1380  		n.formatFast(buf)
  1381  		prefix = ", "
  1382  	}
  1383  }
  1384  
  1385  // formatFast formats the node.
  1386  func (node *DeallocateStmt) formatFast(buf *TrackedBuffer) {
  1387  	buf.WriteString(node.Type.ToString())
  1388  	buf.WriteByte(' ')
  1389  	node.Comments.formatFast(buf)
  1390  	buf.WriteString("prepare ")
  1391  	node.Name.formatFast(buf)
  1392  }
  1393  
  1394  // formatFast formats the node.
  1395  func (node *CallProc) formatFast(buf *TrackedBuffer) {
  1396  	buf.WriteString("call ")
  1397  	node.Name.formatFast(buf)
  1398  	buf.WriteByte('(')
  1399  	node.Params.formatFast(buf)
  1400  	buf.WriteByte(')')
  1401  }
  1402  
  1403  // formatFast formats the node.
  1404  func (node *OtherRead) formatFast(buf *TrackedBuffer) {
  1405  	buf.WriteString("otherread")
  1406  }
  1407  
  1408  // formatFast formats the node.
  1409  func (node *OtherAdmin) formatFast(buf *TrackedBuffer) {
  1410  	buf.WriteString("otheradmin")
  1411  }
  1412  
  1413  // formatFast formats the node.
  1414  func (node *ParsedComments) formatFast(buf *TrackedBuffer) {
  1415  	if node == nil {
  1416  		return
  1417  	}
  1418  	for _, c := range node.comments {
  1419  		buf.WriteString(c)
  1420  		buf.WriteByte(' ')
  1421  	}
  1422  }
  1423  
  1424  // formatFast formats the node.
  1425  func (node SelectExprs) formatFast(buf *TrackedBuffer) {
  1426  	var prefix string
  1427  	for _, n := range node {
  1428  		buf.WriteString(prefix)
  1429  		n.formatFast(buf)
  1430  		prefix = ", "
  1431  	}
  1432  }
  1433  
  1434  // formatFast formats the node.
  1435  func (node *StarExpr) formatFast(buf *TrackedBuffer) {
  1436  	if !node.TableName.IsEmpty() {
  1437  		node.TableName.formatFast(buf)
  1438  		buf.WriteByte('.')
  1439  	}
  1440  	buf.WriteByte('*')
  1441  }
  1442  
  1443  // formatFast formats the node.
  1444  func (node *AliasedExpr) formatFast(buf *TrackedBuffer) {
  1445  	node.Expr.formatFast(buf)
  1446  	if !node.As.IsEmpty() {
  1447  		buf.WriteString(" as ")
  1448  		node.As.formatFast(buf)
  1449  	}
  1450  }
  1451  
  1452  // formatFast formats the node.
  1453  func (node *Nextval) formatFast(buf *TrackedBuffer) {
  1454  	buf.WriteString("next ")
  1455  	node.Expr.formatFast(buf)
  1456  	buf.WriteString(" values")
  1457  }
  1458  
  1459  // formatFast formats the node.
  1460  func (node Columns) formatFast(buf *TrackedBuffer) {
  1461  	if node == nil {
  1462  		return
  1463  	}
  1464  	buf.WriteByte('(')
  1465  	prefix := ""
  1466  	for _, n := range node {
  1467  		buf.WriteString(prefix)
  1468  		n.formatFast(buf)
  1469  		prefix = ", "
  1470  	}
  1471  	buf.WriteByte(')')
  1472  }
  1473  
  1474  // formatFast formats the node
  1475  func (node Partitions) formatFast(buf *TrackedBuffer) {
  1476  	if node == nil {
  1477  		return
  1478  	}
  1479  	prefix := " partition ("
  1480  	for _, n := range node {
  1481  		buf.WriteString(prefix)
  1482  		n.formatFast(buf)
  1483  		prefix = ", "
  1484  	}
  1485  	buf.WriteByte(')')
  1486  }
  1487  
  1488  // formatFast formats the node.
  1489  func (node TableExprs) formatFast(buf *TrackedBuffer) {
  1490  	var prefix string
  1491  	for _, n := range node {
  1492  		buf.WriteString(prefix)
  1493  		n.formatFast(buf)
  1494  		prefix = ", "
  1495  	}
  1496  }
  1497  
  1498  // formatFast formats the node.
  1499  func (node *AliasedTableExpr) formatFast(buf *TrackedBuffer) {
  1500  	node.Expr.formatFast(buf)
  1501  	node.Partitions.formatFast(buf)
  1502  	if !node.As.IsEmpty() {
  1503  		buf.WriteString(" as ")
  1504  		node.As.formatFast(buf)
  1505  		if len(node.Columns) != 0 {
  1506  			node.Columns.formatFast(buf)
  1507  		}
  1508  	}
  1509  	if node.Hints != nil {
  1510  		// Hint node provides the space padding.
  1511  		node.Hints.formatFast(buf)
  1512  	}
  1513  }
  1514  
  1515  // formatFast formats the node.
  1516  func (node TableNames) formatFast(buf *TrackedBuffer) {
  1517  	var prefix string
  1518  	for _, n := range node {
  1519  		buf.WriteString(prefix)
  1520  		n.formatFast(buf)
  1521  		prefix = ", "
  1522  	}
  1523  }
  1524  
  1525  // formatFast formats the node.
  1526  func (node TableName) formatFast(buf *TrackedBuffer) {
  1527  	if node.IsEmpty() {
  1528  		return
  1529  	}
  1530  	if !node.Qualifier.IsEmpty() {
  1531  		node.Qualifier.formatFast(buf)
  1532  		buf.WriteByte('.')
  1533  	}
  1534  	node.Name.formatFast(buf)
  1535  }
  1536  
  1537  // formatFast formats the node.
  1538  func (node *ParenTableExpr) formatFast(buf *TrackedBuffer) {
  1539  	buf.WriteByte('(')
  1540  	node.Exprs.formatFast(buf)
  1541  	buf.WriteByte(')')
  1542  }
  1543  
  1544  // formatFast formats the node.
  1545  func (node *JoinCondition) formatFast(buf *TrackedBuffer) {
  1546  	if node == nil {
  1547  		return
  1548  	}
  1549  	if node.On != nil {
  1550  		buf.WriteString(" on ")
  1551  		node.On.formatFast(buf)
  1552  	}
  1553  	if node.Using != nil {
  1554  		buf.WriteString(" using ")
  1555  		node.Using.formatFast(buf)
  1556  	}
  1557  }
  1558  
  1559  // formatFast formats the node.
  1560  func (node *JoinTableExpr) formatFast(buf *TrackedBuffer) {
  1561  	node.LeftExpr.formatFast(buf)
  1562  	buf.WriteByte(' ')
  1563  	buf.WriteString(node.Join.ToString())
  1564  	buf.WriteByte(' ')
  1565  	node.RightExpr.formatFast(buf)
  1566  	node.Condition.formatFast(buf)
  1567  }
  1568  
  1569  // formatFast formats the node.
  1570  func (node IndexHints) formatFast(buf *TrackedBuffer) {
  1571  	for _, n := range node {
  1572  		n.formatFast(buf)
  1573  	}
  1574  }
  1575  
  1576  // formatFast formats the node.
  1577  func (node *IndexHint) formatFast(buf *TrackedBuffer) {
  1578  	buf.WriteByte(' ')
  1579  	buf.WriteString(node.Type.ToString())
  1580  	buf.WriteString("index ")
  1581  	if node.ForType != NoForType {
  1582  		buf.WriteString("for ")
  1583  		buf.WriteString(node.ForType.ToString())
  1584  		buf.WriteByte(' ')
  1585  	}
  1586  	if len(node.Indexes) == 0 {
  1587  		buf.WriteString("()")
  1588  	} else {
  1589  		prefix := "("
  1590  		for _, n := range node.Indexes {
  1591  			buf.WriteString(prefix)
  1592  			n.formatFast(buf)
  1593  			prefix = ", "
  1594  		}
  1595  		buf.WriteByte(')')
  1596  	}
  1597  }
  1598  
  1599  // formatFast formats the node.
  1600  func (node *Where) formatFast(buf *TrackedBuffer) {
  1601  	if node == nil || node.Expr == nil {
  1602  		return
  1603  	}
  1604  	buf.WriteByte(' ')
  1605  	buf.WriteString(node.Type.ToString())
  1606  	buf.WriteByte(' ')
  1607  	node.Expr.formatFast(buf)
  1608  }
  1609  
  1610  // formatFast formats the node.
  1611  func (node Exprs) formatFast(buf *TrackedBuffer) {
  1612  	var prefix string
  1613  	for _, n := range node {
  1614  		buf.WriteString(prefix)
  1615  		n.formatFast(buf)
  1616  		prefix = ", "
  1617  	}
  1618  }
  1619  
  1620  // formatFast formats the node.
  1621  func (node *AndExpr) formatFast(buf *TrackedBuffer) {
  1622  	buf.printExpr(node, node.Left, true)
  1623  	buf.WriteString(" and ")
  1624  	buf.printExpr(node, node.Right, false)
  1625  }
  1626  
  1627  // formatFast formats the node.
  1628  func (node *OrExpr) formatFast(buf *TrackedBuffer) {
  1629  	buf.printExpr(node, node.Left, true)
  1630  	buf.WriteString(" or ")
  1631  	buf.printExpr(node, node.Right, false)
  1632  }
  1633  
  1634  // formatFast formats the node.
  1635  func (node *XorExpr) formatFast(buf *TrackedBuffer) {
  1636  	buf.printExpr(node, node.Left, true)
  1637  	buf.WriteString(" xor ")
  1638  	buf.printExpr(node, node.Right, false)
  1639  }
  1640  
  1641  // formatFast formats the node.
  1642  func (node *NotExpr) formatFast(buf *TrackedBuffer) {
  1643  	buf.WriteString("not ")
  1644  	buf.printExpr(node, node.Expr, true)
  1645  }
  1646  
  1647  // formatFast formats the node.
  1648  func (node *ComparisonExpr) formatFast(buf *TrackedBuffer) {
  1649  	buf.printExpr(node, node.Left, true)
  1650  	buf.WriteByte(' ')
  1651  	buf.WriteString(node.Operator.ToString())
  1652  	buf.WriteByte(' ')
  1653  	buf.printExpr(node, node.Right, false)
  1654  	if node.Escape != nil {
  1655  		buf.WriteString(" escape ")
  1656  		buf.printExpr(node, node.Escape, true)
  1657  	}
  1658  }
  1659  
  1660  // formatFast formats the node.
  1661  func (node *BetweenExpr) formatFast(buf *TrackedBuffer) {
  1662  	if node.IsBetween {
  1663  		buf.printExpr(node, node.Left, true)
  1664  		buf.WriteString(" between ")
  1665  		buf.printExpr(node, node.From, true)
  1666  		buf.WriteString(" and ")
  1667  		buf.printExpr(node, node.To, false)
  1668  	} else {
  1669  		buf.printExpr(node, node.Left, true)
  1670  		buf.WriteString(" not between ")
  1671  		buf.printExpr(node, node.From, true)
  1672  		buf.WriteString(" and ")
  1673  		buf.printExpr(node, node.To, false)
  1674  	}
  1675  }
  1676  
  1677  // formatFast formats the node.
  1678  func (node *IsExpr) formatFast(buf *TrackedBuffer) {
  1679  	buf.printExpr(node, node.Left, true)
  1680  	buf.WriteByte(' ')
  1681  	buf.WriteString(node.Right.ToString())
  1682  }
  1683  
  1684  // formatFast formats the node.
  1685  func (node *ExistsExpr) formatFast(buf *TrackedBuffer) {
  1686  	buf.WriteString("exists ")
  1687  	buf.printExpr(node, node.Subquery, true)
  1688  }
  1689  
  1690  // formatFast formats the node.
  1691  func (node *Literal) formatFast(buf *TrackedBuffer) {
  1692  	switch node.Type {
  1693  	case StrVal:
  1694  		sqltypes.MakeTrusted(sqltypes.VarBinary, node.Bytes()).EncodeSQL(buf)
  1695  	case IntVal, FloatVal, DecimalVal, HexNum:
  1696  		buf.WriteString(node.Val)
  1697  	case HexVal:
  1698  		buf.WriteString("X'")
  1699  		buf.WriteString(node.Val)
  1700  		buf.WriteByte('\'')
  1701  	case BitVal:
  1702  		buf.WriteString("B'")
  1703  		buf.WriteString(node.Val)
  1704  		buf.WriteByte('\'')
  1705  	case DateVal:
  1706  		buf.WriteString("date'")
  1707  		buf.WriteString(node.Val)
  1708  		buf.WriteByte('\'')
  1709  	case TimeVal:
  1710  		buf.WriteString("time'")
  1711  		buf.WriteString(node.Val)
  1712  		buf.WriteByte('\'')
  1713  	case TimestampVal:
  1714  		buf.WriteString("timestamp'")
  1715  		buf.WriteString(node.Val)
  1716  		buf.WriteByte('\'')
  1717  	default:
  1718  		panic("unexpected")
  1719  	}
  1720  }
  1721  
  1722  // formatFast formats the node.
  1723  func (node Argument) formatFast(buf *TrackedBuffer) {
  1724  	buf.WriteArg(":", string(node))
  1725  }
  1726  
  1727  // formatFast formats the node.
  1728  func (node *NullVal) formatFast(buf *TrackedBuffer) {
  1729  	buf.WriteString("null")
  1730  }
  1731  
  1732  // formatFast formats the node.
  1733  func (node BoolVal) formatFast(buf *TrackedBuffer) {
  1734  	if node {
  1735  		buf.WriteString("true")
  1736  	} else {
  1737  		buf.WriteString("false")
  1738  	}
  1739  }
  1740  
  1741  // formatFast formats the node.
  1742  func (node *ColName) formatFast(buf *TrackedBuffer) {
  1743  	if !node.Qualifier.IsEmpty() {
  1744  		node.Qualifier.formatFast(buf)
  1745  		buf.WriteByte('.')
  1746  	}
  1747  	node.Name.formatFast(buf)
  1748  }
  1749  
  1750  // formatFast formats the node.
  1751  func (node ValTuple) formatFast(buf *TrackedBuffer) {
  1752  	buf.WriteByte('(')
  1753  	Exprs(node).formatFast(buf)
  1754  	buf.WriteByte(')')
  1755  }
  1756  
  1757  // formatFast formats the node.
  1758  func (node *Subquery) formatFast(buf *TrackedBuffer) {
  1759  	buf.WriteByte('(')
  1760  	node.Select.formatFast(buf)
  1761  	buf.WriteByte(')')
  1762  }
  1763  
  1764  // formatFast formats the node.
  1765  func (node *DerivedTable) formatFast(buf *TrackedBuffer) {
  1766  	if node.Lateral {
  1767  		buf.WriteString("lateral ")
  1768  	}
  1769  	buf.WriteByte('(')
  1770  	node.Select.formatFast(buf)
  1771  	buf.WriteByte(')')
  1772  }
  1773  
  1774  // formatFast formats the node.
  1775  func (node ListArg) formatFast(buf *TrackedBuffer) {
  1776  	buf.WriteArg("::", string(node))
  1777  }
  1778  
  1779  // formatFast formats the node.
  1780  func (node *BinaryExpr) formatFast(buf *TrackedBuffer) {
  1781  	buf.printExpr(node, node.Left, true)
  1782  	buf.WriteByte(' ')
  1783  	buf.WriteString(node.Operator.ToString())
  1784  	buf.WriteByte(' ')
  1785  	buf.printExpr(node, node.Right, false)
  1786  }
  1787  
  1788  // formatFast formats the node.
  1789  func (node *UnaryExpr) formatFast(buf *TrackedBuffer) {
  1790  	if _, unary := node.Expr.(*UnaryExpr); unary {
  1791  		// They have same precedence so parenthesis is not required.
  1792  		buf.WriteString(node.Operator.ToString())
  1793  		buf.WriteByte(' ')
  1794  		buf.printExpr(node, node.Expr, true)
  1795  		return
  1796  	}
  1797  	buf.WriteString(node.Operator.ToString())
  1798  	buf.printExpr(node, node.Expr, true)
  1799  }
  1800  
  1801  // formatFast formats the node.
  1802  func (node *IntroducerExpr) formatFast(buf *TrackedBuffer) {
  1803  	buf.WriteString(node.CharacterSet)
  1804  	buf.WriteByte(' ')
  1805  	buf.printExpr(node, node.Expr, true)
  1806  }
  1807  
  1808  // formatFast formats the node.
  1809  func (node *IntervalExpr) formatFast(buf *TrackedBuffer) {
  1810  	buf.WriteString("interval ")
  1811  	buf.printExpr(node, node.Expr, true)
  1812  	buf.WriteByte(' ')
  1813  	buf.WriteString(node.Unit)
  1814  }
  1815  
  1816  // formatFast formats the node.
  1817  func (node *TimestampFuncExpr) formatFast(buf *TrackedBuffer) {
  1818  	buf.WriteString(node.Name)
  1819  	buf.WriteByte('(')
  1820  	buf.WriteString(node.Unit)
  1821  	buf.WriteString(", ")
  1822  	buf.printExpr(node, node.Expr1, true)
  1823  	buf.WriteString(", ")
  1824  	buf.printExpr(node, node.Expr2, true)
  1825  	buf.WriteByte(')')
  1826  }
  1827  
  1828  // formatFast formats the node.
  1829  func (node *ExtractFuncExpr) formatFast(buf *TrackedBuffer) {
  1830  	buf.WriteString("extract(")
  1831  	buf.WriteString(node.IntervalTypes.ToString())
  1832  	buf.WriteString(" from ")
  1833  	buf.printExpr(node, node.Expr, true)
  1834  	buf.WriteByte(')')
  1835  }
  1836  
  1837  // formatFast formats the node
  1838  func (node *RegexpInstrExpr) formatFast(buf *TrackedBuffer) {
  1839  	buf.WriteString("regexp_instr(")
  1840  	buf.printExpr(node, node.Expr, true)
  1841  	buf.WriteString(", ")
  1842  	buf.printExpr(node, node.Pattern, true)
  1843  	if node.Position != nil {
  1844  		buf.WriteString(", ")
  1845  		buf.printExpr(node, node.Position, true)
  1846  	}
  1847  	if node.Occurrence != nil {
  1848  		buf.WriteString(", ")
  1849  		buf.printExpr(node, node.Occurrence, true)
  1850  	}
  1851  	if node.ReturnOption != nil {
  1852  		buf.WriteString(", ")
  1853  		buf.printExpr(node, node.ReturnOption, true)
  1854  	}
  1855  	if node.MatchType != nil {
  1856  		buf.WriteString(", ")
  1857  		buf.printExpr(node, node.MatchType, true)
  1858  	}
  1859  	buf.WriteByte(')')
  1860  }
  1861  
  1862  // formatFast formats the node
  1863  func (node *RegexpLikeExpr) formatFast(buf *TrackedBuffer) {
  1864  	buf.WriteString("regexp_like(")
  1865  	buf.printExpr(node, node.Expr, true)
  1866  	buf.WriteString(", ")
  1867  	buf.printExpr(node, node.Pattern, true)
  1868  	if node.MatchType != nil {
  1869  		buf.WriteString(", ")
  1870  		buf.printExpr(node, node.MatchType, true)
  1871  	}
  1872  	buf.WriteByte(')')
  1873  }
  1874  
  1875  // formatFast formats the node
  1876  func (node *RegexpReplaceExpr) formatFast(buf *TrackedBuffer) {
  1877  	buf.WriteString("regexp_replace(")
  1878  	buf.printExpr(node, node.Expr, true)
  1879  	buf.WriteString(", ")
  1880  	buf.printExpr(node, node.Pattern, true)
  1881  	buf.WriteString(", ")
  1882  	buf.printExpr(node, node.Repl, true)
  1883  	if node.Position != nil {
  1884  		buf.WriteString(", ")
  1885  		buf.printExpr(node, node.Position, true)
  1886  	}
  1887  	if node.Occurrence != nil {
  1888  		buf.WriteString(", ")
  1889  		buf.printExpr(node, node.Occurrence, true)
  1890  	}
  1891  	if node.MatchType != nil {
  1892  		buf.WriteString(", ")
  1893  		buf.printExpr(node, node.MatchType, true)
  1894  	}
  1895  	buf.WriteByte(')')
  1896  }
  1897  
  1898  // formatFast formats the node
  1899  func (node *RegexpSubstrExpr) formatFast(buf *TrackedBuffer) {
  1900  	buf.WriteString("regexp_substr(")
  1901  	buf.printExpr(node, node.Expr, true)
  1902  	buf.WriteString(", ")
  1903  	buf.printExpr(node, node.Pattern, true)
  1904  	if node.Position != nil {
  1905  		buf.WriteString(", ")
  1906  		buf.printExpr(node, node.Position, true)
  1907  	}
  1908  	if node.Occurrence != nil {
  1909  		buf.WriteString(", ")
  1910  		buf.printExpr(node, node.Occurrence, true)
  1911  	}
  1912  	if node.MatchType != nil {
  1913  		buf.WriteString(", ")
  1914  		buf.printExpr(node, node.MatchType, true)
  1915  	}
  1916  	buf.WriteByte(')')
  1917  }
  1918  
  1919  // formatFast formats the node.
  1920  func (node *TrimFuncExpr) formatFast(buf *TrackedBuffer) {
  1921  	buf.WriteString(node.TrimFuncType.ToString())
  1922  	buf.WriteByte('(')
  1923  	if node.Type.ToString() != "" {
  1924  		buf.WriteString(node.Type.ToString())
  1925  		buf.WriteByte(' ')
  1926  	}
  1927  	if node.TrimArg != nil {
  1928  		buf.printExpr(node, node.TrimArg, true)
  1929  		buf.WriteByte(' ')
  1930  	}
  1931  
  1932  	if (node.Type.ToString() != "") || (node.TrimArg != nil) {
  1933  		buf.WriteString("from ")
  1934  	}
  1935  	buf.printExpr(node, node.StringArg, true)
  1936  	buf.WriteByte(')')
  1937  }
  1938  
  1939  // formatFast formats the node.
  1940  func (node *WeightStringFuncExpr) formatFast(buf *TrackedBuffer) {
  1941  	if node.As != nil {
  1942  		buf.WriteString("weight_string(")
  1943  		buf.printExpr(node, node.Expr, true)
  1944  		buf.WriteString(" as ")
  1945  		node.As.formatFast(buf)
  1946  		buf.WriteByte(')')
  1947  	} else {
  1948  		buf.WriteString("weight_string(")
  1949  		buf.printExpr(node, node.Expr, true)
  1950  		buf.WriteByte(')')
  1951  	}
  1952  }
  1953  
  1954  // formatFast formats the node.
  1955  func (node *CurTimeFuncExpr) formatFast(buf *TrackedBuffer) {
  1956  	if node.Fsp != nil {
  1957  		buf.WriteString(node.Name.String())
  1958  		buf.WriteByte('(')
  1959  		buf.printExpr(node, node.Fsp, true)
  1960  		buf.WriteByte(')')
  1961  	} else {
  1962  		buf.WriteString(node.Name.String())
  1963  		buf.WriteString("()")
  1964  	}
  1965  }
  1966  
  1967  // formatFast formats the node.
  1968  func (node *CollateExpr) formatFast(buf *TrackedBuffer) {
  1969  	buf.printExpr(node, node.Expr, true)
  1970  	buf.WriteString(" collate ")
  1971  	buf.WriteString(node.Collation)
  1972  }
  1973  
  1974  // formatFast formats the node.
  1975  func (node *FuncExpr) formatFast(buf *TrackedBuffer) {
  1976  	if !node.Qualifier.IsEmpty() {
  1977  		node.Qualifier.formatFast(buf)
  1978  		buf.WriteByte('.')
  1979  	}
  1980  	// Function names should not be back-quoted even
  1981  	// if they match a reserved word, only if they contain illegal characters
  1982  	funcName := node.Name.String()
  1983  
  1984  	if containEscapableChars(funcName, NoAt) {
  1985  		writeEscapedString(buf, funcName)
  1986  	} else {
  1987  		buf.WriteString(funcName)
  1988  	}
  1989  	buf.WriteByte('(')
  1990  	node.Exprs.formatFast(buf)
  1991  	buf.WriteByte(')')
  1992  }
  1993  
  1994  // formatFast formats the node
  1995  func (node *GroupConcatExpr) formatFast(buf *TrackedBuffer) {
  1996  	if node.Distinct {
  1997  		buf.WriteString("group_concat(")
  1998  		buf.WriteString(DistinctStr)
  1999  		node.Exprs.formatFast(buf)
  2000  		node.OrderBy.formatFast(buf)
  2001  		buf.WriteString(node.Separator)
  2002  		node.Limit.formatFast(buf)
  2003  		buf.WriteByte(')')
  2004  	} else {
  2005  		buf.WriteString("group_concat(")
  2006  		node.Exprs.formatFast(buf)
  2007  		node.OrderBy.formatFast(buf)
  2008  		buf.WriteString(node.Separator)
  2009  		node.Limit.formatFast(buf)
  2010  		buf.WriteByte(')')
  2011  	}
  2012  }
  2013  
  2014  // formatFast formats the node.
  2015  func (node *ValuesFuncExpr) formatFast(buf *TrackedBuffer) {
  2016  	buf.WriteString("values(")
  2017  	buf.printExpr(node, node.Name, true)
  2018  	buf.WriteByte(')')
  2019  }
  2020  
  2021  // formatFast formats the node
  2022  func (node *JSONPrettyExpr) formatFast(buf *TrackedBuffer) {
  2023  	buf.WriteString("json_pretty(")
  2024  	buf.printExpr(node, node.JSONVal, true)
  2025  	buf.WriteByte(')')
  2026  
  2027  }
  2028  
  2029  // formatFast formats the node
  2030  func (node *JSONStorageFreeExpr) formatFast(buf *TrackedBuffer) {
  2031  	buf.WriteString("json_storage_free(")
  2032  	buf.printExpr(node, node.JSONVal, true)
  2033  	buf.WriteByte(')')
  2034  
  2035  }
  2036  
  2037  // formatFast formats the node
  2038  func (node *JSONStorageSizeExpr) formatFast(buf *TrackedBuffer) {
  2039  	buf.WriteString("json_storage_size(")
  2040  	buf.printExpr(node, node.JSONVal, true)
  2041  	buf.WriteByte(')')
  2042  
  2043  }
  2044  
  2045  // formatFast formats the node
  2046  func (node *OverClause) formatFast(buf *TrackedBuffer) {
  2047  	buf.WriteString("over")
  2048  	if !node.WindowName.IsEmpty() {
  2049  		buf.WriteByte(' ')
  2050  		node.WindowName.formatFast(buf)
  2051  	}
  2052  	if node.WindowSpec != nil {
  2053  		buf.WriteString(" (")
  2054  		node.WindowSpec.formatFast(buf)
  2055  		buf.WriteByte(')')
  2056  	}
  2057  }
  2058  
  2059  // formatFast formats the node
  2060  func (node *WindowSpecification) formatFast(buf *TrackedBuffer) {
  2061  	if !node.Name.IsEmpty() {
  2062  		buf.WriteByte(' ')
  2063  		node.Name.formatFast(buf)
  2064  	}
  2065  	if node.PartitionClause != nil {
  2066  		buf.WriteString(" partition by ")
  2067  		node.PartitionClause.formatFast(buf)
  2068  	}
  2069  	if node.OrderClause != nil {
  2070  		node.OrderClause.formatFast(buf)
  2071  	}
  2072  	if node.FrameClause != nil {
  2073  		node.FrameClause.formatFast(buf)
  2074  	}
  2075  }
  2076  
  2077  // formatFast formats the node
  2078  func (node *FrameClause) formatFast(buf *TrackedBuffer) {
  2079  	buf.WriteByte(' ')
  2080  	buf.WriteString(node.Unit.ToString())
  2081  	if node.End != nil {
  2082  		buf.WriteString(" between")
  2083  		node.Start.formatFast(buf)
  2084  		buf.WriteString(" and")
  2085  		node.End.formatFast(buf)
  2086  	} else {
  2087  		node.Start.formatFast(buf)
  2088  	}
  2089  }
  2090  
  2091  // formatFast formats the node
  2092  func (node *NullTreatmentClause) formatFast(buf *TrackedBuffer) {
  2093  	buf.WriteByte(' ')
  2094  	buf.WriteString(node.Type.ToString())
  2095  }
  2096  
  2097  // formatFast formats the node
  2098  func (node *FromFirstLastClause) formatFast(buf *TrackedBuffer) {
  2099  	buf.WriteByte(' ')
  2100  	buf.WriteString(node.Type.ToString())
  2101  }
  2102  
  2103  // formatFast formats the node
  2104  func (node *FramePoint) formatFast(buf *TrackedBuffer) {
  2105  	if node.Expr != nil {
  2106  		buf.WriteByte(' ')
  2107  		node.Expr.formatFast(buf)
  2108  	}
  2109  	buf.WriteByte(' ')
  2110  	buf.WriteString(node.Type.ToString())
  2111  }
  2112  
  2113  // formatFast formats the node
  2114  func (node *ArgumentLessWindowExpr) formatFast(buf *TrackedBuffer) {
  2115  	buf.WriteString(node.Type.ToString())
  2116  	buf.WriteString("()")
  2117  	if node.OverClause != nil {
  2118  		buf.WriteByte(' ')
  2119  		node.OverClause.formatFast(buf)
  2120  	}
  2121  }
  2122  
  2123  // formatFast formats the node
  2124  func (node *FirstOrLastValueExpr) formatFast(buf *TrackedBuffer) {
  2125  	buf.WriteString(node.Type.ToString())
  2126  	buf.WriteByte('(')
  2127  	buf.printExpr(node, node.Expr, true)
  2128  	buf.WriteByte(')')
  2129  	if node.NullTreatmentClause != nil {
  2130  		node.NullTreatmentClause.formatFast(buf)
  2131  	}
  2132  	if node.OverClause != nil {
  2133  		buf.WriteByte(' ')
  2134  		node.OverClause.formatFast(buf)
  2135  	}
  2136  }
  2137  
  2138  // formatFast formats the node
  2139  func (node *NtileExpr) formatFast(buf *TrackedBuffer) {
  2140  	buf.WriteString("ntile(")
  2141  	buf.printExpr(node, node.N, true)
  2142  	buf.WriteString(")")
  2143  	if node.OverClause != nil {
  2144  		buf.WriteByte(' ')
  2145  		node.OverClause.formatFast(buf)
  2146  	}
  2147  }
  2148  
  2149  // formatFast formats the node
  2150  func (node *NTHValueExpr) formatFast(buf *TrackedBuffer) {
  2151  	buf.WriteString("nth_value(")
  2152  	buf.printExpr(node, node.Expr, true)
  2153  	buf.WriteString(", ")
  2154  	buf.printExpr(node, node.N, true)
  2155  	buf.WriteString(")")
  2156  	if node.FromFirstLastClause != nil {
  2157  		node.FromFirstLastClause.formatFast(buf)
  2158  	}
  2159  	if node.NullTreatmentClause != nil {
  2160  		node.NullTreatmentClause.formatFast(buf)
  2161  	}
  2162  	if node.OverClause != nil {
  2163  		buf.WriteByte(' ')
  2164  		node.OverClause.formatFast(buf)
  2165  	}
  2166  }
  2167  
  2168  // formatFast formats the node
  2169  func (node *LagLeadExpr) formatFast(buf *TrackedBuffer) {
  2170  	buf.WriteString(node.Type.ToString())
  2171  	buf.WriteByte('(')
  2172  	buf.printExpr(node, node.Expr, true)
  2173  	if node.N != nil {
  2174  		buf.WriteString(", ")
  2175  		buf.printExpr(node, node.N, true)
  2176  	}
  2177  	if node.Default != nil {
  2178  		buf.WriteString(", ")
  2179  		buf.printExpr(node, node.Default, true)
  2180  	}
  2181  	buf.WriteString(")")
  2182  	if node.NullTreatmentClause != nil {
  2183  		node.NullTreatmentClause.formatFast(buf)
  2184  	}
  2185  	if node.OverClause != nil {
  2186  		buf.WriteByte(' ')
  2187  		node.OverClause.formatFast(buf)
  2188  	}
  2189  }
  2190  
  2191  // formatFast formats the node
  2192  func (node *ExtractValueExpr) formatFast(buf *TrackedBuffer) {
  2193  	buf.WriteString("extractvalue(")
  2194  	buf.printExpr(node, node.Fragment, true)
  2195  	buf.WriteString(", ")
  2196  	buf.printExpr(node, node.XPathExpr, true)
  2197  	buf.WriteByte(')')
  2198  }
  2199  
  2200  // formatFast formats the node
  2201  func (node *UpdateXMLExpr) formatFast(buf *TrackedBuffer) {
  2202  	buf.WriteString("updatexml(")
  2203  	buf.printExpr(node, node.Target, true)
  2204  	buf.WriteString(", ")
  2205  	buf.printExpr(node, node.XPathExpr, true)
  2206  	buf.WriteString(", ")
  2207  	buf.printExpr(node, node.NewXML, true)
  2208  	buf.WriteByte(')')
  2209  }
  2210  
  2211  func (node *PerformanceSchemaFuncExpr) formatFast(buf *TrackedBuffer) {
  2212  	buf.WriteString(node.Type.ToString())
  2213  	buf.WriteByte('(')
  2214  	if node.Argument != nil {
  2215  		buf.printExpr(node, node.Argument, true)
  2216  	}
  2217  	buf.WriteByte(')')
  2218  }
  2219  
  2220  // formatFast formats the node
  2221  func (node *GTIDFuncExpr) formatFast(buf *TrackedBuffer) {
  2222  	buf.WriteString(node.Type.ToString())
  2223  	buf.WriteByte('(')
  2224  	buf.printExpr(node, node.Set1, true)
  2225  	if node.Set2 != nil {
  2226  		buf.WriteString(", ")
  2227  		buf.printExpr(node, node.Set2, true)
  2228  	}
  2229  	if node.Timeout != nil {
  2230  		buf.WriteString(", ")
  2231  		buf.printExpr(node, node.Timeout, true)
  2232  	}
  2233  	if node.Channel != nil {
  2234  		buf.WriteString(", ")
  2235  		buf.printExpr(node, node.Channel, true)
  2236  	}
  2237  	buf.WriteByte(')')
  2238  }
  2239  
  2240  // formatFast formats the node.
  2241  func (node *SubstrExpr) formatFast(buf *TrackedBuffer) {
  2242  	if node.To == nil {
  2243  		buf.WriteString("substr(")
  2244  		buf.printExpr(node, node.Name, true)
  2245  		buf.WriteString(", ")
  2246  		buf.printExpr(node, node.From, true)
  2247  		buf.WriteByte(')')
  2248  	} else {
  2249  		buf.WriteString("substr(")
  2250  		buf.printExpr(node, node.Name, true)
  2251  		buf.WriteString(", ")
  2252  		buf.printExpr(node, node.From, true)
  2253  		buf.WriteString(", ")
  2254  		buf.printExpr(node, node.To, true)
  2255  		buf.WriteByte(')')
  2256  	}
  2257  }
  2258  
  2259  // formatFast formats the node.
  2260  func (node *InsertExpr) formatFast(buf *TrackedBuffer) {
  2261  	buf.WriteString("insert(")
  2262  	buf.printExpr(node, node.Str, true)
  2263  	buf.WriteString(", ")
  2264  	buf.printExpr(node, node.Pos, true)
  2265  	buf.WriteString(", ")
  2266  	buf.printExpr(node, node.Len, true)
  2267  	buf.WriteString(", ")
  2268  	buf.printExpr(node, node.NewStr, true)
  2269  	buf.WriteByte(')')
  2270  }
  2271  
  2272  // formatFast formats the node.
  2273  func (node *IntervalFuncExpr) formatFast(buf *TrackedBuffer) {
  2274  	buf.WriteString("interval(")
  2275  	buf.printExpr(node, node.Expr, true)
  2276  	buf.WriteString(", ")
  2277  	node.Exprs.formatFast(buf)
  2278  	buf.WriteByte(')')
  2279  }
  2280  
  2281  // formatFast formats the node.
  2282  func (node *LocateExpr) formatFast(buf *TrackedBuffer) {
  2283  	if node.Pos != nil {
  2284  		buf.WriteString("locate(")
  2285  		buf.printExpr(node, node.SubStr, true)
  2286  		buf.WriteString(", ")
  2287  		buf.printExpr(node, node.Str, true)
  2288  		buf.WriteString(", ")
  2289  		buf.printExpr(node, node.Pos, true)
  2290  		buf.WriteByte(')')
  2291  	} else {
  2292  		buf.WriteString("locate(")
  2293  		buf.printExpr(node, node.SubStr, true)
  2294  		buf.WriteString(", ")
  2295  		buf.printExpr(node, node.Str, true)
  2296  		buf.WriteByte(')')
  2297  	}
  2298  }
  2299  
  2300  // formatFast formats the node.
  2301  func (node *CharExpr) formatFast(buf *TrackedBuffer) {
  2302  	buf.WriteString("char(")
  2303  	node.Exprs.formatFast(buf)
  2304  	if node.Charset != "" {
  2305  		buf.WriteString(" using ")
  2306  		buf.WriteString(node.Charset)
  2307  	}
  2308  	buf.WriteByte(')')
  2309  }
  2310  
  2311  // formatFast formats the node.
  2312  func (node *NamedWindow) formatFast(buf *TrackedBuffer) {
  2313  	buf.WriteString("window ")
  2314  	node.Windows.formatFast(buf)
  2315  }
  2316  
  2317  // formatFast formats the node.
  2318  func (node NamedWindows) formatFast(buf *TrackedBuffer) {
  2319  	var prefix string
  2320  	for _, n := range node {
  2321  		buf.WriteString(prefix)
  2322  		n.formatFast(buf)
  2323  		prefix = ", "
  2324  	}
  2325  }
  2326  
  2327  // formatFast formats the node.
  2328  func (node *WindowDefinition) formatFast(buf *TrackedBuffer) {
  2329  	node.Name.formatFast(buf)
  2330  	buf.WriteString(" AS (")
  2331  	node.WindowSpec.formatFast(buf)
  2332  	buf.WriteByte(')')
  2333  }
  2334  
  2335  // formatFast formats the node.
  2336  func (node WindowDefinitions) formatFast(buf *TrackedBuffer) {
  2337  	var prefix string
  2338  	for _, n := range node {
  2339  		buf.WriteString(prefix)
  2340  		n.formatFast(buf)
  2341  		prefix = ", "
  2342  	}
  2343  }
  2344  
  2345  // formatFast formats the node.
  2346  func (node *CastExpr) formatFast(buf *TrackedBuffer) {
  2347  	buf.WriteString("cast(")
  2348  	buf.printExpr(node, node.Expr, true)
  2349  	buf.WriteString(" as ")
  2350  	node.Type.formatFast(buf)
  2351  	if node.Array {
  2352  		buf.WriteByte(' ')
  2353  		buf.WriteString(keywordStrings[ARRAY])
  2354  	}
  2355  	buf.WriteByte(')')
  2356  }
  2357  
  2358  // formatFast formats the node.
  2359  func (node *ConvertExpr) formatFast(buf *TrackedBuffer) {
  2360  	buf.WriteString("convert(")
  2361  	buf.printExpr(node, node.Expr, true)
  2362  	buf.WriteString(", ")
  2363  	node.Type.formatFast(buf)
  2364  	buf.WriteByte(')')
  2365  }
  2366  
  2367  // formatFast formats the node.
  2368  func (node *ConvertUsingExpr) formatFast(buf *TrackedBuffer) {
  2369  	buf.WriteString("convert(")
  2370  	buf.printExpr(node, node.Expr, true)
  2371  	buf.WriteString(" using ")
  2372  	buf.WriteString(node.Type)
  2373  	buf.WriteByte(')')
  2374  }
  2375  
  2376  // formatFast formats the node.
  2377  func (node *ConvertType) formatFast(buf *TrackedBuffer) {
  2378  	buf.WriteString(node.Type)
  2379  	if node.Length != nil {
  2380  		buf.WriteByte('(')
  2381  		node.Length.formatFast(buf)
  2382  		if node.Scale != nil {
  2383  			buf.WriteString(", ")
  2384  			node.Scale.formatFast(buf)
  2385  		}
  2386  		buf.WriteByte(')')
  2387  	}
  2388  	if node.Charset.Name != "" {
  2389  		buf.WriteString(" character set ")
  2390  		buf.WriteString(node.Charset.Name)
  2391  	}
  2392  	if node.Charset.Binary {
  2393  		buf.WriteByte(' ')
  2394  		buf.WriteString(keywordStrings[BINARY])
  2395  	}
  2396  }
  2397  
  2398  // formatFast formats the node
  2399  func (node *MatchExpr) formatFast(buf *TrackedBuffer) {
  2400  	buf.WriteString("match(")
  2401  	for i, col := range node.Columns {
  2402  		if i != 0 {
  2403  			buf.WriteString(", ")
  2404  			buf.printExpr(node, col, true)
  2405  		} else {
  2406  			buf.printExpr(node, col, true)
  2407  		}
  2408  	}
  2409  	buf.WriteString(") against (")
  2410  	buf.printExpr(node, node.Expr, true)
  2411  	buf.WriteString(node.Option.ToString())
  2412  	buf.WriteByte(')')
  2413  }
  2414  
  2415  // formatFast formats the node.
  2416  func (node *CaseExpr) formatFast(buf *TrackedBuffer) {
  2417  	buf.WriteString("case ")
  2418  	if node.Expr != nil {
  2419  		buf.printExpr(node, node.Expr, true)
  2420  		buf.WriteByte(' ')
  2421  	}
  2422  	for _, when := range node.Whens {
  2423  		when.formatFast(buf)
  2424  		buf.WriteByte(' ')
  2425  	}
  2426  	if node.Else != nil {
  2427  		buf.WriteString("else ")
  2428  		buf.printExpr(node, node.Else, true)
  2429  		buf.WriteByte(' ')
  2430  	}
  2431  	buf.WriteString("end")
  2432  }
  2433  
  2434  // formatFast formats the node.
  2435  func (node *Default) formatFast(buf *TrackedBuffer) {
  2436  	buf.WriteString("default")
  2437  	if node.ColName != "" {
  2438  		buf.WriteByte('(')
  2439  		formatID(buf, node.ColName, NoAt)
  2440  		buf.WriteByte(')')
  2441  	}
  2442  }
  2443  
  2444  // formatFast formats the node.
  2445  func (node *When) formatFast(buf *TrackedBuffer) {
  2446  	buf.WriteString("when ")
  2447  	node.Cond.formatFast(buf)
  2448  	buf.WriteString(" then ")
  2449  	node.Val.formatFast(buf)
  2450  }
  2451  
  2452  // formatFast formats the node.
  2453  func (node GroupBy) formatFast(buf *TrackedBuffer) {
  2454  	prefix := " group by "
  2455  	for _, n := range node {
  2456  		buf.WriteString(prefix)
  2457  		n.formatFast(buf)
  2458  		prefix = ", "
  2459  	}
  2460  }
  2461  
  2462  // formatFast formats the node.
  2463  func (node OrderBy) formatFast(buf *TrackedBuffer) {
  2464  	prefix := " order by "
  2465  	for _, n := range node {
  2466  		buf.WriteString(prefix)
  2467  		n.formatFast(buf)
  2468  		prefix = ", "
  2469  	}
  2470  }
  2471  
  2472  // formatFast formats the node.
  2473  func (node *Order) formatFast(buf *TrackedBuffer) {
  2474  	if node, ok := node.Expr.(*NullVal); ok {
  2475  		buf.printExpr(node, node, true)
  2476  		return
  2477  	}
  2478  	if node, ok := node.Expr.(*FuncExpr); ok {
  2479  		if node.Name.Lowered() == "rand" {
  2480  			buf.printExpr(node, node, true)
  2481  			return
  2482  		}
  2483  	}
  2484  
  2485  	node.Expr.formatFast(buf)
  2486  	buf.WriteByte(' ')
  2487  	buf.WriteString(node.Direction.ToString())
  2488  }
  2489  
  2490  // formatFast formats the node.
  2491  func (node *Limit) formatFast(buf *TrackedBuffer) {
  2492  	if node == nil {
  2493  		return
  2494  	}
  2495  	buf.WriteString(" limit ")
  2496  	if node.Offset != nil {
  2497  		node.Offset.formatFast(buf)
  2498  		buf.WriteString(", ")
  2499  	}
  2500  	node.Rowcount.formatFast(buf)
  2501  }
  2502  
  2503  // formatFast formats the node.
  2504  func (node Values) formatFast(buf *TrackedBuffer) {
  2505  	prefix := "values "
  2506  	for _, n := range node {
  2507  		buf.WriteString(prefix)
  2508  		n.formatFast(buf)
  2509  		prefix = ", "
  2510  	}
  2511  }
  2512  
  2513  // formatFast formats the node.
  2514  func (node UpdateExprs) formatFast(buf *TrackedBuffer) {
  2515  	var prefix string
  2516  	for _, n := range node {
  2517  		buf.WriteString(prefix)
  2518  		n.formatFast(buf)
  2519  		prefix = ", "
  2520  	}
  2521  }
  2522  
  2523  // formatFast formats the node.
  2524  func (node *UpdateExpr) formatFast(buf *TrackedBuffer) {
  2525  	node.Name.formatFast(buf)
  2526  	buf.WriteString(" = ")
  2527  	node.Expr.formatFast(buf)
  2528  }
  2529  
  2530  // formatFast formats the node.
  2531  func (node SetExprs) formatFast(buf *TrackedBuffer) {
  2532  	var prefix string
  2533  	for _, n := range node {
  2534  		buf.WriteString(prefix)
  2535  		n.formatFast(buf)
  2536  		prefix = ", "
  2537  	}
  2538  }
  2539  
  2540  // formatFast formats the node.
  2541  func (node *SetExpr) formatFast(buf *TrackedBuffer) {
  2542  	// We don't have to backtick set variable names.
  2543  	switch {
  2544  	case node.Var.Name.EqualString("charset") || node.Var.Name.EqualString("names"):
  2545  		buf.WriteString(node.Var.Name.String())
  2546  		buf.WriteByte(' ')
  2547  		node.Expr.formatFast(buf)
  2548  	default:
  2549  		node.Var.formatFast(buf)
  2550  		buf.WriteString(" = ")
  2551  		node.Expr.formatFast(buf)
  2552  	}
  2553  }
  2554  
  2555  // formatFast formats the node.
  2556  func (node OnDup) formatFast(buf *TrackedBuffer) {
  2557  	if node == nil {
  2558  		return
  2559  	}
  2560  	buf.WriteString(" on duplicate key update ")
  2561  	UpdateExprs(node).formatFast(buf)
  2562  }
  2563  
  2564  // formatFast formats the node.
  2565  func (node IdentifierCI) formatFast(buf *TrackedBuffer) {
  2566  	if node.IsEmpty() {
  2567  		return
  2568  	}
  2569  	formatID(buf, node.val, NoAt)
  2570  }
  2571  
  2572  // formatFast formats the node.
  2573  func (node IdentifierCS) formatFast(buf *TrackedBuffer) {
  2574  	formatID(buf, node.v, NoAt)
  2575  }
  2576  
  2577  // formatFast formats the node.
  2578  func (node *Load) formatFast(buf *TrackedBuffer) {
  2579  	buf.WriteString("AST node missing for Load type")
  2580  }
  2581  
  2582  // formatFast formats the node.
  2583  func (node *ShowBasic) formatFast(buf *TrackedBuffer) {
  2584  	buf.WriteString("show")
  2585  	if node.Full {
  2586  		buf.WriteString(" full")
  2587  	}
  2588  	buf.WriteString(node.Command.ToString())
  2589  	if !node.Tbl.IsEmpty() {
  2590  		buf.WriteString(" from ")
  2591  		node.Tbl.formatFast(buf)
  2592  	}
  2593  	if !node.DbName.IsEmpty() {
  2594  		buf.WriteString(" from ")
  2595  		node.DbName.formatFast(buf)
  2596  	}
  2597  	node.Filter.formatFast(buf)
  2598  }
  2599  
  2600  // formatFast formats the node.
  2601  func (node *ShowCreate) formatFast(buf *TrackedBuffer) {
  2602  	buf.WriteString("show")
  2603  	buf.WriteString(node.Command.ToString())
  2604  	buf.WriteByte(' ')
  2605  	node.Op.formatFast(buf)
  2606  }
  2607  
  2608  // formatFast formats the node.
  2609  func (node *ShowOther) formatFast(buf *TrackedBuffer) {
  2610  	buf.WriteString("show ")
  2611  	buf.WriteString(node.Command)
  2612  }
  2613  
  2614  // formatFast formats the node.
  2615  func (node *SelectInto) formatFast(buf *TrackedBuffer) {
  2616  	if node == nil {
  2617  		return
  2618  	}
  2619  	buf.WriteString(node.Type.ToString())
  2620  	buf.WriteString(node.FileName)
  2621  	if node.Charset.Name != "" {
  2622  		buf.WriteString(" character set ")
  2623  		buf.WriteString(node.Charset.Name)
  2624  	}
  2625  	buf.WriteString(node.FormatOption)
  2626  	buf.WriteString(node.ExportOption)
  2627  	buf.WriteString(node.Manifest)
  2628  	buf.WriteString(node.Overwrite)
  2629  }
  2630  
  2631  // formatFast formats the node.
  2632  func (node *CreateDatabase) formatFast(buf *TrackedBuffer) {
  2633  	buf.WriteString("create database ")
  2634  	node.Comments.formatFast(buf)
  2635  	if node.IfNotExists {
  2636  		buf.WriteString("if not exists ")
  2637  	}
  2638  	node.DBName.formatFast(buf)
  2639  	if node.CreateOptions != nil {
  2640  		for _, createOption := range node.CreateOptions {
  2641  			if createOption.IsDefault {
  2642  				buf.WriteString(" default")
  2643  			}
  2644  			buf.WriteString(createOption.Type.ToString())
  2645  			buf.WriteByte(' ')
  2646  			buf.WriteString(createOption.Value)
  2647  		}
  2648  	}
  2649  }
  2650  
  2651  // formatFast formats the node.
  2652  func (node *AlterDatabase) formatFast(buf *TrackedBuffer) {
  2653  	buf.WriteString("alter database")
  2654  	if !node.DBName.IsEmpty() {
  2655  		buf.WriteByte(' ')
  2656  		node.DBName.formatFast(buf)
  2657  	}
  2658  	if node.UpdateDataDirectory {
  2659  		buf.WriteString(" upgrade data directory name")
  2660  	}
  2661  	if node.AlterOptions != nil {
  2662  		for _, createOption := range node.AlterOptions {
  2663  			if createOption.IsDefault {
  2664  				buf.WriteString(" default")
  2665  			}
  2666  			buf.WriteString(createOption.Type.ToString())
  2667  			buf.WriteByte(' ')
  2668  			buf.WriteString(createOption.Value)
  2669  		}
  2670  	}
  2671  }
  2672  
  2673  // formatFast formats the node.
  2674  func (node *CreateTable) formatFast(buf *TrackedBuffer) {
  2675  	buf.WriteString("create ")
  2676  	node.Comments.formatFast(buf)
  2677  	if node.Temp {
  2678  		buf.WriteString("temporary ")
  2679  	}
  2680  	buf.WriteString("table ")
  2681  
  2682  	if node.IfNotExists {
  2683  		buf.WriteString("if not exists ")
  2684  	}
  2685  	node.Table.formatFast(buf)
  2686  
  2687  	if node.OptLike != nil {
  2688  		buf.WriteByte(' ')
  2689  		node.OptLike.formatFast(buf)
  2690  	}
  2691  	if node.TableSpec != nil {
  2692  		buf.WriteByte(' ')
  2693  		node.TableSpec.formatFast(buf)
  2694  	}
  2695  }
  2696  
  2697  // formatFast formats the node.
  2698  func (node *CreateView) formatFast(buf *TrackedBuffer) {
  2699  	buf.WriteString("create ")
  2700  	node.Comments.formatFast(buf)
  2701  	if node.IsReplace {
  2702  		buf.WriteString("or replace ")
  2703  	}
  2704  	if node.Algorithm != "" {
  2705  		buf.WriteString("algorithm = ")
  2706  		buf.WriteString(node.Algorithm)
  2707  		buf.WriteByte(' ')
  2708  	}
  2709  	if node.Definer != nil {
  2710  		buf.WriteString("definer = ")
  2711  		node.Definer.formatFast(buf)
  2712  		buf.WriteByte(' ')
  2713  	}
  2714  	if node.Security != "" {
  2715  		buf.WriteString("sql security ")
  2716  		buf.WriteString(node.Security)
  2717  		buf.WriteByte(' ')
  2718  	}
  2719  	buf.WriteString("view ")
  2720  	node.ViewName.formatFast(buf)
  2721  	node.Columns.formatFast(buf)
  2722  	buf.WriteString(" as ")
  2723  	node.Select.formatFast(buf)
  2724  	if node.CheckOption != "" {
  2725  		buf.WriteString(" with ")
  2726  		buf.WriteString(node.CheckOption)
  2727  		buf.WriteString(" check option")
  2728  	}
  2729  }
  2730  
  2731  // formatFast formats the LockTables node.
  2732  func (node *LockTables) formatFast(buf *TrackedBuffer) {
  2733  	buf.WriteString("lock tables ")
  2734  	node.Tables[0].Table.formatFast(buf)
  2735  	buf.WriteByte(' ')
  2736  	buf.WriteString(node.Tables[0].Lock.ToString())
  2737  	for i := 1; i < len(node.Tables); i++ {
  2738  		buf.WriteString(", ")
  2739  		node.Tables[i].Table.formatFast(buf)
  2740  		buf.WriteByte(' ')
  2741  		buf.WriteString(node.Tables[i].Lock.ToString())
  2742  	}
  2743  }
  2744  
  2745  // formatFast formats the UnlockTables node.
  2746  func (node *UnlockTables) formatFast(buf *TrackedBuffer) {
  2747  	buf.WriteString("unlock tables")
  2748  }
  2749  
  2750  // formatFast formats the node.
  2751  func (node *AlterView) formatFast(buf *TrackedBuffer) {
  2752  	buf.WriteString("alter ")
  2753  	node.Comments.formatFast(buf)
  2754  	if node.Algorithm != "" {
  2755  		buf.WriteString("algorithm = ")
  2756  		buf.WriteString(node.Algorithm)
  2757  		buf.WriteByte(' ')
  2758  	}
  2759  	if node.Definer != nil {
  2760  		buf.WriteString("definer = ")
  2761  		node.Definer.formatFast(buf)
  2762  		buf.WriteByte(' ')
  2763  	}
  2764  	if node.Security != "" {
  2765  		buf.WriteString("sql security ")
  2766  		buf.WriteString(node.Security)
  2767  		buf.WriteByte(' ')
  2768  	}
  2769  	buf.WriteString("view ")
  2770  	node.ViewName.formatFast(buf)
  2771  	node.Columns.formatFast(buf)
  2772  	buf.WriteString(" as ")
  2773  	node.Select.formatFast(buf)
  2774  	if node.CheckOption != "" {
  2775  		buf.WriteString(" with ")
  2776  		buf.WriteString(node.CheckOption)
  2777  		buf.WriteString(" check option")
  2778  	}
  2779  }
  2780  
  2781  func (definer *Definer) formatFast(buf *TrackedBuffer) {
  2782  	buf.WriteString(definer.Name)
  2783  	if definer.Address != "" {
  2784  		buf.WriteByte('@')
  2785  		buf.WriteString(definer.Address)
  2786  	}
  2787  }
  2788  
  2789  // formatFast formats the node.
  2790  func (node *DropTable) formatFast(buf *TrackedBuffer) {
  2791  	temp := ""
  2792  	if node.Temp {
  2793  		temp = "temporary "
  2794  	}
  2795  	exists := ""
  2796  	if node.IfExists {
  2797  		exists = " if exists"
  2798  	}
  2799  	buf.WriteString("drop ")
  2800  	node.Comments.formatFast(buf)
  2801  	buf.WriteString(temp)
  2802  	buf.WriteString("table")
  2803  	buf.WriteString(exists)
  2804  	buf.WriteByte(' ')
  2805  	node.FromTables.formatFast(buf)
  2806  }
  2807  
  2808  // formatFast formats the node.
  2809  func (node *DropView) formatFast(buf *TrackedBuffer) {
  2810  	buf.WriteString("drop ")
  2811  	node.Comments.formatFast(buf)
  2812  	exists := ""
  2813  	if node.IfExists {
  2814  		exists = " if exists"
  2815  	}
  2816  	buf.WriteString("view")
  2817  	buf.WriteString(exists)
  2818  	buf.WriteByte(' ')
  2819  	node.FromTables.formatFast(buf)
  2820  }
  2821  
  2822  // formatFast formats the AlterTable node.
  2823  func (node *AlterTable) formatFast(buf *TrackedBuffer) {
  2824  	buf.WriteString("alter ")
  2825  	node.Comments.formatFast(buf)
  2826  	buf.WriteString("table ")
  2827  	node.Table.formatFast(buf)
  2828  	prefix := ""
  2829  	for i, option := range node.AlterOptions {
  2830  		if i != 0 {
  2831  			buf.WriteByte(',')
  2832  		}
  2833  		buf.WriteByte(' ')
  2834  		option.formatFast(buf)
  2835  		if node.PartitionSpec != nil && node.PartitionSpec.Action != RemoveAction {
  2836  			prefix = ","
  2837  		}
  2838  	}
  2839  	if node.PartitionSpec != nil {
  2840  		buf.WriteString(prefix)
  2841  		buf.WriteByte(' ')
  2842  		node.PartitionSpec.formatFast(buf)
  2843  	}
  2844  	if node.PartitionOption != nil {
  2845  		buf.WriteString(prefix)
  2846  		buf.WriteByte(' ')
  2847  		node.PartitionOption.formatFast(buf)
  2848  	}
  2849  }
  2850  
  2851  // formatFast formats the node.
  2852  func (node *AddConstraintDefinition) formatFast(buf *TrackedBuffer) {
  2853  	buf.WriteString("add ")
  2854  	node.ConstraintDefinition.formatFast(buf)
  2855  }
  2856  
  2857  func (node *AlterCheck) formatFast(buf *TrackedBuffer) {
  2858  	buf.WriteString("alter check ")
  2859  	node.Name.formatFast(buf)
  2860  	if node.Enforced {
  2861  		buf.WriteByte(' ')
  2862  		buf.WriteString(keywordStrings[ENFORCED])
  2863  	} else {
  2864  		buf.WriteByte(' ')
  2865  		buf.WriteString(keywordStrings[NOT])
  2866  		buf.WriteByte(' ')
  2867  		buf.WriteString(keywordStrings[ENFORCED])
  2868  	}
  2869  }
  2870  
  2871  // formatFast formats the node.
  2872  func (node *AddIndexDefinition) formatFast(buf *TrackedBuffer) {
  2873  	buf.WriteString("add ")
  2874  	node.IndexDefinition.formatFast(buf)
  2875  }
  2876  
  2877  // formatFast formats the node.
  2878  func (node *AddColumns) formatFast(buf *TrackedBuffer) {
  2879  
  2880  	if len(node.Columns) == 1 {
  2881  		buf.WriteString("add column ")
  2882  		node.Columns[0].formatFast(buf)
  2883  		if node.First {
  2884  			buf.WriteString(" first")
  2885  		}
  2886  		if node.After != nil {
  2887  			buf.WriteString(" after ")
  2888  			node.After.formatFast(buf)
  2889  		}
  2890  	} else {
  2891  		for i, col := range node.Columns {
  2892  			if i == 0 {
  2893  				buf.WriteString("add column (")
  2894  				col.formatFast(buf)
  2895  			} else {
  2896  				buf.WriteString(", ")
  2897  				col.formatFast(buf)
  2898  			}
  2899  		}
  2900  		buf.WriteByte(')')
  2901  	}
  2902  }
  2903  
  2904  // formatFast formats the node.
  2905  func (node AlgorithmValue) formatFast(buf *TrackedBuffer) {
  2906  	buf.WriteString("algorithm = ")
  2907  	buf.WriteString(string(node))
  2908  }
  2909  
  2910  // formatFast formats the node
  2911  func (node *AlterColumn) formatFast(buf *TrackedBuffer) {
  2912  	buf.WriteString("alter column ")
  2913  	node.Column.formatFast(buf)
  2914  	if node.DropDefault {
  2915  		buf.WriteString(" drop default")
  2916  	} else if node.DefaultVal != nil {
  2917  		buf.WriteString(" set default ")
  2918  		node.DefaultVal.formatFast(buf)
  2919  	}
  2920  	if node.Invisible != nil {
  2921  		if *node.Invisible {
  2922  			buf.WriteString(" set invisible")
  2923  		} else {
  2924  			buf.WriteString(" set visible")
  2925  		}
  2926  	}
  2927  }
  2928  
  2929  // formatFast formats the node
  2930  func (node *AlterIndex) formatFast(buf *TrackedBuffer) {
  2931  	buf.WriteString("alter index ")
  2932  	node.Name.formatFast(buf)
  2933  	if node.Invisible {
  2934  		buf.WriteString(" invisible")
  2935  	} else {
  2936  		buf.WriteString(" visible")
  2937  	}
  2938  }
  2939  
  2940  // formatFast formats the node
  2941  func (node *ChangeColumn) formatFast(buf *TrackedBuffer) {
  2942  	buf.WriteString("change column ")
  2943  	node.OldColumn.formatFast(buf)
  2944  	buf.WriteByte(' ')
  2945  	node.NewColDefinition.formatFast(buf)
  2946  	if node.First {
  2947  		buf.WriteString(" first")
  2948  	}
  2949  	if node.After != nil {
  2950  		buf.WriteString(" after ")
  2951  		node.After.formatFast(buf)
  2952  	}
  2953  }
  2954  
  2955  // formatFast formats the node
  2956  func (node *ModifyColumn) formatFast(buf *TrackedBuffer) {
  2957  	buf.WriteString("modify column ")
  2958  	node.NewColDefinition.formatFast(buf)
  2959  	if node.First {
  2960  		buf.WriteString(" first")
  2961  	}
  2962  	if node.After != nil {
  2963  		buf.WriteString(" after ")
  2964  		node.After.formatFast(buf)
  2965  	}
  2966  }
  2967  
  2968  // formatFast formats the node
  2969  func (node *RenameColumn) formatFast(buf *TrackedBuffer) {
  2970  	buf.WriteString("rename column ")
  2971  	node.OldName.formatFast(buf)
  2972  	buf.WriteString(" to ")
  2973  	node.NewName.formatFast(buf)
  2974  }
  2975  
  2976  // formatFast formats the node
  2977  func (node *AlterCharset) formatFast(buf *TrackedBuffer) {
  2978  	buf.WriteString("convert to character set ")
  2979  	buf.WriteString(node.CharacterSet)
  2980  	if node.Collate != "" {
  2981  		buf.WriteString(" collate ")
  2982  		buf.WriteString(node.Collate)
  2983  	}
  2984  }
  2985  
  2986  // formatFast formats the node
  2987  func (node *KeyState) formatFast(buf *TrackedBuffer) {
  2988  	if node.Enable {
  2989  		buf.WriteString("enable keys")
  2990  	} else {
  2991  		buf.WriteString("disable keys")
  2992  	}
  2993  
  2994  }
  2995  
  2996  // formatFast formats the node
  2997  func (node *TablespaceOperation) formatFast(buf *TrackedBuffer) {
  2998  	if node.Import {
  2999  		buf.WriteString("import tablespace")
  3000  	} else {
  3001  		buf.WriteString("discard tablespace")
  3002  	}
  3003  }
  3004  
  3005  // formatFast formats the node
  3006  func (node *DropColumn) formatFast(buf *TrackedBuffer) {
  3007  	buf.WriteString("drop column ")
  3008  	node.Name.formatFast(buf)
  3009  }
  3010  
  3011  // formatFast formats the node
  3012  func (node *DropKey) formatFast(buf *TrackedBuffer) {
  3013  	buf.WriteString("drop ")
  3014  	buf.WriteString(node.Type.ToString())
  3015  	if !node.Name.IsEmpty() {
  3016  		buf.WriteByte(' ')
  3017  		node.Name.formatFast(buf)
  3018  	}
  3019  }
  3020  
  3021  // formatFast formats the node
  3022  func (node *Force) formatFast(buf *TrackedBuffer) {
  3023  	buf.WriteString("force")
  3024  }
  3025  
  3026  // formatFast formats the node
  3027  func (node *LockOption) formatFast(buf *TrackedBuffer) {
  3028  	buf.WriteString("lock ")
  3029  	buf.WriteString(node.Type.ToString())
  3030  }
  3031  
  3032  // formatFast formats the node
  3033  func (node *OrderByOption) formatFast(buf *TrackedBuffer) {
  3034  	buf.WriteString("order by ")
  3035  	prefix := ""
  3036  	for _, n := range node.Cols {
  3037  		buf.WriteString(prefix)
  3038  		n.formatFast(buf)
  3039  		prefix = ", "
  3040  	}
  3041  }
  3042  
  3043  // formatFast formats the node
  3044  func (node *RenameTableName) formatFast(buf *TrackedBuffer) {
  3045  	buf.WriteString("rename ")
  3046  	node.Table.formatFast(buf)
  3047  }
  3048  
  3049  // formatFast formats the node
  3050  func (node *RenameIndex) formatFast(buf *TrackedBuffer) {
  3051  	buf.WriteString("rename index ")
  3052  	node.OldName.formatFast(buf)
  3053  	buf.WriteString(" to ")
  3054  	node.NewName.formatFast(buf)
  3055  }
  3056  
  3057  // formatFast formats the node
  3058  func (node *Validation) formatFast(buf *TrackedBuffer) {
  3059  	if node.With {
  3060  		buf.WriteString("with validation")
  3061  	} else {
  3062  		buf.WriteString("without validation")
  3063  	}
  3064  }
  3065  
  3066  // formatFast formats the node
  3067  func (node TableOptions) formatFast(buf *TrackedBuffer) {
  3068  	for i, option := range node {
  3069  		if i != 0 {
  3070  			buf.WriteByte(' ')
  3071  		}
  3072  		buf.WriteString(option.Name)
  3073  		switch {
  3074  		case option.String != "":
  3075  			if option.CaseSensitive {
  3076  				buf.WriteByte(' ')
  3077  				buf.WriteString(option.String)
  3078  			} else {
  3079  				buf.WriteByte(' ')
  3080  				buf.WriteString(option.String)
  3081  			}
  3082  		case option.Value != nil:
  3083  			buf.WriteByte(' ')
  3084  			option.Value.formatFast(buf)
  3085  		default:
  3086  			buf.WriteString(" (")
  3087  			option.Tables.formatFast(buf)
  3088  			buf.WriteByte(')')
  3089  		}
  3090  	}
  3091  }
  3092  
  3093  // formatFast formats the node
  3094  func (node *TruncateTable) formatFast(buf *TrackedBuffer) {
  3095  	buf.WriteString("truncate table ")
  3096  	node.Table.formatFast(buf)
  3097  }
  3098  
  3099  // formatFast formats the node.
  3100  func (node *RenameTable) formatFast(buf *TrackedBuffer) {
  3101  	buf.WriteString("rename table")
  3102  	prefix := " "
  3103  	for _, pair := range node.TablePairs {
  3104  		buf.WriteString(prefix)
  3105  		pair.FromTable.formatFast(buf)
  3106  		buf.WriteString(" to ")
  3107  		pair.ToTable.formatFast(buf)
  3108  		prefix = ", "
  3109  	}
  3110  }
  3111  
  3112  // formatFast formats the node.
  3113  // If an extracted subquery is still in the AST when we print it,
  3114  // it will be formatted as if the subquery has been extracted, and instead
  3115  // show up like argument comparisons
  3116  func (node *ExtractedSubquery) formatFast(buf *TrackedBuffer) {
  3117  	node.alternative.Format(buf)
  3118  }
  3119  
  3120  func (node *JSONTableExpr) formatFast(buf *TrackedBuffer) {
  3121  	buf.WriteString("json_table(")
  3122  	node.Expr.formatFast(buf)
  3123  	buf.WriteString(", ")
  3124  	node.Filter.formatFast(buf)
  3125  	buf.WriteString(" columns(\n")
  3126  	sz := len(node.Columns)
  3127  
  3128  	for i := 0; i < sz-1; i++ {
  3129  		buf.WriteByte('\t')
  3130  		node.Columns[i].formatFast(buf)
  3131  		buf.WriteString(",\n")
  3132  	}
  3133  	buf.WriteByte('\t')
  3134  	node.Columns[sz-1].formatFast(buf)
  3135  	buf.WriteByte('\n')
  3136  	buf.WriteString("\t)\n) as ")
  3137  	node.Alias.formatFast(buf)
  3138  }
  3139  
  3140  func (node *JtColumnDefinition) formatFast(buf *TrackedBuffer) {
  3141  	if node.JtOrdinal != nil {
  3142  		node.JtOrdinal.Name.formatFast(buf)
  3143  		buf.WriteString(" for ordinality")
  3144  	} else if node.JtNestedPath != nil {
  3145  		buf.WriteString("nested path ")
  3146  		node.JtNestedPath.Path.formatFast(buf)
  3147  		buf.WriteString(" columns(\n")
  3148  		sz := len(node.JtNestedPath.Columns)
  3149  
  3150  		for i := 0; i < sz-1; i++ {
  3151  			buf.WriteByte('\t')
  3152  			node.JtNestedPath.Columns[i].formatFast(buf)
  3153  			buf.WriteString(",\n")
  3154  		}
  3155  		buf.WriteByte('\t')
  3156  		node.JtNestedPath.Columns[sz-1].formatFast(buf)
  3157  		buf.WriteString("\n)")
  3158  	} else if node.JtPath != nil {
  3159  		node.JtPath.Name.formatFast(buf)
  3160  		buf.WriteByte(' ')
  3161  		node.JtPath.Type.formatFast(buf)
  3162  		buf.WriteByte(' ')
  3163  		if node.JtPath.JtColExists {
  3164  			buf.WriteString("exists ")
  3165  		}
  3166  		buf.WriteString("path ")
  3167  		node.JtPath.Path.formatFast(buf)
  3168  		buf.WriteByte(' ')
  3169  
  3170  		if node.JtPath.EmptyOnResponse != nil {
  3171  			node.JtPath.EmptyOnResponse.formatFast(buf)
  3172  			buf.WriteString(" on empty ")
  3173  		}
  3174  
  3175  		if node.JtPath.ErrorOnResponse != nil {
  3176  			node.JtPath.ErrorOnResponse.formatFast(buf)
  3177  			buf.WriteString(" on error ")
  3178  		}
  3179  	}
  3180  }
  3181  
  3182  func (node *JtOnResponse) formatFast(buf *TrackedBuffer) {
  3183  	switch node.ResponseType {
  3184  	case ErrorJSONType:
  3185  		buf.WriteString("error")
  3186  	case NullJSONType:
  3187  		buf.WriteString("null")
  3188  	case DefaultJSONType:
  3189  		buf.WriteString("default ")
  3190  		node.Expr.formatFast(buf)
  3191  	}
  3192  }
  3193  
  3194  // formatFast formats the node.
  3195  func (node *Offset) formatFast(buf *TrackedBuffer) {
  3196  	buf.WriteByte(':')
  3197  	buf.WriteString(fmt.Sprintf("%d", node.V))
  3198  }
  3199  
  3200  // formatFast formats the node.
  3201  func (node *JSONSchemaValidFuncExpr) formatFast(buf *TrackedBuffer) {
  3202  	buf.WriteString("json_schema_valid(")
  3203  	buf.printExpr(node, node.Schema, true)
  3204  	buf.WriteString(", ")
  3205  	buf.printExpr(node, node.Document, true)
  3206  	buf.WriteByte(')')
  3207  }
  3208  
  3209  // formatFast formats the node.
  3210  func (node *JSONSchemaValidationReportFuncExpr) formatFast(buf *TrackedBuffer) {
  3211  	buf.WriteString("json_schema_validation_report(")
  3212  	buf.printExpr(node, node.Schema, true)
  3213  	buf.WriteString(", ")
  3214  	buf.printExpr(node, node.Document, true)
  3215  	buf.WriteByte(')')
  3216  }
  3217  
  3218  // formatFast formats the node.
  3219  func (node *JSONArrayExpr) formatFast(buf *TrackedBuffer) {
  3220  	// buf.astPrintf(node,"%s(,"node.Name.Lowered())
  3221  	buf.WriteString("json_array(")
  3222  	if len(node.Params) > 0 {
  3223  		var prefix string
  3224  		for _, n := range node.Params {
  3225  			buf.WriteString(prefix)
  3226  			buf.printExpr(node, n, true)
  3227  			prefix = ", "
  3228  		}
  3229  	}
  3230  	buf.WriteByte(')')
  3231  }
  3232  
  3233  // formatFast formats the node.
  3234  func (node *JSONObjectExpr) formatFast(buf *TrackedBuffer) {
  3235  	// buf.astPrintf(node,"%s(,"node.Name.Lowered())
  3236  	buf.WriteString("json_object(")
  3237  	if len(node.Params) > 0 {
  3238  		for i, p := range node.Params {
  3239  			if i != 0 {
  3240  				buf.WriteString(", ")
  3241  
  3242  			}
  3243  			p.formatFast(buf)
  3244  		}
  3245  	}
  3246  	buf.WriteByte(')')
  3247  }
  3248  
  3249  // formatFast formats the node.
  3250  func (node *JSONObjectParam) formatFast(buf *TrackedBuffer) {
  3251  	node.Key.formatFast(buf)
  3252  	buf.WriteString(", ")
  3253  	node.Value.formatFast(buf)
  3254  }
  3255  
  3256  // formatFast formats the node.
  3257  func (node *JSONQuoteExpr) formatFast(buf *TrackedBuffer) {
  3258  	buf.WriteString("json_quote(")
  3259  	buf.printExpr(node, node.StringArg, true)
  3260  	buf.WriteByte(')')
  3261  }
  3262  
  3263  // formatFast formats the node
  3264  func (node *JSONContainsExpr) formatFast(buf *TrackedBuffer) {
  3265  	buf.WriteString("json_contains(")
  3266  	buf.printExpr(node, node.Target, true)
  3267  	buf.WriteString(", ")
  3268  	buf.printExpr(node, node.Candidate, true)
  3269  	if len(node.PathList) > 0 {
  3270  		buf.WriteString(", ")
  3271  	}
  3272  	var prefix string
  3273  	for _, n := range node.PathList {
  3274  		buf.WriteString(prefix)
  3275  		buf.printExpr(node, n, true)
  3276  		prefix = ", "
  3277  	}
  3278  	buf.WriteByte(')')
  3279  }
  3280  
  3281  // formatFast formats the node
  3282  func (node *JSONContainsPathExpr) formatFast(buf *TrackedBuffer) {
  3283  	buf.WriteString("json_contains_path(")
  3284  	buf.printExpr(node, node.JSONDoc, true)
  3285  	buf.WriteString(", ")
  3286  	buf.printExpr(node, node.OneOrAll, true)
  3287  	buf.WriteString(", ")
  3288  	var prefix string
  3289  	for _, n := range node.PathList {
  3290  		buf.WriteString(prefix)
  3291  		buf.printExpr(node, n, true)
  3292  		prefix = ", "
  3293  	}
  3294  	buf.WriteByte(')')
  3295  }
  3296  
  3297  // formatFast formats the node
  3298  func (node *JSONExtractExpr) formatFast(buf *TrackedBuffer) {
  3299  	buf.WriteString("json_extract(")
  3300  	buf.printExpr(node, node.JSONDoc, true)
  3301  	buf.WriteString(", ")
  3302  	var prefix string
  3303  	for _, n := range node.PathList {
  3304  		buf.WriteString(prefix)
  3305  		buf.printExpr(node, n, true)
  3306  		prefix = ", "
  3307  	}
  3308  	buf.WriteByte(')')
  3309  }
  3310  
  3311  // formatFast formats the node
  3312  func (node *JSONKeysExpr) formatFast(buf *TrackedBuffer) {
  3313  	buf.WriteString("json_keys(")
  3314  	buf.printExpr(node, node.JSONDoc, true)
  3315  	if node.Path != nil {
  3316  		buf.WriteString(", ")
  3317  		buf.printExpr(node, node.Path, true)
  3318  		buf.WriteByte(')')
  3319  		return
  3320  	}
  3321  	buf.WriteByte(')')
  3322  }
  3323  
  3324  // formatFast formats the node
  3325  func (node *JSONOverlapsExpr) formatFast(buf *TrackedBuffer) {
  3326  	buf.WriteString("json_overlaps(")
  3327  	buf.printExpr(node, node.JSONDoc1, true)
  3328  	buf.WriteString(", ")
  3329  	buf.printExpr(node, node.JSONDoc2, true)
  3330  	buf.WriteByte(')')
  3331  }
  3332  
  3333  // formatFast formats the node
  3334  func (node *JSONSearchExpr) formatFast(buf *TrackedBuffer) {
  3335  	buf.WriteString("json_search(")
  3336  	buf.printExpr(node, node.JSONDoc, true)
  3337  	buf.WriteString(", ")
  3338  	buf.printExpr(node, node.OneOrAll, true)
  3339  	buf.WriteString(", ")
  3340  	buf.printExpr(node, node.SearchStr, true)
  3341  	if node.EscapeChar != nil {
  3342  		buf.WriteString(", ")
  3343  		buf.printExpr(node, node.EscapeChar, true)
  3344  	}
  3345  	if len(node.PathList) > 0 {
  3346  		buf.WriteString(", ")
  3347  	}
  3348  	var prefix string
  3349  	for _, n := range node.PathList {
  3350  		buf.WriteString(prefix)
  3351  		buf.printExpr(node, n, true)
  3352  		prefix = ", "
  3353  	}
  3354  	buf.WriteByte(')')
  3355  }
  3356  
  3357  // formatFast formats the node
  3358  func (node *JSONValueExpr) formatFast(buf *TrackedBuffer) {
  3359  	buf.WriteString("json_value(")
  3360  	buf.printExpr(node, node.JSONDoc, true)
  3361  	buf.WriteString(", ")
  3362  	buf.printExpr(node, node.Path, true)
  3363  
  3364  	if node.ReturningType != nil {
  3365  		buf.WriteString(" returning ")
  3366  		node.ReturningType.formatFast(buf)
  3367  	}
  3368  
  3369  	if node.EmptyOnResponse != nil {
  3370  		buf.WriteByte(' ')
  3371  		node.EmptyOnResponse.formatFast(buf)
  3372  		buf.WriteString(" on empty")
  3373  	}
  3374  
  3375  	if node.ErrorOnResponse != nil {
  3376  		buf.WriteByte(' ')
  3377  		node.ErrorOnResponse.formatFast(buf)
  3378  		buf.WriteString(" on error")
  3379  	}
  3380  
  3381  	buf.WriteByte(')')
  3382  }
  3383  
  3384  // formatFast formats the node
  3385  func (node *MemberOfExpr) formatFast(buf *TrackedBuffer) {
  3386  	buf.printExpr(node, node.Value, true)
  3387  	buf.WriteString(" member of (")
  3388  	buf.printExpr(node, node.JSONArr, true)
  3389  	buf.WriteByte(')')
  3390  }
  3391  
  3392  // formatFast formats the node
  3393  func (node *JSONAttributesExpr) formatFast(buf *TrackedBuffer) {
  3394  	buf.WriteString(node.Type.ToString())
  3395  	buf.WriteByte('(')
  3396  	buf.printExpr(node, node.JSONDoc, true)
  3397  	if node.Path != nil {
  3398  		buf.WriteString(", ")
  3399  		buf.printExpr(node, node.Path, true)
  3400  	}
  3401  	buf.WriteString(")")
  3402  }
  3403  
  3404  // formatFast formats the node.
  3405  func (node *JSONValueModifierExpr) formatFast(buf *TrackedBuffer) {
  3406  	buf.WriteString(node.Type.ToString())
  3407  	buf.WriteByte('(')
  3408  	buf.printExpr(node, node.JSONDoc, true)
  3409  	buf.WriteString(", ")
  3410  	var prefix string
  3411  	for _, n := range node.Params {
  3412  		buf.WriteString(prefix)
  3413  		n.formatFast(buf)
  3414  		prefix = ", "
  3415  	}
  3416  	buf.WriteString(")")
  3417  }
  3418  
  3419  // formatFast formats the node.
  3420  func (node *JSONValueMergeExpr) formatFast(buf *TrackedBuffer) {
  3421  	buf.WriteString(node.Type.ToString())
  3422  	buf.WriteByte('(')
  3423  	buf.printExpr(node, node.JSONDoc, true)
  3424  	buf.WriteString(", ")
  3425  	var prefix string
  3426  	for _, n := range node.JSONDocList {
  3427  		buf.WriteString(prefix)
  3428  		buf.printExpr(node, n, true)
  3429  		prefix = ", "
  3430  	}
  3431  	buf.WriteString(")")
  3432  }
  3433  
  3434  // formatFast formats the node.
  3435  func (node *JSONRemoveExpr) formatFast(buf *TrackedBuffer) {
  3436  	buf.WriteString("json_remove(")
  3437  	buf.printExpr(node, node.JSONDoc, true)
  3438  	buf.WriteString(", ")
  3439  	var prefix string
  3440  	for _, n := range node.PathList {
  3441  		buf.WriteString(prefix)
  3442  		buf.printExpr(node, n, true)
  3443  		prefix = ", "
  3444  	}
  3445  	buf.WriteString(")")
  3446  }
  3447  
  3448  // formatFast formats the node.
  3449  func (node *JSONUnquoteExpr) formatFast(buf *TrackedBuffer) {
  3450  	buf.WriteString("json_unquote(")
  3451  	buf.printExpr(node, node.JSONValue, true)
  3452  	buf.WriteString(")")
  3453  }
  3454  
  3455  func (node *Count) formatFast(buf *TrackedBuffer) {
  3456  	buf.WriteString(node.AggrName())
  3457  	buf.WriteByte('(')
  3458  	if node.Distinct {
  3459  		buf.WriteString(DistinctStr)
  3460  	}
  3461  	node.Args.formatFast(buf)
  3462  	buf.WriteByte(')')
  3463  }
  3464  
  3465  func (node *CountStar) formatFast(buf *TrackedBuffer) {
  3466  	buf.WriteString(node.AggrName())
  3467  	buf.WriteByte('(')
  3468  	buf.WriteString("*)")
  3469  }
  3470  
  3471  func (node *Avg) formatFast(buf *TrackedBuffer) {
  3472  	buf.WriteString(node.AggrName())
  3473  	buf.WriteByte('(')
  3474  	if node.Distinct {
  3475  		buf.WriteString(DistinctStr)
  3476  	}
  3477  	buf.printExpr(node, node.Arg, true)
  3478  	buf.WriteByte(')')
  3479  }
  3480  
  3481  func (node *Max) formatFast(buf *TrackedBuffer) {
  3482  	buf.WriteString(node.AggrName())
  3483  	buf.WriteByte('(')
  3484  	if node.Distinct {
  3485  		buf.WriteString(DistinctStr)
  3486  	}
  3487  	buf.printExpr(node, node.Arg, true)
  3488  	buf.WriteByte(')')
  3489  }
  3490  
  3491  func (node *Min) formatFast(buf *TrackedBuffer) {
  3492  	buf.WriteString(node.AggrName())
  3493  	buf.WriteByte('(')
  3494  	if node.Distinct {
  3495  		buf.WriteString(DistinctStr)
  3496  	}
  3497  	buf.printExpr(node, node.Arg, true)
  3498  	buf.WriteByte(')')
  3499  }
  3500  
  3501  func (node *Sum) formatFast(buf *TrackedBuffer) {
  3502  	buf.WriteString(node.AggrName())
  3503  	buf.WriteByte('(')
  3504  	if node.Distinct {
  3505  		buf.WriteString(DistinctStr)
  3506  	}
  3507  	buf.printExpr(node, node.Arg, true)
  3508  	buf.WriteByte(')')
  3509  }
  3510  
  3511  func (node *BitAnd) formatFast(buf *TrackedBuffer) {
  3512  	buf.WriteString(node.AggrName())
  3513  	buf.WriteByte('(')
  3514  	buf.printExpr(node, node.Arg, true)
  3515  	buf.WriteByte(')')
  3516  }
  3517  
  3518  func (node *BitOr) formatFast(buf *TrackedBuffer) {
  3519  	buf.WriteString(node.AggrName())
  3520  	buf.WriteByte('(')
  3521  	buf.printExpr(node, node.Arg, true)
  3522  	buf.WriteByte(')')
  3523  }
  3524  
  3525  func (node *BitXor) formatFast(buf *TrackedBuffer) {
  3526  	buf.WriteString(node.AggrName())
  3527  	buf.WriteByte('(')
  3528  	buf.printExpr(node, node.Arg, true)
  3529  	buf.WriteByte(')')
  3530  }
  3531  
  3532  func (node *Std) formatFast(buf *TrackedBuffer) {
  3533  	buf.WriteString(node.AggrName())
  3534  	buf.WriteByte('(')
  3535  	buf.printExpr(node, node.Arg, true)
  3536  	buf.WriteByte(')')
  3537  }
  3538  
  3539  func (node *StdDev) formatFast(buf *TrackedBuffer) {
  3540  	buf.WriteString(node.AggrName())
  3541  	buf.WriteByte('(')
  3542  	buf.printExpr(node, node.Arg, true)
  3543  	buf.WriteByte(')')
  3544  }
  3545  
  3546  func (node *StdPop) formatFast(buf *TrackedBuffer) {
  3547  	buf.WriteString(node.AggrName())
  3548  	buf.WriteByte('(')
  3549  	buf.printExpr(node, node.Arg, true)
  3550  	buf.WriteByte(')')
  3551  }
  3552  
  3553  func (node *StdSamp) formatFast(buf *TrackedBuffer) {
  3554  	buf.WriteString(node.AggrName())
  3555  	buf.WriteByte('(')
  3556  	buf.printExpr(node, node.Arg, true)
  3557  	buf.WriteByte(')')
  3558  }
  3559  
  3560  func (node *VarPop) formatFast(buf *TrackedBuffer) {
  3561  	buf.WriteString(node.AggrName())
  3562  	buf.WriteByte('(')
  3563  	buf.printExpr(node, node.Arg, true)
  3564  	buf.WriteByte(')')
  3565  }
  3566  
  3567  func (node *VarSamp) formatFast(buf *TrackedBuffer) {
  3568  	buf.WriteString(node.AggrName())
  3569  	buf.WriteByte('(')
  3570  	buf.printExpr(node, node.Arg, true)
  3571  	buf.WriteByte(')')
  3572  }
  3573  
  3574  func (node *Variance) formatFast(buf *TrackedBuffer) {
  3575  	buf.WriteString(node.AggrName())
  3576  	buf.WriteByte('(')
  3577  	buf.printExpr(node, node.Arg, true)
  3578  	buf.WriteByte(')')
  3579  }
  3580  
  3581  // formatFast formats the node.
  3582  func (node *LockingFunc) formatFast(buf *TrackedBuffer) {
  3583  	buf.WriteString(node.Type.ToString() + "(")
  3584  	if node.Type != ReleaseAllLocks {
  3585  		buf.printExpr(node, node.Name, true)
  3586  	}
  3587  	if node.Type == GetLock {
  3588  		buf.WriteString(", ")
  3589  		buf.printExpr(node, node.Timeout, true)
  3590  	}
  3591  	buf.WriteString(")")
  3592  }
  3593  
  3594  // formatFast formats the node.
  3595  func (node *Variable) formatFast(buf *TrackedBuffer) {
  3596  	switch node.Scope {
  3597  	case VariableScope:
  3598  		buf.WriteString("@")
  3599  	case SessionScope:
  3600  		if node.Name.EqualString(TransactionIsolationStr) || node.Name.EqualString(TransactionReadOnlyStr) {
  3601  			// @@ without session have `next transaction` scope for these system variables.
  3602  			// so if they are in session scope it has to be printed explicitly.
  3603  			buf.WriteString("@@")
  3604  			buf.WriteString(node.Scope.ToString())
  3605  			buf.WriteByte('.')
  3606  			break
  3607  		}
  3608  		buf.WriteString("@@")
  3609  	case GlobalScope, PersistSysScope, PersistOnlySysScope:
  3610  		buf.WriteString("@@")
  3611  		buf.WriteString(node.Scope.ToString())
  3612  		buf.WriteByte('.')
  3613  	case NextTxScope:
  3614  		buf.WriteString("@@")
  3615  	}
  3616  	node.Name.formatFast(buf)
  3617  }
  3618  
  3619  // formatFast formats the node.
  3620  func (node *PointExpr) formatFast(buf *TrackedBuffer) {
  3621  	buf.WriteString("point(")
  3622  	buf.printExpr(node, node.XCordinate, true)
  3623  	buf.WriteString(", ")
  3624  	buf.printExpr(node, node.YCordinate, true)
  3625  	buf.WriteByte(')')
  3626  }
  3627  
  3628  // formatFast formats the node.
  3629  func (node *LineStringExpr) formatFast(buf *TrackedBuffer) {
  3630  	buf.WriteString("linestring(")
  3631  	node.PointParams.formatFast(buf)
  3632  	buf.WriteByte(')')
  3633  }