github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/optbuilder/testdata/update (about)

     1  exec-ddl
     2  CREATE TABLE abcde (
     3      a INT NOT NULL,
     4      b INT,
     5      c INT DEFAULT (10),
     6      d INT AS (b + c + 1) STORED,
     7      e INT AS (a) STORED
     8  )
     9  ----
    10  
    11  exec-ddl
    12  CREATE TABLE xyz (
    13      x TEXT PRIMARY KEY,
    14      y INT8,
    15      z FLOAT8
    16  )
    17  ----
    18  
    19  exec-ddl
    20  CREATE TABLE uv (
    21      u DECIMAL,
    22      v BYTES
    23  )
    24  ----
    25  
    26  exec-ddl
    27  CREATE TABLE mutation (
    28      m INT PRIMARY KEY,
    29      n INT,
    30      "o:write-only" INT DEFAULT(10),
    31      "p:write-only" INT AS (o + n) STORED,
    32      "q:delete-only" INT AS (m * p) STORED,
    33      CHECK (m > 0)
    34  )
    35  ----
    36  
    37  exec-ddl
    38  CREATE TABLE checks (
    39      a INT PRIMARY KEY CHECK (a > 0),
    40      b INT,
    41      c INT,
    42      d INT AS (c + 1) STORED,
    43      CHECK (b < d)
    44  )
    45  ----
    46  
    47  exec-ddl
    48  CREATE TABLE decimals (
    49      a DECIMAL(10,0) PRIMARY KEY CHECK (round(a) = a),
    50      b DECIMAL(5,1)[] CHECK (b[0] > 1),
    51      c DECIMAL(10,1) DEFAULT (1.23),
    52      d DECIMAL(10,1) AS (a+c) STORED
    53  )
    54  ----
    55  
    56  # ------------------------------------------------------------------------------
    57  # Basic tests.
    58  # ------------------------------------------------------------------------------
    59  
    60  # Set single column.
    61  build
    62  UPDATE abcde SET a=2 WHERE a=1
    63  ----
    64  update abcde
    65   ├── columns: <none>
    66   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
    67   ├── update-mapping:
    68   │    ├── a_new:13 => a:1
    69   │    ├── column14:14 => d:4
    70   │    └── a_new:13 => e:5
    71   └── project
    72        ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13!null
    73        ├── project
    74        │    ├── columns: a_new:13!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
    75        │    ├── select
    76        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
    77        │    │    ├── scan abcde
    78        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
    79        │    │    │    └── computed column expressions
    80        │    │    │         ├── d:10
    81        │    │    │         │    └── (b:8 + c:9) + 1
    82        │    │    │         └── e:11
    83        │    │    │              └── a:7
    84        │    │    └── filters
    85        │    │         └── a:7 = 1
    86        │    └── projections
    87        │         └── 2 [as=a_new:13]
    88        └── projections
    89             └── (b:8 + c:9) + 1 [as=column14:14]
    90  
    91  # Set all non-computed columns.
    92  build
    93  UPDATE abcde SET a=1, b=2, c=3, rowid=4
    94  ----
    95  update abcde
    96   ├── columns: <none>
    97   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
    98   ├── update-mapping:
    99   │    ├── a_new:13 => a:1
   100   │    ├── b_new:14 => b:2
   101   │    ├── c_new:15 => c:3
   102   │    ├── column17:17 => d:4
   103   │    ├── a_new:13 => e:5
   104   │    └── rowid_new:16 => rowid:6
   105   └── project
   106        ├── columns: column17:17!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13!null b_new:14!null c_new:15!null rowid_new:16!null
   107        ├── project
   108        │    ├── columns: a_new:13!null b_new:14!null c_new:15!null rowid_new:16!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   109        │    ├── scan abcde
   110        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   111        │    │    └── computed column expressions
   112        │    │         ├── d:10
   113        │    │         │    └── (b:8 + c:9) + 1
   114        │    │         └── e:11
   115        │    │              └── a:7
   116        │    └── projections
   117        │         ├── 1 [as=a_new:13]
   118        │         ├── 2 [as=b_new:14]
   119        │         ├── 3 [as=c_new:15]
   120        │         └── 4 [as=rowid_new:16]
   121        └── projections
   122             └── (b_new:14 + c_new:15) + 1 [as=column17:17]
   123  
   124  # Set all non-computed columns in reverse order.
   125  build
   126  UPDATE abcde SET rowid=1, c=2, b=3, a=4
   127  ----
   128  update abcde
   129   ├── columns: <none>
   130   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   131   ├── update-mapping:
   132   │    ├── a_new:16 => a:1
   133   │    ├── b_new:15 => b:2
   134   │    ├── c_new:14 => c:3
   135   │    ├── column17:17 => d:4
   136   │    ├── a_new:16 => e:5
   137   │    └── rowid_new:13 => rowid:6
   138   └── project
   139        ├── columns: column17:17!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null rowid_new:13!null c_new:14!null b_new:15!null a_new:16!null
   140        ├── project
   141        │    ├── columns: rowid_new:13!null c_new:14!null b_new:15!null a_new:16!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   142        │    ├── scan abcde
   143        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   144        │    │    └── computed column expressions
   145        │    │         ├── d:10
   146        │    │         │    └── (b:8 + c:9) + 1
   147        │    │         └── e:11
   148        │    │              └── a:7
   149        │    └── projections
   150        │         ├── 1 [as=rowid_new:13]
   151        │         ├── 2 [as=c_new:14]
   152        │         ├── 3 [as=b_new:15]
   153        │         └── 4 [as=a_new:16]
   154        └── projections
   155             └── (b_new:15 + c_new:14) + 1 [as=column17:17]
   156  
   157  # Set all non-computed columns to NULL.
   158  build
   159  UPDATE abcde SET a=NULL, b=NULL, c=NULL, rowid=NULL
   160  ----
   161  update abcde
   162   ├── columns: <none>
   163   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   164   ├── update-mapping:
   165   │    ├── a_new:13 => a:1
   166   │    ├── a_new:13 => b:2
   167   │    ├── a_new:13 => c:3
   168   │    ├── column14:14 => d:4
   169   │    ├── a_new:13 => e:5
   170   │    └── a_new:13 => rowid:6
   171   └── project
   172        ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13
   173        ├── project
   174        │    ├── columns: a_new:13 a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   175        │    ├── scan abcde
   176        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   177        │    │    └── computed column expressions
   178        │    │         ├── d:10
   179        │    │         │    └── (b:8 + c:9) + 1
   180        │    │         └── e:11
   181        │    │              └── a:7
   182        │    └── projections
   183        │         └── NULL::INT8 [as=a_new:13]
   184        └── projections
   185             └── (a_new:13 + a_new:13) + 1 [as=column14:14]
   186  
   187  # Set columns using variable expressions.
   188  build
   189  UPDATE abcde SET a=a+1, b=b*c WHERE b>e
   190  ----
   191  update abcde
   192   ├── columns: <none>
   193   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   194   ├── update-mapping:
   195   │    ├── a_new:13 => a:1
   196   │    ├── b_new:14 => b:2
   197   │    ├── column15:15 => d:4
   198   │    └── a_new:13 => e:5
   199   └── project
   200        ├── columns: column15:15 a:7!null b:8!null c:9 d:10 e:11!null rowid:12!null a_new:13!null b_new:14
   201        ├── project
   202        │    ├── columns: a_new:13!null b_new:14 a:7!null b:8!null c:9 d:10 e:11!null rowid:12!null
   203        │    ├── select
   204        │    │    ├── columns: a:7!null b:8!null c:9 d:10 e:11!null rowid:12!null
   205        │    │    ├── scan abcde
   206        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   207        │    │    │    └── computed column expressions
   208        │    │    │         ├── d:10
   209        │    │    │         │    └── (b:8 + c:9) + 1
   210        │    │    │         └── e:11
   211        │    │    │              └── a:7
   212        │    │    └── filters
   213        │    │         └── b:8 > e:11
   214        │    └── projections
   215        │         ├── a:7 + 1 [as=a_new:13]
   216        │         └── b:8 * c:9 [as=b_new:14]
   217        └── projections
   218             └── (b_new:14 + c:9) + 1 [as=column15:15]
   219  
   220  # Set columns using aliased expressions.
   221  build
   222  UPDATE abcde AS foo SET a=foo.b, b=foo.c
   223  ----
   224  update foo
   225   ├── columns: <none>
   226   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   227   ├── update-mapping:
   228   │    ├── b:8 => a:1
   229   │    ├── c:9 => b:2
   230   │    ├── column13:13 => d:4
   231   │    └── b:8 => e:5
   232   └── project
   233        ├── columns: column13:13 a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   234        ├── scan foo
   235        │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   236        │    └── computed column expressions
   237        │         ├── d:10
   238        │         │    └── (b:8 + c:9) + 1
   239        │         └── e:11
   240        │              └── a:7
   241        └── projections
   242             └── (c:9 + c:9) + 1 [as=column13:13]
   243  
   244  # Use WHERE, ORDER BY, LIMIT.
   245  build
   246  UPDATE abcde SET b=1 WHERE a>0 ORDER BY a LIMIT 10
   247  ----
   248  update abcde
   249   ├── columns: <none>
   250   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   251   ├── update-mapping:
   252   │    ├── b_new:13 => b:2
   253   │    ├── column14:14 => d:4
   254   │    └── a:7 => e:5
   255   └── project
   256        ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null b_new:13!null
   257        ├── project
   258        │    ├── columns: b_new:13!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   259        │    ├── limit
   260        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   261        │    │    ├── internal-ordering: +7
   262        │    │    ├── sort
   263        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   264        │    │    │    ├── ordering: +7
   265        │    │    │    ├── limit hint: 10.00
   266        │    │    │    └── select
   267        │    │    │         ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   268        │    │    │         ├── scan abcde
   269        │    │    │         │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   270        │    │    │         │    └── computed column expressions
   271        │    │    │         │         ├── d:10
   272        │    │    │         │         │    └── (b:8 + c:9) + 1
   273        │    │    │         │         └── e:11
   274        │    │    │         │              └── a:7
   275        │    │    │         └── filters
   276        │    │    │              └── a:7 > 0
   277        │    │    └── 10
   278        │    └── projections
   279        │         └── 1 [as=b_new:13]
   280        └── projections
   281             └── (b_new:13 + c:9) + 1 [as=column14:14]
   282  
   283  # UPDATE with index hints.
   284  exec-ddl
   285  CREATE TABLE xyzw (
   286    x INT PRIMARY KEY,
   287    y INT,
   288    z INT,
   289    w INT,
   290    INDEX foo (z, y)
   291  )
   292  ----
   293  
   294  build
   295  UPDATE xyzw@primary SET x=2 WHERE z=1
   296  ----
   297  update xyzw
   298   ├── columns: <none>
   299   ├── fetch columns: x:5 y:6 z:7 w:8
   300   ├── update-mapping:
   301   │    └── x_new:9 => x:1
   302   └── project
   303        ├── columns: x_new:9!null x:5!null y:6 z:7!null w:8
   304        ├── select
   305        │    ├── columns: x:5!null y:6 z:7!null w:8
   306        │    ├── scan xyzw
   307        │    │    ├── columns: x:5!null y:6 z:7 w:8
   308        │    │    └── flags: force-index=primary
   309        │    └── filters
   310        │         └── z:7 = 1
   311        └── projections
   312             └── 2 [as=x_new:9]
   313  
   314  build
   315  UPDATE xyzw@foo SET x=2 WHERE z=1
   316  ----
   317  update xyzw
   318   ├── columns: <none>
   319   ├── fetch columns: x:5 y:6 z:7 w:8
   320   ├── update-mapping:
   321   │    └── x_new:9 => x:1
   322   └── project
   323        ├── columns: x_new:9!null x:5!null y:6 z:7!null w:8
   324        ├── select
   325        │    ├── columns: x:5!null y:6 z:7!null w:8
   326        │    ├── scan xyzw
   327        │    │    ├── columns: x:5!null y:6 z:7 w:8
   328        │    │    └── flags: force-index=foo
   329        │    └── filters
   330        │         └── z:7 = 1
   331        └── projections
   332             └── 2 [as=x_new:9]
   333  
   334  build
   335  UPDATE xyzw@{FORCE_INDEX=foo,ASC} SET x=2 WHERE z=1
   336  ----
   337  update xyzw
   338   ├── columns: <none>
   339   ├── fetch columns: x:5 y:6 z:7 w:8
   340   ├── update-mapping:
   341   │    └── x_new:9 => x:1
   342   └── project
   343        ├── columns: x_new:9!null x:5!null y:6 z:7!null w:8
   344        ├── select
   345        │    ├── columns: x:5!null y:6 z:7!null w:8
   346        │    ├── scan xyzw
   347        │    │    ├── columns: x:5!null y:6 z:7 w:8
   348        │    │    └── flags: force-index=foo,fwd
   349        │    └── filters
   350        │         └── z:7 = 1
   351        └── projections
   352             └── 2 [as=x_new:9]
   353  
   354  build
   355  UPDATE xyzw@{FORCE_INDEX=foo,DESC} SET x=2 WHERE z=1
   356  ----
   357  update xyzw
   358   ├── columns: <none>
   359   ├── fetch columns: x:5 y:6 z:7 w:8
   360   ├── update-mapping:
   361   │    └── x_new:9 => x:1
   362   └── project
   363        ├── columns: x_new:9!null x:5!null y:6 z:7!null w:8
   364        ├── select
   365        │    ├── columns: x:5!null y:6 z:7!null w:8
   366        │    ├── scan xyzw,rev
   367        │    │    ├── columns: x:5!null y:6 z:7 w:8
   368        │    │    └── flags: force-index=foo,rev
   369        │    └── filters
   370        │         └── z:7 = 1
   371        └── projections
   372             └── 2 [as=x_new:9]
   373  
   374  build
   375  UPDATE xyzw@{NO_INDEX_JOIN} SET x=2 WHERE z=1
   376  ----
   377  update xyzw
   378   ├── columns: <none>
   379   ├── fetch columns: x:5 y:6 z:7 w:8
   380   ├── update-mapping:
   381   │    └── x_new:9 => x:1
   382   └── project
   383        ├── columns: x_new:9!null x:5!null y:6 z:7!null w:8
   384        ├── select
   385        │    ├── columns: x:5!null y:6 z:7!null w:8
   386        │    ├── scan xyzw
   387        │    │    ├── columns: x:5!null y:6 z:7 w:8
   388        │    │    └── flags: no-index-join
   389        │    └── filters
   390        │         └── z:7 = 1
   391        └── projections
   392             └── 2 [as=x_new:9]
   393  
   394  build
   395  UPDATE xyzw@bad_idx SET x=2 WHERE z=1
   396  ----
   397  error: index "bad_idx" not found
   398  
   399  
   400  # Infer types.
   401  build
   402  UPDATE xyz SET y=1, z=1
   403  ----
   404  update xyz
   405   ├── columns: <none>
   406   ├── fetch columns: x:4 y:5 z:6
   407   ├── update-mapping:
   408   │    ├── y_new:7 => y:2
   409   │    └── z_new:8 => z:3
   410   └── project
   411        ├── columns: y_new:7!null z_new:8!null x:4!null y:5 z:6
   412        ├── scan xyz
   413        │    └── columns: x:4!null y:5 z:6
   414        └── projections
   415             ├── 1 [as=y_new:7]
   416             └── 1.0 [as=z_new:8]
   417  
   418  # Use placeholders.
   419  build
   420  UPDATE xyz SET x=$1, y=$2, z=$3
   421  ----
   422  update xyz
   423   ├── columns: <none>
   424   ├── fetch columns: x:4 y:5 z:6
   425   ├── update-mapping:
   426   │    ├── x_new:7 => x:1
   427   │    ├── y_new:8 => y:2
   428   │    └── z_new:9 => z:3
   429   └── project
   430        ├── columns: x_new:7 y_new:8 z_new:9 x:4!null y:5 z:6
   431        ├── scan xyz
   432        │    └── columns: x:4!null y:5 z:6
   433        └── projections
   434             ├── $1 [as=x_new:7]
   435             ├── $2 [as=y_new:8]
   436             └── $3 [as=z_new:9]
   437  
   438  # Duplicate expressions with placeholders.
   439  build
   440  UPDATE abcde SET a=$1 + 1, b=$1 + 1 WHERE c=10
   441  ----
   442  update abcde
   443   ├── columns: <none>
   444   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   445   ├── update-mapping:
   446   │    ├── a_new:13 => a:1
   447   │    ├── a_new:13 => b:2
   448   │    ├── column14:14 => d:4
   449   │    └── a_new:13 => e:5
   450   └── project
   451        ├── columns: column14:14 a:7!null b:8 c:9!null d:10 e:11 rowid:12!null a_new:13
   452        ├── project
   453        │    ├── columns: a_new:13 a:7!null b:8 c:9!null d:10 e:11 rowid:12!null
   454        │    ├── select
   455        │    │    ├── columns: a:7!null b:8 c:9!null d:10 e:11 rowid:12!null
   456        │    │    ├── scan abcde
   457        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   458        │    │    │    └── computed column expressions
   459        │    │    │         ├── d:10
   460        │    │    │         │    └── (b:8 + c:9) + 1
   461        │    │    │         └── e:11
   462        │    │    │              └── a:7
   463        │    │    └── filters
   464        │    │         └── c:9 = 10
   465        │    └── projections
   466        │         └── $1 + 1 [as=a_new:13]
   467        └── projections
   468             └── (a_new:13 + c:9) + 1 [as=column14:14]
   469  
   470  
   471  # Unknown target table.
   472  build
   473  UPDATE unknown SET x=1
   474  ----
   475  error (42P01): no data source matches prefix: "unknown"
   476  
   477  # Unknown target column.
   478  build
   479  UPDATE abcde SET f=1
   480  ----
   481  error (42703): column "f" does not exist
   482  
   483  # Test SET type checking.
   484  build
   485  UPDATE xyz SET x=1, y=1, z=1
   486  ----
   487  error (42804): value type int doesn't match type string of column "x"
   488  
   489  # Try to use non-returning UPDATE as expression.
   490  build
   491  SELECT * FROM [UPDATE abcde SET a=1]
   492  ----
   493  error (42703): statement source "UPDATE abcde SET a = 1" does not return any columns
   494  
   495  # Non-referenced CTE with mutation.
   496  build
   497  WITH cte AS (SELECT b FROM [UPDATE abcde SET a=b RETURNING *]) UPDATE abcde SET a=b
   498  ----
   499  with &1
   500   ├── project
   501   │    ├── columns: abcde.a:1!null abcde.b:2 abcde.c:3 abcde.d:4 abcde.e:5
   502   │    └── update abcde
   503   │         ├── columns: abcde.a:1!null abcde.b:2 abcde.c:3 abcde.d:4 abcde.e:5 rowid:6!null
   504   │         ├── fetch columns: abcde.a:7 abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12
   505   │         ├── update-mapping:
   506   │         │    ├── abcde.b:8 => abcde.a:1
   507   │         │    ├── column13:13 => abcde.d:4
   508   │         │    └── abcde.b:8 => abcde.e:5
   509   │         └── project
   510   │              ├── columns: column13:13 abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   511   │              ├── scan abcde
   512   │              │    ├── columns: abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   513   │              │    └── computed column expressions
   514   │              │         ├── abcde.d:10
   515   │              │         │    └── (abcde.b:8 + abcde.c:9) + 1
   516   │              │         └── abcde.e:11
   517   │              │              └── abcde.a:7
   518   │              └── projections
   519   │                   └── (abcde.b:8 + abcde.c:9) + 1 [as=column13:13]
   520   └── with &2 (cte)
   521        ├── project
   522        │    ├── columns: b:15
   523        │    └── with-scan &1
   524        │         ├── columns: a:14!null b:15 c:16 d:17 e:18
   525        │         └── mapping:
   526        │              ├──  abcde.a:1 => a:14
   527        │              ├──  abcde.b:2 => b:15
   528        │              ├──  abcde.c:3 => c:16
   529        │              ├──  abcde.d:4 => d:17
   530        │              └──  abcde.e:5 => e:18
   531        └── update abcde
   532             ├── columns: <none>
   533             ├── fetch columns: abcde.a:25 abcde.b:26 abcde.c:27 abcde.d:28 abcde.e:29 rowid:30
   534             ├── update-mapping:
   535             │    ├── abcde.b:26 => abcde.a:19
   536             │    ├── column31:31 => abcde.d:22
   537             │    └── abcde.b:26 => abcde.e:23
   538             └── project
   539                  ├── columns: column31:31 abcde.a:25!null abcde.b:26 abcde.c:27 abcde.d:28 abcde.e:29 rowid:30!null
   540                  ├── scan abcde
   541                  │    ├── columns: abcde.a:25!null abcde.b:26 abcde.c:27 abcde.d:28 abcde.e:29 rowid:30!null
   542                  │    └── computed column expressions
   543                  │         ├── abcde.d:28
   544                  │         │    └── (abcde.b:26 + abcde.c:27) + 1
   545                  │         └── abcde.e:29
   546                  │              └── abcde.a:25
   547                  └── projections
   548                       └── (abcde.b:26 + abcde.c:27) + 1 [as=column31:31]
   549  
   550  # With alias, original table name should be inaccessible.
   551  build
   552  UPDATE abcde AS foo SET a=abcde.b
   553  ----
   554  error (42P01): no data source matches prefix: abcde
   555  
   556  # ORDER BY can only be used with LIMIT.
   557  build
   558  UPDATE abcde SET b=1 ORDER BY c
   559  ----
   560  error (42601): UPDATE statement requires LIMIT when ORDER BY is used
   561  
   562  # ------------------------------------------------------------------------------
   563  # Test RETURNING.
   564  # ------------------------------------------------------------------------------
   565  
   566  # Return values from update.
   567  build
   568  UPDATE abcde SET a=2 WHERE a=1 RETURNING *
   569  ----
   570  project
   571   ├── columns: a:1!null b:2 c:3 d:4 e:5!null
   572   └── update abcde
   573        ├── columns: a:1!null b:2 c:3 d:4 e:5!null rowid:6!null
   574        ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   575        ├── update-mapping:
   576        │    ├── a_new:13 => a:1
   577        │    ├── column14:14 => d:4
   578        │    └── a_new:13 => e:5
   579        └── project
   580             ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13!null
   581             ├── project
   582             │    ├── columns: a_new:13!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   583             │    ├── select
   584             │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   585             │    │    ├── scan abcde
   586             │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   587             │    │    │    └── computed column expressions
   588             │    │    │         ├── d:10
   589             │    │    │         │    └── (b:8 + c:9) + 1
   590             │    │    │         └── e:11
   591             │    │    │              └── a:7
   592             │    │    └── filters
   593             │    │         └── a:7 = 1
   594             │    └── projections
   595             │         └── 2 [as=a_new:13]
   596             └── projections
   597                  └── (b:8 + c:9) + 1 [as=column14:14]
   598  
   599  # Return values from aliased table.
   600  build
   601  UPDATE abcde AS foo SET a=2 WHERE a=1 RETURNING foo.a+1, foo.b * foo.d
   602  ----
   603  project
   604   ├── columns: "?column?":15!null "?column?":16
   605   ├── update foo
   606   │    ├── columns: a:1!null b:2 c:3 d:4 e:5!null rowid:6!null
   607   │    ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   608   │    ├── update-mapping:
   609   │    │    ├── a_new:13 => a:1
   610   │    │    ├── column14:14 => d:4
   611   │    │    └── a_new:13 => e:5
   612   │    └── project
   613   │         ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13!null
   614   │         ├── project
   615   │         │    ├── columns: a_new:13!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   616   │         │    ├── select
   617   │         │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   618   │         │    │    ├── scan foo
   619   │         │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   620   │         │    │    │    └── computed column expressions
   621   │         │    │    │         ├── d:10
   622   │         │    │    │         │    └── (b:8 + c:9) + 1
   623   │         │    │    │         └── e:11
   624   │         │    │    │              └── a:7
   625   │         │    │    └── filters
   626   │         │    │         └── a:7 = 1
   627   │         │    └── projections
   628   │         │         └── 2 [as=a_new:13]
   629   │         └── projections
   630   │              └── (b:8 + c:9) + 1 [as=column14:14]
   631   └── projections
   632        ├── a:1 + 1 [as="?column?":15]
   633        └── b:2 * d:4 [as="?column?":16]
   634  
   635  # Use returning UPDATE as a FROM expression.
   636  build
   637  SELECT a, d FROM [UPDATE abcde SET a=2 WHERE a>0 ORDER BY b LIMIT 10 RETURNING *]
   638  ----
   639  with &1
   640   ├── columns: a:15!null d:18
   641   ├── project
   642   │    ├── columns: abcde.a:1!null abcde.b:2 abcde.c:3 abcde.d:4 abcde.e:5!null
   643   │    └── update abcde
   644   │         ├── columns: abcde.a:1!null abcde.b:2 abcde.c:3 abcde.d:4 abcde.e:5!null rowid:6!null
   645   │         ├── fetch columns: abcde.a:7 abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12
   646   │         ├── update-mapping:
   647   │         │    ├── a_new:13 => abcde.a:1
   648   │         │    ├── column14:14 => abcde.d:4
   649   │         │    └── a_new:13 => abcde.e:5
   650   │         └── project
   651   │              ├── columns: column14:14 abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null a_new:13!null
   652   │              ├── project
   653   │              │    ├── columns: a_new:13!null abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   654   │              │    ├── limit
   655   │              │    │    ├── columns: abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   656   │              │    │    ├── internal-ordering: +8
   657   │              │    │    ├── sort
   658   │              │    │    │    ├── columns: abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   659   │              │    │    │    ├── ordering: +8
   660   │              │    │    │    ├── limit hint: 10.00
   661   │              │    │    │    └── select
   662   │              │    │    │         ├── columns: abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   663   │              │    │    │         ├── scan abcde
   664   │              │    │    │         │    ├── columns: abcde.a:7!null abcde.b:8 abcde.c:9 abcde.d:10 abcde.e:11 rowid:12!null
   665   │              │    │    │         │    └── computed column expressions
   666   │              │    │    │         │         ├── abcde.d:10
   667   │              │    │    │         │         │    └── (abcde.b:8 + abcde.c:9) + 1
   668   │              │    │    │         │         └── abcde.e:11
   669   │              │    │    │         │              └── abcde.a:7
   670   │              │    │    │         └── filters
   671   │              │    │    │              └── abcde.a:7 > 0
   672   │              │    │    └── 10
   673   │              │    └── projections
   674   │              │         └── 2 [as=a_new:13]
   675   │              └── projections
   676   │                   └── (abcde.b:8 + abcde.c:9) + 1 [as=column14:14]
   677   └── project
   678        ├── columns: a:15!null d:18
   679        └── with-scan &1
   680             ├── columns: a:15!null b:16 c:17 d:18 e:19!null
   681             └── mapping:
   682                  ├──  abcde.a:1 => a:15
   683                  ├──  abcde.b:2 => b:16
   684                  ├──  abcde.c:3 => c:17
   685                  ├──  abcde.d:4 => d:18
   686                  └──  abcde.e:5 => e:19
   687  
   688  # Return hidden column.
   689  build
   690  UPDATE abcde SET rowid=rowid+1 RETURNING rowid
   691  ----
   692  project
   693   ├── columns: rowid:6!null
   694   └── update abcde
   695        ├── columns: a:1!null b:2 c:3 d:4 e:5!null rowid:6!null
   696        ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   697        ├── update-mapping:
   698        │    ├── column14:14 => d:4
   699        │    ├── a:7 => e:5
   700        │    └── rowid_new:13 => rowid:6
   701        └── project
   702             ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null rowid_new:13!null
   703             ├── project
   704             │    ├── columns: rowid_new:13!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   705             │    ├── scan abcde
   706             │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   707             │    │    └── computed column expressions
   708             │    │         ├── d:10
   709             │    │         │    └── (b:8 + c:9) + 1
   710             │    │         └── e:11
   711             │    │              └── a:7
   712             │    └── projections
   713             │         └── rowid:12 + 1 [as=rowid_new:13]
   714             └── projections
   715                  └── (b:8 + c:9) + 1 [as=column14:14]
   716  
   717  # Try to use aggregate function in RETURNING clause.
   718  build
   719  UPDATE abcde SET b=1 RETURNING sum(a)
   720  ----
   721  error (42803): sum(): aggregate functions are not allowed in RETURNING
   722  
   723  # Try to use SRF in RETURNING clause.
   724  build
   725  UPDATE abcde SET c=1 RETURNING generate_series(1, 10)
   726  ----
   727  error (0A000): generate_series(): generator functions are not allowed in RETURNING
   728  
   729  # ------------------------------------------------------------------------------
   730  # Test DEFAULT values.
   731  # ------------------------------------------------------------------------------
   732  
   733  # Use DEFAULT expressions in RHS of SET expressions.
   734  build
   735  UPDATE abcde SET b=DEFAULT, c=DEFAULT
   736  ----
   737  update abcde
   738   ├── columns: <none>
   739   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   740   ├── update-mapping:
   741   │    ├── b_new:13 => b:2
   742   │    ├── c_new:14 => c:3
   743   │    ├── column15:15 => d:4
   744   │    └── a:7 => e:5
   745   └── project
   746        ├── columns: column15:15 a:7!null b:8 c:9 d:10 e:11 rowid:12!null b_new:13 c_new:14!null
   747        ├── project
   748        │    ├── columns: b_new:13 c_new:14!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   749        │    ├── scan abcde
   750        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   751        │    │    └── computed column expressions
   752        │    │         ├── d:10
   753        │    │         │    └── (b:8 + c:9) + 1
   754        │    │         └── e:11
   755        │    │              └── a:7
   756        │    └── projections
   757        │         ├── NULL::INT8 [as=b_new:13]
   758        │         └── 10 [as=c_new:14]
   759        └── projections
   760             └── (b_new:13 + c_new:14) + 1 [as=column15:15]
   761  
   762  # Allow not-null column to be updated with NULL DEFAULT value (would fail at
   763  # runtime if there are any rows to update).
   764  build
   765  UPDATE abcde SET a=DEFAULT
   766  ----
   767  update abcde
   768   ├── columns: <none>
   769   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   770   ├── update-mapping:
   771   │    ├── a_new:13 => a:1
   772   │    ├── column14:14 => d:4
   773   │    └── a_new:13 => e:5
   774   └── project
   775        ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13
   776        ├── project
   777        │    ├── columns: a_new:13 a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   778        │    ├── scan abcde
   779        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   780        │    │    └── computed column expressions
   781        │    │         ├── d:10
   782        │    │         │    └── (b:8 + c:9) + 1
   783        │    │         └── e:11
   784        │    │              └── a:7
   785        │    └── projections
   786        │         └── NULL::INT8 [as=a_new:13]
   787        └── projections
   788             └── (b:8 + c:9) + 1 [as=column14:14]
   789  
   790  build
   791  UPDATE abcde SET c=1+DEFAULT
   792  ----
   793  error (42601): DEFAULT can only appear in a VALUES list within INSERT or on the right side of a SET
   794  
   795  # ------------------------------------------------------------------------------
   796  # Test tuples.
   797  # ------------------------------------------------------------------------------
   798  
   799  build
   800  UPDATE abcde SET (a, b, c) = (1, 2, 3)
   801  ----
   802  update abcde
   803   ├── columns: <none>
   804   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   805   ├── update-mapping:
   806   │    ├── a_new:13 => a:1
   807   │    ├── b_new:14 => b:2
   808   │    ├── c_new:15 => c:3
   809   │    ├── column16:16 => d:4
   810   │    └── a_new:13 => e:5
   811   └── project
   812        ├── columns: column16:16!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13!null b_new:14!null c_new:15!null
   813        ├── project
   814        │    ├── columns: a_new:13!null b_new:14!null c_new:15!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   815        │    ├── scan abcde
   816        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   817        │    │    └── computed column expressions
   818        │    │         ├── d:10
   819        │    │         │    └── (b:8 + c:9) + 1
   820        │    │         └── e:11
   821        │    │              └── a:7
   822        │    └── projections
   823        │         ├── 1 [as=a_new:13]
   824        │         ├── 2 [as=b_new:14]
   825        │         └── 3 [as=c_new:15]
   826        └── projections
   827             └── (b_new:14 + c_new:15) + 1 [as=column16:16]
   828  
   829  build
   830  UPDATE abcde SET (c) = (NULL), (b, a) = (1, 2)
   831  ----
   832  update abcde
   833   ├── columns: <none>
   834   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   835   ├── update-mapping:
   836   │    ├── a_new:15 => a:1
   837   │    ├── b_new:14 => b:2
   838   │    ├── c_new:13 => c:3
   839   │    ├── column16:16 => d:4
   840   │    └── a_new:15 => e:5
   841   └── project
   842        ├── columns: column16:16 a:7!null b:8 c:9 d:10 e:11 rowid:12!null c_new:13 b_new:14!null a_new:15!null
   843        ├── project
   844        │    ├── columns: c_new:13 b_new:14!null a_new:15!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   845        │    ├── scan abcde
   846        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   847        │    │    └── computed column expressions
   848        │    │         ├── d:10
   849        │    │         │    └── (b:8 + c:9) + 1
   850        │    │         └── e:11
   851        │    │              └── a:7
   852        │    └── projections
   853        │         ├── NULL::INT8 [as=c_new:13]
   854        │         ├── 1 [as=b_new:14]
   855        │         └── 2 [as=a_new:15]
   856        └── projections
   857             └── (b_new:14 + c_new:13) + 1 [as=column16:16]
   858  
   859  # Tuples + DEFAULT.
   860  build
   861  UPDATE abcde SET (b, c)=(DEFAULT, DEFAULT)
   862  ----
   863  update abcde
   864   ├── columns: <none>
   865   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   866   ├── update-mapping:
   867   │    ├── b_new:13 => b:2
   868   │    ├── c_new:14 => c:3
   869   │    ├── column15:15 => d:4
   870   │    └── a:7 => e:5
   871   └── project
   872        ├── columns: column15:15 a:7!null b:8 c:9 d:10 e:11 rowid:12!null b_new:13 c_new:14!null
   873        ├── project
   874        │    ├── columns: b_new:13 c_new:14!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   875        │    ├── scan abcde
   876        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   877        │    │    └── computed column expressions
   878        │    │         ├── d:10
   879        │    │         │    └── (b:8 + c:9) + 1
   880        │    │         └── e:11
   881        │    │              └── a:7
   882        │    └── projections
   883        │         ├── NULL::INT8 [as=b_new:13]
   884        │         └── 10 [as=c_new:14]
   885        └── projections
   886             └── (b_new:13 + c_new:14) + 1 [as=column15:15]
   887  
   888  # Tuples + non-null DEFAULT.
   889  build
   890  UPDATE abcde SET (a, b)=(DEFAULT, DEFAULT)
   891  ----
   892  update abcde
   893   ├── columns: <none>
   894   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   895   ├── update-mapping:
   896   │    ├── a_new:13 => a:1
   897   │    ├── a_new:13 => b:2
   898   │    ├── column14:14 => d:4
   899   │    └── a_new:13 => e:5
   900   └── project
   901        ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null a_new:13
   902        ├── project
   903        │    ├── columns: a_new:13 a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   904        │    ├── scan abcde
   905        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   906        │    │    └── computed column expressions
   907        │    │         ├── d:10
   908        │    │         │    └── (b:8 + c:9) + 1
   909        │    │         └── e:11
   910        │    │              └── a:7
   911        │    └── projections
   912        │         └── NULL::INT8 [as=a_new:13]
   913        └── projections
   914             └── (a_new:13 + c:9) + 1 [as=column14:14]
   915  
   916  build
   917  UPDATE abcde SET (a, b)=(1, 2, 3)
   918  ----
   919  error (42601): number of columns (2) does not match number of values (3)
   920  
   921  build
   922  UPDATE abcde SET (a, b, a)=(1, 2, 3)
   923  ----
   924  error (42601): multiple assignments to the same column "a"
   925  
   926  build
   927  UPDATE abcde SET (a, unk)=(1, 2)
   928  ----
   929  error (42703): column "unk" does not exist
   930  
   931  build
   932  UPDATE abcde SET (a, d)=(1, 2)
   933  ----
   934  error (55000): cannot write directly to computed column "d"
   935  
   936  # ------------------------------------------------------------------------------
   937  # Test subqueries.
   938  # ------------------------------------------------------------------------------
   939  
   940  # Update single column.
   941  build
   942  UPDATE abcde SET (a)=(SELECT 1 AS one)
   943  ----
   944  update abcde
   945   ├── columns: <none>
   946   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   947   ├── update-mapping:
   948   │    ├── one:13 => a:1
   949   │    ├── column14:14 => d:4
   950   │    └── one:13 => e:5
   951   └── project
   952        ├── columns: column14:14 a:7!null b:8 c:9 d:10 e:11 rowid:12!null one:13
   953        ├── left-join-apply
   954        │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null one:13
   955        │    ├── scan abcde
   956        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   957        │    │    └── computed column expressions
   958        │    │         ├── d:10
   959        │    │         │    └── (b:8 + c:9) + 1
   960        │    │         └── e:11
   961        │    │              └── a:7
   962        │    ├── max1-row
   963        │    │    ├── columns: one:13!null
   964        │    │    └── project
   965        │    │         ├── columns: one:13!null
   966        │    │         ├── values
   967        │    │         │    └── ()
   968        │    │         └── projections
   969        │    │              └── 1 [as=one:13]
   970        │    └── filters (true)
   971        └── projections
   972             └── (b:8 + c:9) + 1 [as=column14:14]
   973  
   974  # Update all updatable columns.
   975  build
   976  UPDATE abcde SET (a, b, c, rowid)=(SELECT x::int, y, z::int, y+1 AS y1 FROM xyz)
   977  ----
   978  update abcde
   979   ├── columns: <none>
   980   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
   981   ├── update-mapping:
   982   │    ├── x:16 => a:1
   983   │    ├── y:14 => b:2
   984   │    ├── z:17 => c:3
   985   │    ├── column19:19 => d:4
   986   │    ├── x:16 => e:5
   987   │    └── y1:18 => rowid:6
   988   └── project
   989        ├── columns: column19:19 a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 x:16 z:17 y1:18
   990        ├── left-join-apply
   991        │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 x:16 z:17 y1:18
   992        │    ├── scan abcde
   993        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
   994        │    │    └── computed column expressions
   995        │    │         ├── d:10
   996        │    │         │    └── (b:8 + c:9) + 1
   997        │    │         └── e:11
   998        │    │              └── a:7
   999        │    ├── max1-row
  1000        │    │    ├── columns: y:14 x:16!null z:17 y1:18
  1001        │    │    └── project
  1002        │    │         ├── columns: x:16!null z:17 y1:18 y:14
  1003        │    │         ├── scan xyz
  1004        │    │         │    └── columns: xyz.x:13!null y:14 xyz.z:15
  1005        │    │         └── projections
  1006        │    │              ├── xyz.x:13::INT8 [as=x:16]
  1007        │    │              ├── xyz.z:15::INT8 [as=z:17]
  1008        │    │              └── y:14 + 1 [as=y1:18]
  1009        │    └── filters (true)
  1010        └── projections
  1011             └── (y:14 + z:17) + 1 [as=column19:19]
  1012  
  1013  # Update using combination of subquery and tuple SET expressions.
  1014  build
  1015  UPDATE abcde SET (a, b)=(SELECT y, y+1 AS y1 FROM xyz), (c, rowid)=(1, 2)
  1016  ----
  1017  update abcde
  1018   ├── columns: <none>
  1019   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
  1020   ├── update-mapping:
  1021   │    ├── y:14 => a:1
  1022   │    ├── y1:16 => b:2
  1023   │    ├── c_new:17 => c:3
  1024   │    ├── column19:19 => d:4
  1025   │    ├── y:14 => e:5
  1026   │    └── rowid_new:18 => rowid:6
  1027   └── project
  1028        ├── columns: column19:19 a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16 c_new:17!null rowid_new:18!null
  1029        ├── project
  1030        │    ├── columns: c_new:17!null rowid_new:18!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16
  1031        │    ├── left-join-apply
  1032        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16
  1033        │    │    ├── scan abcde
  1034        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
  1035        │    │    │    └── computed column expressions
  1036        │    │    │         ├── d:10
  1037        │    │    │         │    └── (b:8 + c:9) + 1
  1038        │    │    │         └── e:11
  1039        │    │    │              └── a:7
  1040        │    │    ├── max1-row
  1041        │    │    │    ├── columns: y:14 y1:16
  1042        │    │    │    └── project
  1043        │    │    │         ├── columns: y1:16 y:14
  1044        │    │    │         ├── scan xyz
  1045        │    │    │         │    └── columns: x:13!null y:14 z:15
  1046        │    │    │         └── projections
  1047        │    │    │              └── y:14 + 1 [as=y1:16]
  1048        │    │    └── filters (true)
  1049        │    └── projections
  1050        │         ├── 1 [as=c_new:17]
  1051        │         └── 2 [as=rowid_new:18]
  1052        └── projections
  1053             └── (y1:16 + c_new:17) + 1 [as=column19:19]
  1054  
  1055  # Use subquery SET expression after other expressions.
  1056  build
  1057  UPDATE abcde SET a=1, (b)=(2), (c, rowid)=(SELECT y, y+1 AS y1 FROM xyz)
  1058  ----
  1059  update abcde
  1060   ├── columns: <none>
  1061   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
  1062   ├── update-mapping:
  1063   │    ├── a_new:17 => a:1
  1064   │    ├── b_new:18 => b:2
  1065   │    ├── y:14 => c:3
  1066   │    ├── column19:19 => d:4
  1067   │    ├── a_new:17 => e:5
  1068   │    └── y1:16 => rowid:6
  1069   └── project
  1070        ├── columns: column19:19 a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16 a_new:17!null b_new:18!null
  1071        ├── project
  1072        │    ├── columns: a_new:17!null b_new:18!null a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16
  1073        │    ├── left-join-apply
  1074        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16
  1075        │    │    ├── scan abcde
  1076        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
  1077        │    │    │    └── computed column expressions
  1078        │    │    │         ├── d:10
  1079        │    │    │         │    └── (b:8 + c:9) + 1
  1080        │    │    │         └── e:11
  1081        │    │    │              └── a:7
  1082        │    │    ├── max1-row
  1083        │    │    │    ├── columns: y:14 y1:16
  1084        │    │    │    └── project
  1085        │    │    │         ├── columns: y1:16 y:14
  1086        │    │    │         ├── scan xyz
  1087        │    │    │         │    └── columns: x:13!null y:14 z:15
  1088        │    │    │         └── projections
  1089        │    │    │              └── y:14 + 1 [as=y1:16]
  1090        │    │    └── filters (true)
  1091        │    └── projections
  1092        │         ├── 1 [as=a_new:17]
  1093        │         └── 2 [as=b_new:18]
  1094        └── projections
  1095             └── (b_new:18 + y:14) + 1 [as=column19:19]
  1096  
  1097  # Multiple subqueries in SET expressions.
  1098  build
  1099  UPDATE abcde SET (b, a)=(SELECT y, y+1 AS y1 FROM xyz), (c, rowid)=(SELECT 1 AS one, 2 AS two)
  1100  ----
  1101  update abcde
  1102   ├── columns: <none>
  1103   ├── fetch columns: a:7 b:8 c:9 d:10 e:11 rowid:12
  1104   ├── update-mapping:
  1105   │    ├── y1:16 => a:1
  1106   │    ├── y:14 => b:2
  1107   │    ├── one:17 => c:3
  1108   │    ├── column19:19 => d:4
  1109   │    ├── y1:16 => e:5
  1110   │    └── two:18 => rowid:6
  1111   └── project
  1112        ├── columns: column19:19 a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16 one:17 two:18
  1113        ├── left-join-apply
  1114        │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16 one:17 two:18
  1115        │    ├── left-join-apply
  1116        │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null y:14 y1:16
  1117        │    │    ├── scan abcde
  1118        │    │    │    ├── columns: a:7!null b:8 c:9 d:10 e:11 rowid:12!null
  1119        │    │    │    └── computed column expressions
  1120        │    │    │         ├── d:10
  1121        │    │    │         │    └── (b:8 + c:9) + 1
  1122        │    │    │         └── e:11
  1123        │    │    │              └── a:7
  1124        │    │    ├── max1-row
  1125        │    │    │    ├── columns: y:14 y1:16
  1126        │    │    │    └── project
  1127        │    │    │         ├── columns: y1:16 y:14
  1128        │    │    │         ├── scan xyz
  1129        │    │    │         │    └── columns: x:13!null y:14 z:15
  1130        │    │    │         └── projections
  1131        │    │    │              └── y:14 + 1 [as=y1:16]
  1132        │    │    └── filters (true)
  1133        │    ├── max1-row
  1134        │    │    ├── columns: one:17!null two:18!null
  1135        │    │    └── project
  1136        │    │         ├── columns: one:17!null two:18!null
  1137        │    │         ├── values
  1138        │    │         │    └── ()
  1139        │    │         └── projections
  1140        │    │              ├── 1 [as=one:17]
  1141        │    │              └── 2 [as=two:18]
  1142        │    └── filters (true)
  1143        └── projections
  1144             └── (y:14 + one:17) + 1 [as=column19:19]
  1145  
  1146  # Incorporate desired types when compiling subquery.
  1147  build
  1148  UPDATE xyz SET x='foo', (z, y)=(SELECT 2 AS two, 3 AS three)
  1149  ----
  1150  update xyz
  1151   ├── columns: <none>
  1152   ├── fetch columns: x:4 y:5 z:6
  1153   ├── update-mapping:
  1154   │    ├── x_new:9 => x:1
  1155   │    ├── three:8 => y:2
  1156   │    └── two:7 => z:3
  1157   └── project
  1158        ├── columns: x_new:9!null x:4!null y:5 z:6 two:7 three:8
  1159        ├── left-join-apply
  1160        │    ├── columns: x:4!null y:5 z:6 two:7 three:8
  1161        │    ├── scan xyz
  1162        │    │    └── columns: x:4!null y:5 z:6
  1163        │    ├── max1-row
  1164        │    │    ├── columns: two:7!null three:8!null
  1165        │    │    └── project
  1166        │    │         ├── columns: two:7!null three:8!null
  1167        │    │         ├── values
  1168        │    │         │    └── ()
  1169        │    │         └── projections
  1170        │    │              ├── 2.0 [as=two:7]
  1171        │    │              └── 3 [as=three:8]
  1172        │    └── filters (true)
  1173        └── projections
  1174             └── 'foo' [as=x_new:9]
  1175  
  1176  # SET expression contains correlated subquery + alias.
  1177  build
  1178  UPDATE abcde AS abcde1 SET b=(SELECT b FROM abcde AS abcde2 WHERE abcde2.rowid=abcde1.a) RETURNING *
  1179  ----
  1180  project
  1181   ├── columns: a:1!null b:2 c:3 d:4 e:5!null
  1182   └── update abcde1
  1183        ├── columns: abcde1.a:1!null abcde1.b:2 abcde1.c:3 abcde1.d:4 abcde1.e:5!null abcde1.rowid:6!null
  1184        ├── fetch columns: abcde1.a:7 abcde1.b:8 abcde1.c:9 abcde1.d:10 abcde1.e:11 abcde1.rowid:12
  1185        ├── update-mapping:
  1186        │    ├── b_new:19 => abcde1.b:2
  1187        │    ├── column20:20 => abcde1.d:4
  1188        │    └── abcde1.a:7 => abcde1.e:5
  1189        └── project
  1190             ├── columns: column20:20 abcde1.a:7!null abcde1.b:8 abcde1.c:9 abcde1.d:10 abcde1.e:11 abcde1.rowid:12!null b_new:19
  1191             ├── project
  1192             │    ├── columns: b_new:19 abcde1.a:7!null abcde1.b:8 abcde1.c:9 abcde1.d:10 abcde1.e:11 abcde1.rowid:12!null
  1193             │    ├── scan abcde1
  1194             │    │    ├── columns: abcde1.a:7!null abcde1.b:8 abcde1.c:9 abcde1.d:10 abcde1.e:11 abcde1.rowid:12!null
  1195             │    │    └── computed column expressions
  1196             │    │         ├── abcde1.d:10
  1197             │    │         │    └── (abcde1.b:8 + abcde1.c:9) + 1
  1198             │    │         └── abcde1.e:11
  1199             │    │              └── abcde1.a:7
  1200             │    └── projections
  1201             │         └── subquery [as=b_new:19]
  1202             │              └── max1-row
  1203             │                   ├── columns: abcde2.b:14
  1204             │                   └── project
  1205             │                        ├── columns: abcde2.b:14
  1206             │                        └── select
  1207             │                             ├── columns: abcde2.a:13!null abcde2.b:14 abcde2.c:15 abcde2.d:16 abcde2.e:17 abcde2.rowid:18!null
  1208             │                             ├── scan abcde2
  1209             │                             │    ├── columns: abcde2.a:13!null abcde2.b:14 abcde2.c:15 abcde2.d:16 abcde2.e:17 abcde2.rowid:18!null
  1210             │                             │    └── computed column expressions
  1211             │                             │         ├── abcde2.d:16
  1212             │                             │         │    └── (abcde2.b:14 + abcde2.c:15) + 1
  1213             │                             │         └── abcde2.e:17
  1214             │                             │              └── abcde2.a:13
  1215             │                             └── filters
  1216             │                                  └── abcde2.rowid:18 = abcde1.a:7
  1217             └── projections
  1218                  └── (b_new:19 + abcde1.c:9) + 1 [as=column20:20]
  1219  
  1220  # Too many values.
  1221  build
  1222  UPDATE abcde SET (a, b)=(SELECT y, y+1 AS y1, y+2 AS y2 FROM xyz)
  1223  ----
  1224  error (42601): number of columns (2) does not match number of values (3)
  1225  
  1226  # Too few values.
  1227  build
  1228  UPDATE abcde SET (a, b, c)=(SELECT y, y+1 AS y1 FROM xyz)
  1229  ----
  1230  error (42601): number of columns (3) does not match number of values (2)
  1231  
  1232  # Try to update same column.
  1233  build
  1234  UPDATE abcde SET (a, b)=(1, 2), (c, b)=(SELECT y, y+1 AS y1 FROM xyz)
  1235  ----
  1236  error (42601): multiple assignments to the same column "b"
  1237  
  1238  # Target type does not match subquery result.
  1239  build
  1240  UPDATE xyz SET (x, y)=(SELECT a, b FROM abcde WHERE a>0)
  1241  ----
  1242  error (42804): value type int doesn't match type string of column "x"
  1243  
  1244  # ------------------------------------------------------------------------------
  1245  # Test CTEs.
  1246  # ------------------------------------------------------------------------------
  1247  
  1248  # Use CTE within WHERE clause.
  1249  build
  1250  WITH cte AS (SELECT x FROM xyz) UPDATE abcde SET a=b WHERE EXISTS(SELECT * FROM cte)
  1251  ----
  1252  with &1 (cte)
  1253   ├── project
  1254   │    ├── columns: xyz.x:1!null
  1255   │    └── scan xyz
  1256   │         └── columns: xyz.x:1!null y:2 z:3
  1257   └── update abcde
  1258        ├── columns: <none>
  1259        ├── fetch columns: a:10 b:11 c:12 d:13 e:14 rowid:15
  1260        ├── update-mapping:
  1261        │    ├── b:11 => a:4
  1262        │    ├── column17:17 => d:7
  1263        │    └── b:11 => e:8
  1264        └── project
  1265             ├── columns: column17:17 a:10!null b:11 c:12 d:13 e:14 rowid:15!null
  1266             ├── select
  1267             │    ├── columns: a:10!null b:11 c:12 d:13 e:14 rowid:15!null
  1268             │    ├── scan abcde
  1269             │    │    ├── columns: a:10!null b:11 c:12 d:13 e:14 rowid:15!null
  1270             │    │    └── computed column expressions
  1271             │    │         ├── d:13
  1272             │    │         │    └── (b:11 + c:12) + 1
  1273             │    │         └── e:14
  1274             │    │              └── a:10
  1275             │    └── filters
  1276             │         └── exists
  1277             │              └── with-scan &1 (cte)
  1278             │                   ├── columns: x:16!null
  1279             │                   └── mapping:
  1280             │                        └──  xyz.x:1 => x:16
  1281             └── projections
  1282                  └── (b:11 + c:12) + 1 [as=column17:17]
  1283  
  1284  # Use CTE within SET expression.
  1285  build
  1286  WITH a AS (SELECT y, y+1 AS y1 FROM xyz) UPDATE abcde SET (a, b) = (SELECT * FROM a)
  1287  ----
  1288  with &1 (a)
  1289   ├── project
  1290   │    ├── columns: y1:4 xyz.y:2
  1291   │    ├── scan xyz
  1292   │    │    └── columns: x:1!null xyz.y:2 z:3
  1293   │    └── projections
  1294   │         └── xyz.y:2 + 1 [as=y1:4]
  1295   └── update abcde
  1296        ├── columns: <none>
  1297        ├── fetch columns: a:11 b:12 c:13 d:14 e:15 rowid:16
  1298        ├── update-mapping:
  1299        │    ├── y:17 => a:5
  1300        │    ├── y1:18 => b:6
  1301        │    ├── column19:19 => d:8
  1302        │    └── y:17 => e:9
  1303        └── project
  1304             ├── columns: column19:19 a:11!null b:12 c:13 d:14 e:15 rowid:16!null y:17 y1:18
  1305             ├── left-join-apply
  1306             │    ├── columns: a:11!null b:12 c:13 d:14 e:15 rowid:16!null y:17 y1:18
  1307             │    ├── scan abcde
  1308             │    │    ├── columns: a:11!null b:12 c:13 d:14 e:15 rowid:16!null
  1309             │    │    └── computed column expressions
  1310             │    │         ├── d:14
  1311             │    │         │    └── (b:12 + c:13) + 1
  1312             │    │         └── e:15
  1313             │    │              └── a:11
  1314             │    ├── max1-row
  1315             │    │    ├── columns: y:17 y1:18
  1316             │    │    └── with-scan &1 (a)
  1317             │    │         ├── columns: y:17 y1:18
  1318             │    │         └── mapping:
  1319             │    │              ├──  xyz.y:2 => y:17
  1320             │    │              └──  y1:4 => y1:18
  1321             │    └── filters (true)
  1322             └── projections
  1323                  └── (y1:18 + c:13) + 1 [as=column19:19]
  1324  
  1325  # ------------------------------------------------------------------------------
  1326  # Tests with mutations.
  1327  # ------------------------------------------------------------------------------
  1328  
  1329  # Mutation columns should be updated.
  1330  build
  1331  UPDATE mutation SET m=1
  1332  ----
  1333  update mutation
  1334   ├── columns: <none>
  1335   ├── fetch columns: m:6 n:7 o:8 p:9 q:10
  1336   ├── update-mapping:
  1337   │    ├── m_new:11 => m:1
  1338   │    ├── column12:12 => o:3
  1339   │    └── column13:13 => p:4
  1340   ├── check columns: check1:14
  1341   └── project
  1342        ├── columns: check1:14!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null column12:12!null column13:13
  1343        ├── project
  1344        │    ├── columns: column13:13 m:6!null n:7 o:8 p:9 q:10 m_new:11!null column12:12!null
  1345        │    ├── project
  1346        │    │    ├── columns: column12:12!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null
  1347        │    │    ├── project
  1348        │    │    │    ├── columns: m_new:11!null m:6!null n:7 o:8 p:9 q:10
  1349        │    │    │    ├── scan mutation
  1350        │    │    │    │    ├── columns: m:6!null n:7 o:8 p:9 q:10
  1351        │    │    │    │    └── check constraint expressions
  1352        │    │    │    │         └── m:6 > 0
  1353        │    │    │    └── projections
  1354        │    │    │         └── 1 [as=m_new:11]
  1355        │    │    └── projections
  1356        │    │         └── 10 [as=column12:12]
  1357        │    └── projections
  1358        │         └── column12:12 + n:7 [as=column13:13]
  1359        └── projections
  1360             └── m_new:11 > 0 [as=check1:14]
  1361  
  1362  # Update column that mutation column depends upon.
  1363  build
  1364  UPDATE mutation SET m=1, n=2
  1365  ----
  1366  update mutation
  1367   ├── columns: <none>
  1368   ├── fetch columns: m:6 n:7 o:8 p:9 q:10
  1369   ├── update-mapping:
  1370   │    ├── m_new:11 => m:1
  1371   │    ├── n_new:12 => n:2
  1372   │    ├── column13:13 => o:3
  1373   │    └── column14:14 => p:4
  1374   ├── check columns: check1:15
  1375   └── project
  1376        ├── columns: check1:15!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null n_new:12!null column13:13!null column14:14!null
  1377        ├── project
  1378        │    ├── columns: column14:14!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null n_new:12!null column13:13!null
  1379        │    ├── project
  1380        │    │    ├── columns: column13:13!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null n_new:12!null
  1381        │    │    ├── project
  1382        │    │    │    ├── columns: m_new:11!null n_new:12!null m:6!null n:7 o:8 p:9 q:10
  1383        │    │    │    ├── scan mutation
  1384        │    │    │    │    ├── columns: m:6!null n:7 o:8 p:9 q:10
  1385        │    │    │    │    └── check constraint expressions
  1386        │    │    │    │         └── m:6 > 0
  1387        │    │    │    └── projections
  1388        │    │    │         ├── 1 [as=m_new:11]
  1389        │    │    │         └── 2 [as=n_new:12]
  1390        │    │    └── projections
  1391        │    │         └── 10 [as=column13:13]
  1392        │    └── projections
  1393        │         └── column13:13 + n_new:12 [as=column14:14]
  1394        └── projections
  1395             └── m_new:11 > 0 [as=check1:15]
  1396  
  1397  # Ensure that ORDER BY wildcard does not select mutation columns.
  1398  build
  1399  UPDATE mutation SET m=1 ORDER BY mutation.* LIMIT 10
  1400  ----
  1401  update mutation
  1402   ├── columns: <none>
  1403   ├── fetch columns: m:6 n:7 o:8 p:9 q:10
  1404   ├── update-mapping:
  1405   │    ├── m_new:11 => m:1
  1406   │    ├── column12:12 => o:3
  1407   │    └── column13:13 => p:4
  1408   ├── check columns: check1:14
  1409   └── project
  1410        ├── columns: check1:14!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null column12:12!null column13:13
  1411        ├── project
  1412        │    ├── columns: column13:13 m:6!null n:7 o:8 p:9 q:10 m_new:11!null column12:12!null
  1413        │    ├── project
  1414        │    │    ├── columns: column12:12!null m:6!null n:7 o:8 p:9 q:10 m_new:11!null
  1415        │    │    ├── project
  1416        │    │    │    ├── columns: m_new:11!null m:6!null n:7 o:8 p:9 q:10
  1417        │    │    │    ├── limit
  1418        │    │    │    │    ├── columns: m:6!null n:7 o:8 p:9 q:10
  1419        │    │    │    │    ├── internal-ordering: +6,+7
  1420        │    │    │    │    ├── sort (segmented)
  1421        │    │    │    │    │    ├── columns: m:6!null n:7 o:8 p:9 q:10
  1422        │    │    │    │    │    ├── ordering: +6,+7
  1423        │    │    │    │    │    ├── limit hint: 10.00
  1424        │    │    │    │    │    └── scan mutation
  1425        │    │    │    │    │         ├── columns: m:6!null n:7 o:8 p:9 q:10
  1426        │    │    │    │    │         ├── check constraint expressions
  1427        │    │    │    │    │         │    └── m:6 > 0
  1428        │    │    │    │    │         └── ordering: +6
  1429        │    │    │    │    └── 10
  1430        │    │    │    └── projections
  1431        │    │    │         └── 1 [as=m_new:11]
  1432        │    │    └── projections
  1433        │    │         └── 10 [as=column12:12]
  1434        │    └── projections
  1435        │         └── column12:12 + n:7 [as=column13:13]
  1436        └── projections
  1437             └── m_new:11 > 0 [as=check1:14]
  1438  
  1439  # Try to return a mutation column.
  1440  build
  1441  UPDATE mutation SET m=1 RETURNING o
  1442  ----
  1443  error (42703): column "o" does not exist
  1444  
  1445  # Try to update a mutation column.
  1446  build
  1447  UPDATE mutation SET o=10
  1448  ----
  1449  error (42703): column "o" does not exist
  1450  
  1451  # Try to use mutation column in WHERE clause.
  1452  build
  1453  UPDATE mutation SET m=1 WHERE o=10
  1454  ----
  1455  error (42P10): column "o" is being backfilled
  1456  
  1457  # Try to use mutation column in SET expression.
  1458  build
  1459  UPDATE mutation SET m=o
  1460  ----
  1461  error (42P10): column "o" is being backfilled
  1462  
  1463  # Try to use mutation column in ORDER BY expression.
  1464  build
  1465  UPDATE mutation SET m=1 ORDER BY o LIMIT 2
  1466  ----
  1467  error (42P10): column "o" is being backfilled
  1468  
  1469  # ------------------------------------------------------------------------------
  1470  # Test check constraints
  1471  # ------------------------------------------------------------------------------
  1472  
  1473  # Update all columns to be constant.
  1474  build
  1475  UPDATE checks SET a=1, b=2, c=3
  1476  ----
  1477  update checks
  1478   ├── columns: <none>
  1479   ├── fetch columns: a:5 b:6 c:7 d:8
  1480   ├── update-mapping:
  1481   │    ├── a_new:9 => a:1
  1482   │    ├── b_new:10 => b:2
  1483   │    ├── c_new:11 => c:3
  1484   │    └── column12:12 => d:4
  1485   ├── check columns: check1:13 check2:14
  1486   └── project
  1487        ├── columns: check1:13!null check2:14!null a:5!null b:6 c:7 d:8 a_new:9!null b_new:10!null c_new:11!null column12:12!null
  1488        ├── project
  1489        │    ├── columns: column12:12!null a:5!null b:6 c:7 d:8 a_new:9!null b_new:10!null c_new:11!null
  1490        │    ├── project
  1491        │    │    ├── columns: a_new:9!null b_new:10!null c_new:11!null a:5!null b:6 c:7 d:8
  1492        │    │    ├── scan checks
  1493        │    │    │    ├── columns: a:5!null b:6 c:7 d:8
  1494        │    │    │    ├── check constraint expressions
  1495        │    │    │    │    └── a:5 > 0
  1496        │    │    │    └── computed column expressions
  1497        │    │    │         └── d:8
  1498        │    │    │              └── c:7 + 1
  1499        │    │    └── projections
  1500        │    │         ├── 1 [as=a_new:9]
  1501        │    │         ├── 2 [as=b_new:10]
  1502        │    │         └── 3 [as=c_new:11]
  1503        │    └── projections
  1504        │         └── c_new:11 + 1 [as=column12:12]
  1505        └── projections
  1506             ├── b_new:10 < column12:12 [as=check1:13]
  1507             └── a_new:9 > 0 [as=check2:14]
  1508  
  1509  # Do not update columns for one of the constraints.
  1510  build
  1511  UPDATE checks SET a=1
  1512  ----
  1513  update checks
  1514   ├── columns: <none>
  1515   ├── fetch columns: a:5 b:6 c:7 d:8
  1516   ├── update-mapping:
  1517   │    ├── a_new:9 => a:1
  1518   │    └── column10:10 => d:4
  1519   ├── check columns: check1:11 check2:12
  1520   └── project
  1521        ├── columns: check1:11 check2:12!null a:5!null b:6 c:7 d:8 a_new:9!null column10:10
  1522        ├── project
  1523        │    ├── columns: column10:10 a:5!null b:6 c:7 d:8 a_new:9!null
  1524        │    ├── project
  1525        │    │    ├── columns: a_new:9!null a:5!null b:6 c:7 d:8
  1526        │    │    ├── scan checks
  1527        │    │    │    ├── columns: a:5!null b:6 c:7 d:8
  1528        │    │    │    ├── check constraint expressions
  1529        │    │    │    │    └── a:5 > 0
  1530        │    │    │    └── computed column expressions
  1531        │    │    │         └── d:8
  1532        │    │    │              └── c:7 + 1
  1533        │    │    └── projections
  1534        │    │         └── 1 [as=a_new:9]
  1535        │    └── projections
  1536        │         └── c:7 + 1 [as=column10:10]
  1537        └── projections
  1538             ├── b:6 < column10:10 [as=check1:11]
  1539             └── a_new:9 > 0 [as=check2:12]
  1540  
  1541  # Update one column in constraint, but not the other.
  1542  build
  1543  UPDATE checks SET b=2
  1544  ----
  1545  update checks
  1546   ├── columns: <none>
  1547   ├── fetch columns: a:5 b:6 c:7 d:8
  1548   ├── update-mapping:
  1549   │    ├── b_new:9 => b:2
  1550   │    └── column10:10 => d:4
  1551   ├── check columns: check1:11 check2:12
  1552   └── project
  1553        ├── columns: check1:11 check2:12!null a:5!null b:6 c:7 d:8 b_new:9!null column10:10
  1554        ├── project
  1555        │    ├── columns: column10:10 a:5!null b:6 c:7 d:8 b_new:9!null
  1556        │    ├── project
  1557        │    │    ├── columns: b_new:9!null a:5!null b:6 c:7 d:8
  1558        │    │    ├── scan checks
  1559        │    │    │    ├── columns: a:5!null b:6 c:7 d:8
  1560        │    │    │    ├── check constraint expressions
  1561        │    │    │    │    └── a:5 > 0
  1562        │    │    │    └── computed column expressions
  1563        │    │    │         └── d:8
  1564        │    │    │              └── c:7 + 1
  1565        │    │    └── projections
  1566        │    │         └── 2 [as=b_new:9]
  1567        │    └── projections
  1568        │         └── c:7 + 1 [as=column10:10]
  1569        └── projections
  1570             ├── b_new:9 < column10:10 [as=check1:11]
  1571             └── a:5 > 0 [as=check2:12]
  1572  
  1573  # Update using tuple and subquery.
  1574  build
  1575  UPDATE checks SET (a, b)=(SELECT a, b FROM abcde WHERE abcde.a=checks.a)
  1576  ----
  1577  update checks
  1578   ├── columns: <none>
  1579   ├── fetch columns: checks.a:5 checks.b:6 checks.c:7 checks.d:8
  1580   ├── update-mapping:
  1581   │    ├── abcde.a:9 => checks.a:1
  1582   │    ├── abcde.b:10 => checks.b:2
  1583   │    └── column15:15 => checks.d:4
  1584   ├── check columns: check1:16 check2:17
  1585   └── project
  1586        ├── columns: check1:16 check2:17 checks.a:5!null checks.b:6 checks.c:7 checks.d:8 abcde.a:9 abcde.b:10 column15:15
  1587        ├── project
  1588        │    ├── columns: column15:15 checks.a:5!null checks.b:6 checks.c:7 checks.d:8 abcde.a:9 abcde.b:10
  1589        │    ├── left-join-apply
  1590        │    │    ├── columns: checks.a:5!null checks.b:6 checks.c:7 checks.d:8 abcde.a:9 abcde.b:10
  1591        │    │    ├── scan checks
  1592        │    │    │    ├── columns: checks.a:5!null checks.b:6 checks.c:7 checks.d:8
  1593        │    │    │    ├── check constraint expressions
  1594        │    │    │    │    └── checks.a:5 > 0
  1595        │    │    │    └── computed column expressions
  1596        │    │    │         └── checks.d:8
  1597        │    │    │              └── checks.c:7 + 1
  1598        │    │    ├── max1-row
  1599        │    │    │    ├── columns: abcde.a:9!null abcde.b:10
  1600        │    │    │    └── project
  1601        │    │    │         ├── columns: abcde.a:9!null abcde.b:10
  1602        │    │    │         └── select
  1603        │    │    │              ├── columns: abcde.a:9!null abcde.b:10 abcde.c:11 abcde.d:12 e:13 rowid:14!null
  1604        │    │    │              ├── scan abcde
  1605        │    │    │              │    ├── columns: abcde.a:9!null abcde.b:10 abcde.c:11 abcde.d:12 e:13 rowid:14!null
  1606        │    │    │              │    └── computed column expressions
  1607        │    │    │              │         ├── abcde.d:12
  1608        │    │    │              │         │    └── (abcde.b:10 + abcde.c:11) + 1
  1609        │    │    │              │         └── e:13
  1610        │    │    │              │              └── abcde.a:9
  1611        │    │    │              └── filters
  1612        │    │    │                   └── abcde.a:9 = checks.a:5
  1613        │    │    └── filters (true)
  1614        │    └── projections
  1615        │         └── checks.c:7 + 1 [as=column15:15]
  1616        └── projections
  1617             ├── abcde.b:10 < column15:15 [as=check1:16]
  1618             └── abcde.a:9 > 0 [as=check2:17]
  1619  
  1620  # ------------------------------------------------------------------------------
  1621  # Test decimal column truncation.
  1622  # ------------------------------------------------------------------------------
  1623  
  1624  opt
  1625  UPDATE decimals SET a=1.1, b=ARRAY[0.95, NULL, 15]
  1626  ----
  1627  update decimals
  1628   ├── columns: <none>
  1629   ├── fetch columns: decimals.a:5 decimals.b:6 c:7 decimals.d:8
  1630   ├── update-mapping:
  1631   │    ├── a:11 => decimals.a:1
  1632   │    ├── b:12 => decimals.b:2
  1633   │    └── d:14 => decimals.d:4
  1634   ├── check columns: check1:15 check2:16
  1635   └── project
  1636        ├── columns: check1:15!null check2:16 decimals.a:5!null decimals.b:6 c:7 decimals.d:8 a:11!null b:12 d:14
  1637        ├── project
  1638        │    ├── columns: d:14 a:11!null b:12 decimals.a:5!null decimals.b:6 c:7 decimals.d:8
  1639        │    ├── scan decimals
  1640        │    │    ├── columns: decimals.a:5!null decimals.b:6 c:7 decimals.d:8
  1641        │    │    └── computed column expressions
  1642        │    │         └── decimals.d:8
  1643        │    │              └── decimals.a:5 + c:7
  1644        │    └── projections
  1645        │         ├── crdb_internal.round_decimal_values(c:7 + 1, 1) [as=d:14]
  1646        │         ├── 1 [as=a:11]
  1647        │         └── crdb_internal.round_decimal_values(ARRAY[0.95,NULL,15], 1) [as=b:12]
  1648        └── projections
  1649             ├── true [as=check1:15]
  1650             └── b:12[0] > 1 [as=check2:16]