-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
virtual_columns
1431 lines (1380 loc) · 42.5 KB
/
virtual_columns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# LogicTest: local
statement ok
CREATE TABLE t (
a INT PRIMARY KEY,
b INT,
v INT AS (a+b) VIRTUAL,
FAMILY (a),
FAMILY (b)
)
statement ok
CREATE TABLE t_idx (
a INT PRIMARY KEY,
b INT,
c INT,
v INT AS (a+b) VIRTUAL,
w INT AS (c+1) VIRTUAL,
INDEX (v),
UNIQUE (w),
FAMILY (a),
FAMILY (b),
FAMILY (c)
)
query TT
SHOW CREATE TABLE t
----
t CREATE TABLE public.t (
a INT8 NOT NULL,
b INT8 NULL,
v INT8 NULL AS (a + b) VIRTUAL,
CONSTRAINT "primary" PRIMARY KEY (a ASC),
FAMILY fam_0_a (a),
FAMILY fam_1_b (b)
)
query TT
SHOW CREATE TABLE t_idx
----
t_idx CREATE TABLE public.t_idx (
a INT8 NOT NULL,
b INT8 NULL,
c INT8 NULL,
v INT8 NULL AS (a + b) VIRTUAL,
w INT8 NULL AS (c + 1:::INT8) VIRTUAL,
CONSTRAINT "primary" PRIMARY KEY (a ASC),
INDEX t_idx_v_idx (v ASC),
UNIQUE INDEX t_idx_w_key (w ASC),
FAMILY fam_0_a (a),
FAMILY fam_1_b (b),
FAMILY fam_2_c (c)
)
subtest Select
# Verify that the primary index doesn't contain the virtual column.
query T
EXPLAIN (OPT, CATALOG) SELECT * from t
----
TABLE t
├── a int not null
├── b int
├── v int as (a + b) virtual
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_a (a)
├── FAMILY fam_1_b (b)
└── PRIMARY INDEX primary
└── a int not null
project
├── scan t
│ └── computed column expressions
│ └── v
│ └── a + b
└── projections
└── a + b
query T
EXPLAIN (VERBOSE) SELECT * FROM t
----
distribution: local
vectorized: true
·
• render
│ columns: (a, b, v)
│ estimated row count: 1,000 (missing stats)
│ render v: a + b
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1,000 (missing stats)
table: t@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) SELECT a FROM t_idx WHERE a+b=1
----
distribution: local
vectorized: true
·
• scan
columns: (a)
estimated row count: 10 (missing stats)
table: t_idx@t_idx_v_idx
spans: /1-/2
query T
EXPLAIN (VERBOSE) SELECT a FROM t_idx WHERE v=1
----
distribution: local
vectorized: true
·
• scan
columns: (a)
estimated row count: 10 (missing stats)
table: t_idx@t_idx_v_idx
spans: /1-/2
# TODO(radu): allow retrieving the virtual column from the index.
query T
EXPLAIN (VERBOSE) SELECT a, v FROM t_idx WHERE v=1
----
distribution: local
vectorized: true
·
• render
│ columns: (a, v)
│ estimated row count: 333 (missing stats)
│ render v: a + b
│ render a: a
│
└── • index join
│ columns: (a, b)
│ estimated row count: 333 (missing stats)
│ table: t_idx@primary
│ key columns: a
│
└── • scan
columns: (a)
estimated row count: 10 (missing stats)
table: t_idx@t_idx_v_idx
spans: /1-/2
subtest Insert
# TODO(radu): we shouldn't need to synthesize v here.
query T
EXPLAIN (VERBOSE) INSERT INTO t VALUES (1, 1)
----
distribution: local
vectorized: true
·
• insert fast path
columns: ()
estimated row count: 0 (missing stats)
into: t(a, b, v)
auto commit
size: 3 columns, 1 row
row 0, expr 0: 1
row 0, expr 1: 1
row 0, expr 2: 2
query T
EXPLAIN (VERBOSE) INSERT INTO t VALUES (1, 1) RETURNING v
----
distribution: local
vectorized: true
·
• project
│ columns: (v)
│ estimated row count: 1
│
└── • insert fast path
columns: (a, v)
estimated row count: 1
into: t(a, b, v)
auto commit
size: 3 columns, 1 row
row 0, expr 0: 1
row 0, expr 1: 1
row 0, expr 2: 2
query T
EXPLAIN (VERBOSE) INSERT INTO t_idx VALUES (1, 1, 1)
----
distribution: local
vectorized: true
·
• insert fast path
columns: ()
estimated row count: 0 (missing stats)
into: t_idx(a, b, c, v, w)
auto commit
size: 5 columns, 1 row
row 0, expr 0: 1
row 0, expr 1: 1
row 0, expr 2: 1
row 0, expr 3: 2
row 0, expr 4: 2
subtest Delete
query T
EXPLAIN (VERBOSE) DELETE FROM t WHERE a > 1
----
distribution: local
vectorized: true
·
• delete range
columns: ()
estimated row count: 0 (missing stats)
from: t
spans: /2-
query T
EXPLAIN (VERBOSE) DELETE FROM t WHERE a > 1 RETURNING v
----
distribution: local
vectorized: true
·
• project
│ columns: (v)
│ estimated row count: 333 (missing stats)
│
└── • delete
│ columns: (a, v)
│ estimated row count: 333 (missing stats)
│ from: t
│ auto commit
│
└── • render
│ columns: (a, v)
│ estimated row count: 333 (missing stats)
│ render v: a + b
│ render a: a
│
└── • scan
columns: (a, b)
estimated row count: 333 (missing stats)
table: t@primary
spans: /2-
query T
EXPLAIN (VERBOSE) DELETE FROM t WHERE v = 1
----
distribution: local
vectorized: true
·
• delete
│ columns: ()
│ estimated row count: 0 (missing stats)
│ from: t
│ auto commit
│
└── • project
│ columns: (a)
│ estimated row count: 333 (missing stats)
│
└── • filter
│ columns: (a, b)
│ estimated row count: 333 (missing stats)
│ filter: (a + b) = 1
│
└── • scan
columns: (a, b)
estimated row count: 1,000 (missing stats)
table: t@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) DELETE FROM t_idx WHERE a > 1
----
distribution: local
vectorized: true
·
• delete
│ columns: ()
│ estimated row count: 0 (missing stats)
│ from: t_idx
│ auto commit
│
└── • render
│ columns: (a, v, w)
│ estimated row count: 333 (missing stats)
│ render v: a + b
│ render w: c + 1
│ render a: a
│
└── • scan
columns: (a, b, c)
estimated row count: 333 (missing stats)
table: t_idx@primary
spans: /2-
query T
EXPLAIN (VERBOSE) DELETE FROM t_idx WHERE a > 1 RETURNING v
----
distribution: local
vectorized: true
·
• project
│ columns: (v)
│ estimated row count: 333 (missing stats)
│
└── • delete
│ columns: (a, v)
│ estimated row count: 333 (missing stats)
│ from: t_idx
│ auto commit
│
└── • render
│ columns: (a, v, w)
│ estimated row count: 333 (missing stats)
│ render v: a + b
│ render w: c + 1
│ render a: a
│
└── • scan
columns: (a, b, c)
estimated row count: 333 (missing stats)
table: t_idx@primary
spans: /2-
query T
EXPLAIN (VERBOSE) DELETE FROM t_idx WHERE v = 1
----
distribution: local
vectorized: true
·
• delete
│ columns: ()
│ estimated row count: 0 (missing stats)
│ from: t_idx
│ auto commit
│
└── • render
│ columns: (a, v, w)
│ estimated row count: 333 (missing stats)
│ render v: a + b
│ render w: c + 1
│ render a: a
│
└── • index join
│ columns: (a, b, c)
│ estimated row count: 333 (missing stats)
│ table: t_idx@primary
│ key columns: a
│
└── • scan
columns: (a)
estimated row count: 10 (missing stats)
table: t_idx@t_idx_v_idx
spans: /1-/2
query T
EXPLAIN (VERBOSE) DELETE FROM t_idx WHERE a + b = 1
----
distribution: local
vectorized: true
·
• delete
│ columns: ()
│ estimated row count: 0 (missing stats)
│ from: t_idx
│ auto commit
│
└── • render
│ columns: (a, v, w)
│ estimated row count: 333 (missing stats)
│ render v: a + b
│ render w: c + 1
│ render a: a
│
└── • index join
│ columns: (a, b, c)
│ estimated row count: 333 (missing stats)
│ table: t_idx@primary
│ key columns: a
│
└── • scan
columns: (a)
estimated row count: 10 (missing stats)
table: t_idx@t_idx_v_idx
spans: /1-/2
subtest Update
query T
EXPLAIN (VERBOSE) UPDATE t SET a=a+1
----
distribution: local
vectorized: true
·
• update
│ columns: ()
│ estimated row count: 0 (missing stats)
│ table: t
│ set: a, v
│ auto commit
│
└── • render
│ columns: (a, b, v, a_new, column12)
│ estimated row count: 1,000 (missing stats)
│ render column12: a_new + b
│ render a: a
│ render b: b
│ render v: v
│ render a_new: a_new
│
└── • render
│ columns: (a_new, v, a, b)
│ estimated row count: 1,000 (missing stats)
│ render a_new: a + 1
│ render v: a + b
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1,000 (missing stats)
table: t@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) UPDATE t SET b=b+1 WHERE v=45 RETURNING a,b,v
----
distribution: local
vectorized: true
·
• update
│ columns: (a, b, v)
│ estimated row count: 333 (missing stats)
│ table: t
│ set: b, v
│ auto commit
│
└── • render
│ columns: (a, b, v, b_new, column12)
│ estimated row count: 333 (missing stats)
│ render column12: a + b_new
│ render a: a
│ render b: b
│ render v: v
│ render b_new: b_new
│
└── • render
│ columns: (b_new, v, a, b)
│ estimated row count: 333 (missing stats)
│ render b_new: b + 1
│ render v: a + b
│ render a: a
│ render b: b
│
└── • filter
│ columns: (a, b)
│ estimated row count: 333 (missing stats)
│ filter: (a + b) = 45
│
└── • scan
columns: (a, b)
estimated row count: 1,000 (missing stats)
table: t@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) UPDATE t_idx SET a=a+1
----
distribution: local
vectorized: true
·
• update
│ columns: ()
│ estimated row count: 0 (missing stats)
│ table: t_idx
│ set: a, v
│ auto commit
│
└── • render
│ columns: (a, b, c, v, w, a_new, column16)
│ estimated row count: 1,000 (missing stats)
│ render column16: a_new + b
│ render a: a
│ render b: b
│ render c: c
│ render v: v
│ render w: w
│ render a_new: a_new
│
└── • render
│ columns: (a_new, v, w, a, b, c)
│ estimated row count: 1,000 (missing stats)
│ render a_new: a + 1
│ render v: a + b
│ render w: c + 1
│ render a: a
│ render b: b
│ render c: c
│
└── • scan
columns: (a, b, c)
estimated row count: 1,000 (missing stats)
table: t_idx@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) UPDATE t_idx SET b=b+1 RETURNING v, w
----
distribution: local
vectorized: true
·
• project
│ columns: (v, w)
│ estimated row count: 1,000 (missing stats)
│
└── • update
│ columns: (a, v, w)
│ estimated row count: 1,000 (missing stats)
│ table: t_idx
│ set: b, v
│ auto commit
│
└── • render
│ columns: (a, b, v, w, b_new, column16)
│ estimated row count: 1,000 (missing stats)
│ render column16: a + b_new
│ render a: a
│ render b: b
│ render v: v
│ render w: w
│ render b_new: b_new
│
└── • render
│ columns: (b_new, v, w, a, b)
│ estimated row count: 1,000 (missing stats)
│ render b_new: b + 1
│ render v: a + b
│ render w: c + 1
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b, c)
estimated row count: 1,000 (missing stats)
table: t_idx@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) UPDATE t_idx SET b=b+1 WHERE v=45 RETURNING v, w
----
distribution: local
vectorized: true
·
• project
│ columns: (v, w)
│ estimated row count: 333 (missing stats)
│
└── • update
│ columns: (a, v, w)
│ estimated row count: 333 (missing stats)
│ table: t_idx
│ set: b, v
│ auto commit
│
└── • render
│ columns: (a, b, v, w, b_new, column16)
│ estimated row count: 333 (missing stats)
│ render column16: a + b_new
│ render a: a
│ render b: b
│ render v: v
│ render w: w
│ render b_new: b_new
│
└── • render
│ columns: (b_new, v, w, a, b)
│ estimated row count: 333 (missing stats)
│ render b_new: b + 1
│ render v: a + b
│ render w: c + 1
│ render a: a
│ render b: b
│
└── • index join
│ columns: (a, b, c)
│ estimated row count: 333 (missing stats)
│ table: t_idx@primary
│ key columns: a
│
└── • scan
columns: (a)
estimated row count: 10 (missing stats)
table: t_idx@t_idx_v_idx
spans: /45-/46
query T
EXPLAIN (VERBOSE) UPDATE t_idx SET c=6 WHERE a=2
----
distribution: local
vectorized: true
·
• update
│ columns: ()
│ estimated row count: 0 (missing stats)
│ table: t_idx
│ set: c, w
│ auto commit
│
└── • render
│ columns: (a, c, w, c_new, column17)
│ estimated row count: 1 (missing stats)
│ render column17: 7
│ render c_new: 6
│ render w: c + 1
│ render a: a
│ render c: c
│
└── • scan
columns: (a, c)
estimated row count: 1 (missing stats)
table: t_idx@primary
spans: /2/0-/2/1 /2/2/1-/2/2/2
locking strength: for update
query T
EXPLAIN (VERBOSE) UPDATE t_idx SET a=a+1 RETURNING a,v,w
----
distribution: local
vectorized: true
·
• update
│ columns: (a, v, w)
│ estimated row count: 1,000 (missing stats)
│ table: t_idx
│ set: a, v
│ auto commit
│
└── • render
│ columns: (a, b, c, v, w, a_new, column16)
│ estimated row count: 1,000 (missing stats)
│ render column16: a_new + b
│ render a: a
│ render b: b
│ render c: c
│ render v: v
│ render w: w
│ render a_new: a_new
│
└── • render
│ columns: (a_new, v, w, a, b, c)
│ estimated row count: 1,000 (missing stats)
│ render a_new: a + 1
│ render v: a + b
│ render w: c + 1
│ render a: a
│ render b: b
│ render c: c
│
└── • scan
columns: (a, b, c)
estimated row count: 1,000 (missing stats)
table: t_idx@primary
spans: FULL SCAN
query T
EXPLAIN (VERBOSE) UPDATE t_idx SET b=b+1 RETURNING w
----
distribution: local
vectorized: true
·
• project
│ columns: (w)
│ estimated row count: 1,000 (missing stats)
│
└── • update
│ columns: (a, w)
│ estimated row count: 1,000 (missing stats)
│ table: t_idx
│ set: b, v
│ auto commit
│
└── • render
│ columns: (a, b, v, w, b_new, column16)
│ estimated row count: 1,000 (missing stats)
│ render column16: a + b_new
│ render a: a
│ render b: b
│ render v: v
│ render w: w
│ render b_new: b_new
│
└── • render
│ columns: (b_new, v, w, a, b)
│ estimated row count: 1,000 (missing stats)
│ render b_new: b + 1
│ render v: a + b
│ render w: c + 1
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b, c)
estimated row count: 1,000 (missing stats)
table: t_idx@primary
spans: FULL SCAN
subtest Upsert
query T
EXPLAIN (VERBOSE) UPSERT INTO t VALUES (1, 10), (2, 20), (3, 30), (4, 40)
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t(a, b, v)
│ auto commit
│
└── • project
│ columns: (column1, column2, column8, column2, column8)
│
└── • render
│ columns: (column8, column1, column2)
│ estimated row count: 4
│ render column8: column1 + column2
│ render column1: column1
│ render column2: column2
│
└── • values
columns: (column1, column2)
size: 2 columns, 4 rows
row 0, expr 0: 1
row 0, expr 1: 10
row 1, expr 0: 2
row 1, expr 1: 20
row 2, expr 0: 3
row 2, expr 1: 30
row 3, expr 0: 4
row 3, expr 1: 40
query T
EXPLAIN (VERBOSE) INSERT INTO t VALUES (5, 51), (6, 60) ON CONFLICT DO NOTHING RETURNING v
----
distribution: local
vectorized: true
·
• project
│ columns: (v)
│ estimated row count: 0 (missing stats)
│
└── • insert
│ columns: (a, v)
│ estimated row count: 0 (missing stats)
│ into: t(a, b, v)
│ auto commit
│ arbiter indexes: primary
│
└── • lookup join (anti)
│ columns: (column1, column2, column8)
│ estimated row count: 0 (missing stats)
│ table: t@primary
│ equality: (column1) = (a)
│ equality cols are key
│
└── • render
│ columns: (column8, column1, column2)
│ estimated row count: 2
│ render column8: column1 + column2
│ render column1: column1
│ render column2: column2
│
└── • values
columns: (column1, column2)
size: 2 columns, 2 rows
row 0, expr 0: 5
row 0, expr 1: 51
row 1, expr 0: 6
row 1, expr 1: 60
query T
EXPLAIN (VERBOSE) INSERT INTO t VALUES (4, 100), (6, 100), (7, 100) ON CONFLICT (a) DO UPDATE SET b = t.v
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t(a, b, v)
│ auto commit
│ arbiter indexes: primary
│
└── • project
│ columns: (column1, column2, column8, a, b, v, upsert_b, upsert_v, a)
│
└── • render
│ columns: (upsert_b, upsert_v, column1, column2, column8, a, b, v)
│ estimated row count: 3 (missing stats)
│ render upsert_b: CASE WHEN a IS NULL THEN column2 ELSE v END
│ render upsert_v: CASE WHEN a IS NULL THEN column8 ELSE a + v END
│ render column1: column1
│ render column2: column2
│ render column8: column8
│ render a: a
│ render b: b
│ render v: v
│
└── • render
│ columns: (v, column1, column2, column8, a, b)
│ estimated row count: 3 (missing stats)
│ render v: CASE a IS NULL WHEN true THEN CAST(NULL AS INT8) ELSE a + b END
│ render column1: column1
│ render column2: column2
│ render column8: column8
│ render a: a
│ render b: b
│
└── • lookup join (left outer)
│ columns: (column8, column1, column2, a, b)
│ estimated row count: 3 (missing stats)
│ table: t@primary
│ equality: (column1) = (a)
│ equality cols are key
│
└── • render
│ columns: (column8, column1, column2)
│ estimated row count: 3
│ render column8: column1 + column2
│ render column1: column1
│ render column2: column2
│
└── • values
columns: (column1, column2)
size: 2 columns, 3 rows
row 0, expr 0: 4
row 0, expr 1: 100
row 1, expr 0: 6
row 1, expr 1: 100
row 2, expr 0: 7
row 2, expr 1: 100
query T
EXPLAIN (VERBOSE) INSERT INTO t VALUES (2, 100), (5, 100), (8, 100) ON CONFLICT (a) DO UPDATE SET b = excluded.v
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t(a, b, v)
│ auto commit
│ arbiter indexes: primary
│
└── • project
│ columns: (column1, column2, column8, a, b, v, upsert_b, upsert_v, a)
│
└── • render
│ columns: (upsert_b, upsert_v, column1, column2, column8, a, b, v)
│ estimated row count: 3 (missing stats)
│ render upsert_b: CASE WHEN a IS NULL THEN column2 ELSE column8 END
│ render upsert_v: CASE WHEN a IS NULL THEN column8 ELSE a + column8 END
│ render column1: column1
│ render column2: column2
│ render column8: column8
│ render a: a
│ render b: b
│ render v: v
│
└── • render
│ columns: (v, column1, column2, column8, a, b)
│ estimated row count: 3 (missing stats)
│ render v: CASE a IS NULL WHEN true THEN CAST(NULL AS INT8) ELSE a + b END
│ render column1: column1
│ render column2: column2
│ render column8: column8
│ render a: a
│ render b: b
│
└── • lookup join (left outer)
│ columns: (column8, column1, column2, a, b)
│ estimated row count: 3 (missing stats)
│ table: t@primary
│ equality: (column1) = (a)
│ equality cols are key
│
└── • render
│ columns: (column8, column1, column2)
│ estimated row count: 3
│ render column8: column1 + column2
│ render column1: column1
│ render column2: column2
│
└── • values
columns: (column1, column2)
size: 2 columns, 3 rows
row 0, expr 0: 2
row 0, expr 1: 100
row 1, expr 0: 5
row 1, expr 1: 100
row 2, expr 0: 8
row 2, expr 1: 100
query T
EXPLAIN (VERBOSE) UPSERT INTO t_idx VALUES (1, 10, 100), (2, 20, 200), (3, 30, 300), (4, 40, 400)
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_idx(a, b, c, v, w)
│ auto commit
│ arbiter indexes: primary
│
└── • project
│ columns: (column1, column2, column3, column11, column12, a, b, c, v, w, column2, column3, column11, column12, a)
│
└── • render
│ columns: (v, w, column1, column2, column3, column11, column12, a, b, c)
│ estimated row count: 4 (missing stats)
│ render v: CASE a IS NULL WHEN true THEN CAST(NULL AS INT8) ELSE a + b END
│ render w: CASE a IS NULL WHEN true THEN CAST(NULL AS INT8) ELSE c + 1 END
│ render column1: column1
│ render column2: column2
│ render column3: column3
│ render column11: column11
│ render column12: column12
│ render a: a
│ render b: b
│ render c: c
│
└── • lookup join (left outer)
│ columns: (column11, column12, column1, column2, column3, a, b, c)
│ estimated row count: 4 (missing stats)
│ table: t_idx@primary
│ equality: (column1) = (a)
│ equality cols are key
│ locking strength: for update
│
└── • render
│ columns: (column11, column12, column1, column2, column3)
│ estimated row count: 4
│ render column11: column1 + column2
│ render column12: column3 + 1
│ render column1: column1
│ render column2: column2
│ render column3: column3
│
└── • values
columns: (column1, column2, column3)
size: 3 columns, 4 rows
row 0, expr 0: 1
row 0, expr 1: 10
row 0, expr 2: 100
row 1, expr 0: 2
row 1, expr 1: 20
row 1, expr 2: 200
row 2, expr 0: 3
row 2, expr 1: 30
row 2, expr 2: 300
row 3, expr 0: 4
row 3, expr 1: 40
row 3, expr 2: 400
query T
EXPLAIN (VERBOSE) UPSERT INTO t_idx VALUES (3, 31, 301), (5, 50, 500) RETURNING a, v, w
----
distribution: local
vectorized: true
·
• upsert
│ columns: (a, v, w)
│ estimated row count: 2 (missing stats)
│ into: t_idx(a, b, c, v, w)
│ auto commit
│ arbiter indexes: primary
│
└── • project
│ columns: (column1, column2, column3, column11, column12, a, b, c, v, w, column2, column3, column11, column12, a)
│
└── • render
│ columns: (upsert_a, column1, column2, column3, column11, column12, a, b, c, v, w)
│ estimated row count: 2 (missing stats)
│ render upsert_a: CASE WHEN a IS NULL THEN column1 ELSE a END
│ render column1: column1
│ render column2: column2
│ render column3: column3
│ render column11: column11
│ render column12: column12
│ render a: a
│ render b: b
│ render c: c
│ render v: v
│ render w: w