@@ -159,6 +159,7 @@ type idxScope struct {
159159 childScopes []* idxScope
160160 ids []sql.ColumnId
161161 columns []string
162+ addedColumns sql.Schema
162163 children []sql.Node
163164 expressions []sql.Expression
164165 checks sql.CheckConstraints
@@ -301,6 +302,7 @@ func (s *idxScope) copy() *idxScope {
301302 parentScopes : parentCopy ,
302303 columns : varsCopy ,
303304 ids : idsCopy ,
305+ addedColumns : s .addedColumns ,
304306 subqueryScope : s .subqueryScope ,
305307 triggerScope : s .triggerScope ,
306308 insertSourceScope : s .insertSourceScope ,
@@ -399,6 +401,9 @@ func (s *idxScope) visitChildren(n sql.Node) error {
399401 if err != nil {
400402 return err
401403 }
404+ if ac , ok := c .(* plan.AddColumn ); ok {
405+ s .addedColumns = append (s .addedColumns , ac .Column ())
406+ }
402407 s .childScopes = append (s .childScopes , cScope )
403408 s .children = append (s .children , newC )
404409 }
@@ -565,6 +570,11 @@ func (s *idxScope) visitSelf(n sql.Node) error {
565570 newDef := fixExprToScope (sql .Expression (col .Default ), scope )
566571 n .DestSch [colIdx ].Default = newDef .(* sql.ColumnDefaultValue )
567572 }
573+ case * plan.CreateCheck :
574+ addedScope := & idxScope {}
575+ addedScope .addSchema (s .addedColumns )
576+ scope := append (append (s .parentScopes , s .childScopes ... ), addedScope )
577+ s .expressions = append (s .expressions , fixExprToScope (n .Check .Expr , scope ... ))
568578 default :
569579 // Group By and Window functions already account for the new/old columns present from triggers
570580 // This means that when indexing the Projections, we should not include the trigger scope(s), which are
0 commit comments