@@ -81,8 +81,8 @@ func resolveInsertRows(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Sc
8181 }
8282
8383 // The schema of the destination node and the underlying table differ subtly in terms of defaults
84- var missingValFlags [] bool
85- project , firstGeneratedAutoIncRowIdx , missingValFlags , err := wrapRowSource (
84+ var deferredDefaults sql. FastIntSet
85+ project , firstGeneratedAutoIncRowIdx , deferredDefaults , err := wrapRowSource (
8686 ctx ,
8787 source ,
8888 insertable ,
@@ -95,7 +95,7 @@ func resolveInsertRows(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Sc
9595
9696 return insert .WithSource (project ).
9797 WithAutoIncrementIdx (firstGeneratedAutoIncRowIdx ).
98- WithMissingValFlags ( missingValFlags ),
98+ WithDeferredDefaults ( deferredDefaults ),
9999 transform .NewTree ,
100100 nil
101101 })
@@ -128,9 +128,9 @@ func findColIdx(colName string, colNames []string) int {
128128// wrapRowSource returns a projection that wraps the original row source so that its schema matches the full schema of
129129// the underlying table in the same order. Also, returns an integer value that indicates when this row source will
130130// result in an automatically generated value for an auto_increment column.
131- func wrapRowSource (ctx * sql.Context , insertSource sql.Node , destTbl sql.Table , schema sql.Schema , columnNames []string ) (sql.Node , int , [] bool , error ) {
131+ func wrapRowSource (ctx * sql.Context , insertSource sql.Node , destTbl sql.Table , schema sql.Schema , columnNames []string ) (sql.Node , int , sql. FastIntSet , error ) {
132132 projExprs := make ([]sql.Expression , len (schema ))
133- missingVals := make ([] bool , len ( schema ) )
133+ deferredDefaults := sql . NewFastIntSet ( )
134134 firstGeneratedAutoIncRowIdx := - 1
135135
136136 for i , col := range schema {
@@ -142,7 +142,7 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
142142 defaultExpr = col .Generated
143143 }
144144 if ! col .Nullable && defaultExpr == nil && ! col .AutoIncrement {
145- missingVals [ i ] = true
145+ deferredDefaults . Add ( i )
146146 }
147147
148148 var err error
@@ -163,7 +163,7 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
163163 }
164164 })
165165 if err != nil {
166- return nil , - 1 , nil , err
166+ return nil , - 1 , sql. FastIntSet {} , err
167167 }
168168 projExprs [i ] = def
169169 } else {
@@ -175,7 +175,7 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
175175 // wrap it in an AutoIncrement expression.
176176 ai , err := expression .NewAutoIncrement (ctx , destTbl , projExprs [i ])
177177 if err != nil {
178- return nil , - 1 , nil , err
178+ return nil , - 1 , sql. FastIntSet {} , err
179179 }
180180 projExprs [i ] = ai
181181
@@ -218,7 +218,7 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
218218 // ColumnDefaultValue to create the UUID), then update the project to include the AutoUuid expression.
219219 newExpr , identity , err := insertAutoUuidExpression (ctx , columnDefaultValue , autoUuidCol )
220220 if err != nil {
221- return nil , - 1 , nil , err
221+ return nil , - 1 , sql. FastIntSet {} , err
222222 }
223223 if identity == transform .NewTree {
224224 projExprs [autoUuidColIdx ] = newExpr
@@ -229,12 +229,12 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
229229 // the AutoUuid expression to it.
230230 err := wrapAutoUuidInValuesTuples (ctx , autoUuidCol , insertSource , columnNames )
231231 if err != nil {
232- return nil , - 1 , nil , err
232+ return nil , - 1 , sql. FastIntSet {} , err
233233 }
234234 }
235235 }
236236
237- return plan .NewProject (projExprs , insertSource ), firstGeneratedAutoIncRowIdx , missingVals , nil
237+ return plan .NewProject (projExprs , insertSource ), firstGeneratedAutoIncRowIdx , deferredDefaults , nil
238238}
239239
240240// isZero returns true if the specified literal value |lit| has a value equal to 0.
0 commit comments