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

     1  exec-ddl
     2  CREATE TABLE xy (x INT PRIMARY KEY, y INT)
     3  ----
     4  
     5  exec-ddl
     6  CREATE TABLE uv (u INT, v INT NOT NULL)
     7  ----
     8  
     9  build
    10  SELECT * FROM xy UNION SELECT * FROM uv
    11  ----
    12  union
    13   ├── columns: x:6(int) y:7(int)
    14   ├── left columns: xy.x:1(int) xy.y:2(int)
    15   ├── right columns: u:3(int) v:4(int)
    16   ├── key: (6,7)
    17   ├── scan xy
    18   │    ├── columns: xy.x:1(int!null) xy.y:2(int)
    19   │    ├── key: (1)
    20   │    ├── fd: (1)-->(2)
    21   │    ├── prune: (1,2)
    22   │    └── interesting orderings: (+1)
    23   └── project
    24        ├── columns: u:3(int) v:4(int!null)
    25        ├── prune: (3,4)
    26        └── scan uv
    27             ├── columns: u:3(int) v:4(int!null) rowid:5(int!null)
    28             ├── key: (5)
    29             ├── fd: (5)-->(3,4)
    30             ├── prune: (3-5)
    31             └── interesting orderings: (+5)
    32  
    33  build
    34  SELECT x, y, x FROM xy INTERSECT SELECT v, u, rowid FROM (SELECT *, rowid FROM uv WHERE u=1) uv
    35  ----
    36  intersect
    37   ├── columns: x:1(int!null) y:2(int) x:1(int!null)
    38   ├── left columns: x:1(int!null) y:2(int) x:1(int!null)
    39   ├── right columns: v:4(int) u:3(int) rowid:5(int)
    40   ├── key: (1,2)
    41   ├── scan xy
    42   │    ├── columns: x:1(int!null) y:2(int)
    43   │    ├── key: (1)
    44   │    ├── fd: (1)-->(2)
    45   │    ├── prune: (1,2)
    46   │    └── interesting orderings: (+1)
    47   └── select
    48        ├── columns: u:3(int!null) v:4(int!null) rowid:5(int!null)
    49        ├── key: (5)
    50        ├── fd: ()-->(3), (5)-->(4)
    51        ├── prune: (4,5)
    52        ├── interesting orderings: (+5)
    53        ├── scan uv
    54        │    ├── columns: u:3(int) v:4(int!null) rowid:5(int!null)
    55        │    ├── key: (5)
    56        │    ├── fd: (5)-->(3,4)
    57        │    ├── prune: (3-5)
    58        │    └── interesting orderings: (+5)
    59        └── filters
    60             └── eq [type=bool, outer=(3), constraints=(/3: [/1 - /1]; tight), fd=()-->(3)]
    61                  ├── variable: u:3 [type=int]
    62                  └── const: 1 [type=int]
    63  
    64  build
    65  SELECT x, x, y FROM xy EXCEPT SELECT u, v, v FROM (SELECT * FROM uv WHERE u=1) uv
    66  ----
    67  except
    68   ├── columns: x:1(int!null) x:1(int!null) y:2(int)
    69   ├── left columns: x:1(int!null) x:1(int!null) y:2(int)
    70   ├── right columns: u:3(int) v:4(int) v:4(int)
    71   ├── key: (1,2)
    72   ├── scan xy
    73   │    ├── columns: x:1(int!null) y:2(int)
    74   │    ├── key: (1)
    75   │    ├── fd: (1)-->(2)
    76   │    ├── prune: (1,2)
    77   │    └── interesting orderings: (+1)
    78   └── project
    79        ├── columns: u:3(int!null) v:4(int!null)
    80        ├── fd: ()-->(3)
    81        ├── prune: (3,4)
    82        └── select
    83             ├── columns: u:3(int!null) v:4(int!null) rowid:5(int!null)
    84             ├── key: (5)
    85             ├── fd: ()-->(3), (5)-->(4)
    86             ├── prune: (4,5)
    87             ├── interesting orderings: (+5)
    88             ├── scan uv
    89             │    ├── columns: u:3(int) v:4(int!null) rowid:5(int!null)
    90             │    ├── key: (5)
    91             │    ├── fd: (5)-->(3,4)
    92             │    ├── prune: (3-5)
    93             │    └── interesting orderings: (+5)
    94             └── filters
    95                  └── eq [type=bool, outer=(3), constraints=(/3: [/1 - /1]; tight), fd=()-->(3)]
    96                       ├── variable: u:3 [type=int]
    97                       └── const: 1 [type=int]
    98  
    99  # Propagate outer columns.
   100  build
   101  SELECT * FROM xy WHERE (SELECT x, u FROM uv UNION SELECT y, v FROM uv) = (1, 2)
   102  ----
   103  select
   104   ├── columns: x:1(int!null) y:2(int)
   105   ├── key: (1)
   106   ├── fd: (1)-->(2)
   107   ├── interesting orderings: (+1)
   108   ├── scan xy
   109   │    ├── columns: xy.x:1(int!null) xy.y:2(int)
   110   │    ├── key: (1)
   111   │    ├── fd: (1)-->(2)
   112   │    ├── prune: (1,2)
   113   │    └── interesting orderings: (+1)
   114   └── filters
   115        └── eq [type=bool, outer=(1,2), correlated-subquery]
   116             ├── subquery [type=tuple{int, int}]
   117             │    └── max1-row
   118             │         ├── columns: column13:13(tuple{int, int})
   119             │         ├── error: "more than one row returned by a subquery used as an expression"
   120             │         ├── outer: (1,2)
   121             │         ├── cardinality: [0 - 1]
   122             │         ├── key: ()
   123             │         ├── fd: ()-->(13)
   124             │         └── project
   125             │              ├── columns: column13:13(tuple{int, int})
   126             │              ├── outer: (1,2)
   127             │              ├── prune: (13)
   128             │              ├── union
   129             │              │    ├── columns: x:11(int) u:12(int)
   130             │              │    ├── left columns: x:6(int) uv.u:3(int)
   131             │              │    ├── right columns: y:10(int) v:8(int)
   132             │              │    ├── outer: (1,2)
   133             │              │    ├── key: (11,12)
   134             │              │    ├── project
   135             │              │    │    ├── columns: x:6(int) uv.u:3(int)
   136             │              │    │    ├── outer: (1)
   137             │              │    │    ├── fd: ()-->(6)
   138             │              │    │    ├── prune: (3,6)
   139             │              │    │    ├── scan uv
   140             │              │    │    │    ├── columns: uv.u:3(int) v:4(int!null) rowid:5(int!null)
   141             │              │    │    │    ├── key: (5)
   142             │              │    │    │    ├── fd: (5)-->(3,4)
   143             │              │    │    │    ├── prune: (3-5)
   144             │              │    │    │    └── interesting orderings: (+5)
   145             │              │    │    └── projections
   146             │              │    │         └── variable: xy.x:1 [as=x:6, type=int, outer=(1)]
   147             │              │    └── project
   148             │              │         ├── columns: y:10(int) v:8(int!null)
   149             │              │         ├── outer: (2)
   150             │              │         ├── fd: ()-->(10)
   151             │              │         ├── prune: (8,10)
   152             │              │         ├── scan uv
   153             │              │         │    ├── columns: uv.u:7(int) v:8(int!null) rowid:9(int!null)
   154             │              │         │    ├── key: (9)
   155             │              │         │    ├── fd: (9)-->(7,8)
   156             │              │         │    ├── prune: (7-9)
   157             │              │         │    └── interesting orderings: (+9)
   158             │              │         └── projections
   159             │              │              └── variable: xy.y:2 [as=y:10, type=int, outer=(2)]
   160             │              └── projections
   161             │                   └── tuple [as=column13:13, type=tuple{int, int}, outer=(11,12)]
   162             │                        ├── variable: x:11 [type=int]
   163             │                        └── variable: u:12 [type=int]
   164             └── tuple [type=tuple{int, int}]
   165                  ├── const: 1 [type=int]
   166                  └── const: 2 [type=int]
   167  
   168  # Calculate union cardinality.
   169  build
   170  SELECT * FROM (VALUES (1), (2), (3))
   171  UNION ALL
   172  SELECT * FROM (VALUES (4), (5))
   173  UNION
   174  SELECT * FROM (VALUES (6), (7), (8))
   175  ----
   176  union
   177   ├── columns: column1:5(int!null)
   178   ├── left columns: column1:3(int)
   179   ├── right columns: column1:4(int)
   180   ├── cardinality: [1 - 8]
   181   ├── key: (5)
   182   ├── union-all
   183   │    ├── columns: column1:3(int!null)
   184   │    ├── left columns: column1:1(int)
   185   │    ├── right columns: column1:2(int)
   186   │    ├── cardinality: [5 - 5]
   187   │    ├── prune: (3)
   188   │    ├── values
   189   │    │    ├── columns: column1:1(int!null)
   190   │    │    ├── cardinality: [3 - 3]
   191   │    │    ├── prune: (1)
   192   │    │    ├── tuple [type=tuple{int}]
   193   │    │    │    └── const: 1 [type=int]
   194   │    │    ├── tuple [type=tuple{int}]
   195   │    │    │    └── const: 2 [type=int]
   196   │    │    └── tuple [type=tuple{int}]
   197   │    │         └── const: 3 [type=int]
   198   │    └── values
   199   │         ├── columns: column1:2(int!null)
   200   │         ├── cardinality: [2 - 2]
   201   │         ├── prune: (2)
   202   │         ├── tuple [type=tuple{int}]
   203   │         │    └── const: 4 [type=int]
   204   │         └── tuple [type=tuple{int}]
   205   │              └── const: 5 [type=int]
   206   └── values
   207        ├── columns: column1:4(int!null)
   208        ├── cardinality: [3 - 3]
   209        ├── prune: (4)
   210        ├── tuple [type=tuple{int}]
   211        │    └── const: 6 [type=int]
   212        ├── tuple [type=tuple{int}]
   213        │    └── const: 7 [type=int]
   214        └── tuple [type=tuple{int}]
   215             └── const: 8 [type=int]
   216  
   217  # Calculate intersection cardinality.
   218  build
   219  SELECT * FROM (VALUES (1), (2), (3))
   220  INTERSECT ALL
   221  SELECT * FROM (VALUES (4), (5))
   222  INTERSECT
   223  SELECT * FROM (VALUES (6), (7), (8))
   224  ----
   225  intersect
   226   ├── columns: column1:1(int!null)
   227   ├── left columns: column1:1(int!null)
   228   ├── right columns: column1:3(int)
   229   ├── cardinality: [0 - 2]
   230   ├── key: (1)
   231   ├── intersect-all
   232   │    ├── columns: column1:1(int!null)
   233   │    ├── left columns: column1:1(int!null)
   234   │    ├── right columns: column1:2(int)
   235   │    ├── cardinality: [0 - 2]
   236   │    ├── values
   237   │    │    ├── columns: column1:1(int!null)
   238   │    │    ├── cardinality: [3 - 3]
   239   │    │    ├── prune: (1)
   240   │    │    ├── tuple [type=tuple{int}]
   241   │    │    │    └── const: 1 [type=int]
   242   │    │    ├── tuple [type=tuple{int}]
   243   │    │    │    └── const: 2 [type=int]
   244   │    │    └── tuple [type=tuple{int}]
   245   │    │         └── const: 3 [type=int]
   246   │    └── values
   247   │         ├── columns: column1:2(int!null)
   248   │         ├── cardinality: [2 - 2]
   249   │         ├── prune: (2)
   250   │         ├── tuple [type=tuple{int}]
   251   │         │    └── const: 4 [type=int]
   252   │         └── tuple [type=tuple{int}]
   253   │              └── const: 5 [type=int]
   254   └── values
   255        ├── columns: column1:3(int!null)
   256        ├── cardinality: [3 - 3]
   257        ├── prune: (3)
   258        ├── tuple [type=tuple{int}]
   259        │    └── const: 6 [type=int]
   260        ├── tuple [type=tuple{int}]
   261        │    └── const: 7 [type=int]
   262        └── tuple [type=tuple{int}]
   263             └── const: 8 [type=int]
   264  
   265  # Calculate except cardinality.
   266  build
   267  SELECT * FROM (VALUES (1), (2), (3))
   268  EXCEPT ALL
   269  SELECT * FROM (VALUES (4), (5))
   270  EXCEPT
   271  SELECT * FROM (VALUES (6), (7), (8), (9))
   272  ----
   273  except
   274   ├── columns: column1:1(int!null)
   275   ├── left columns: column1:1(int!null)
   276   ├── right columns: column1:3(int)
   277   ├── cardinality: [0 - 3]
   278   ├── key: (1)
   279   ├── except-all
   280   │    ├── columns: column1:1(int!null)
   281   │    ├── left columns: column1:1(int!null)
   282   │    ├── right columns: column1:2(int)
   283   │    ├── cardinality: [1 - 3]
   284   │    ├── values
   285   │    │    ├── columns: column1:1(int!null)
   286   │    │    ├── cardinality: [3 - 3]
   287   │    │    ├── prune: (1)
   288   │    │    ├── tuple [type=tuple{int}]
   289   │    │    │    └── const: 1 [type=int]
   290   │    │    ├── tuple [type=tuple{int}]
   291   │    │    │    └── const: 2 [type=int]
   292   │    │    └── tuple [type=tuple{int}]
   293   │    │         └── const: 3 [type=int]
   294   │    └── values
   295   │         ├── columns: column1:2(int!null)
   296   │         ├── cardinality: [2 - 2]
   297   │         ├── prune: (2)
   298   │         ├── tuple [type=tuple{int}]
   299   │         │    └── const: 4 [type=int]
   300   │         └── tuple [type=tuple{int}]
   301   │              └── const: 5 [type=int]
   302   └── values
   303        ├── columns: column1:3(int!null)
   304        ├── cardinality: [4 - 4]
   305        ├── prune: (3)
   306        ├── tuple [type=tuple{int}]
   307        │    └── const: 6 [type=int]
   308        ├── tuple [type=tuple{int}]
   309        │    └── const: 7 [type=int]
   310        ├── tuple [type=tuple{int}]
   311        │    └── const: 8 [type=int]
   312        └── tuple [type=tuple{int}]
   313             └── const: 9 [type=int]