-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
hash_sharded_index
901 lines (863 loc) · 34.9 KB
/
hash_sharded_index
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
# LogicTest: local
statement ok
SET experimental_enable_hash_sharded_indexes = true;
statement ok
CREATE TABLE sharded_primary (a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT=11)
query T
EXPLAIN (VERBOSE) INSERT INTO sharded_primary (a) VALUES (1), (2)
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: sharded_primary(crdb_internal_a_shard_11, a)
│ auto commit
│
└── • render
│ columns: (crdb_internal_a_shard_11_cast, column1, check1)
│ estimated row count: 2
│ render check1: crdb_internal_a_shard_11_cast IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
│ render column1: column1
│ render crdb_internal_a_shard_11_cast: crdb_internal_a_shard_11_cast
│
└── • render
│ columns: (crdb_internal_a_shard_11_cast, column1)
│ estimated row count: 2
│ render crdb_internal_a_shard_11_cast: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column1)), 11), NULL::INT4)
│ render column1: column1
│
└── • values
columns: (column1)
size: 1 column, 2 rows
row 0, expr 0: 1
row 1, expr 0: 2
statement ok
CREATE TABLE sharded_secondary (a INT8, INDEX (a) USING HASH WITH BUCKET_COUNT=12)
query T
EXPLAIN (VERBOSE) INSERT INTO sharded_secondary (a) VALUES (1), (2)
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: sharded_secondary(a, crdb_internal_a_shard_12, rowid)
│ auto commit
│
└── • render
│ columns: (column1, crdb_internal_a_shard_12_cast, rowid_default, check1)
│ estimated row count: 2
│ render check1: crdb_internal_a_shard_12_cast IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
│ render column1: column1
│ render rowid_default: rowid_default
│ render crdb_internal_a_shard_12_cast: crdb_internal_a_shard_12_cast
│
└── • render
│ columns: (crdb_internal_a_shard_12_cast, rowid_default, column1)
│ estimated row count: 2
│ render crdb_internal_a_shard_12_cast: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column1)), 12), NULL::INT4)
│ render rowid_default: unique_rowid()
│ render column1: column1
│
└── • values
columns: (column1)
size: 1 column, 2 rows
row 0, expr 0: 1
row 1, expr 0: 2
statement ok
CREATE TABLE sharded_primary_with_many_column_types (
i2 INT2,
i4 INT4,
i8 INT8,
f4 FLOAT4,
f8 FLOAT8,
s STRING,
c CHAR,
b BYTES,
dc DECIMAL,
ival INTERVAL,
oid OID,
tstz TIMESTAMPTZ,
ts TIMESTAMP,
da DATE,
inet INET,
vb VARBIT,
FAMILY (i2, i4, i8, f4, f8, s, c, b, dc, ival, oid, tstz, ts, da, inet, vb),
PRIMARY KEY (i2, i4, i8, f4, f8, s, c, b, dc, ival, oid, tstz, ts, da, inet, vb) USING HASH WITH BUCKET_COUNT = 7
);
query T
EXPLAIN (VERBOSE) SELECT * FROM sharded_primary_with_many_column_types WHERE (i2, i4, i8, f4, f8, s, c, b, dc, ival, oid, tstz, ts, da, inet, vb) = (1::INT2,
1::INT4,
1::INT8,
1::FLOAT4,
1::FLOAT8,
1::STRING,
1::CHAR,
1::STRING::BYTES,
1::DECIMAL,
1::INTERVAL,
1::OID,
1::TIMESTAMPTZ,
1::TIMESTAMP,
1::DATE,
('127.0.0.' || 1::STRING)::INET,
1::VARBIT);
----
distribution: local
vectorized: true
·
• scan
columns: (i2, i4, i8, f4, f8, s, c, b, dc, ival, oid, tstz, ts, da, inet, vb)
estimated row count: 1 (missing stats)
table: sharded_primary_with_many_column_types@sharded_primary_with_many_column_types_pkey
spans: /3/1/1/1/1/1/"1"/"1"/"1"/1/00:00:01/1/1970-01-01T00:00:01Z/1970-01-01T00:00:01Z/1/"\x00 \u007f\x00\x00\x01"/B/0
# Test to make sure constraint on shard column value is added correctly when
# creating a table with output show create table.
subtest create_with_show_create_keeps_shard_col_constraint
statement ok
CREATE TABLE t (
a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = 8
);
query T
EXPLAIN (OPT, CATALOG) SELECT * FROM t
----
TABLE t
├── crdb_internal_a_shard_8 int4 not null as (mod(fnv32("crdb_internal.datums_to_bytes"(a)), 8:::INT8)) virtual [hidden]
├── a int not null
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── CHECK (crdb_internal_a_shard_8 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8))
├── PRIMARY INDEX t_pkey
│ ├── crdb_internal_a_shard_8 int4 not null as (mod(fnv32("crdb_internal.datums_to_bytes"(a)), 8:::INT8)) virtual [hidden]
│ └── a int not null
└── UNIQUE WITHOUT INDEX (a)
scan t
├── check constraint expressions
│ └── crdb_internal_a_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7)
└── computed column expressions
└── crdb_internal_a_shard_8
└── mod(fnv32(crdb_internal.datums_to_bytes(a)), 8)
let $create_statement
SELECT create_statement FROM [SHOW CREATE TABLE t]
statement ok
DROP TABLE t
statement ok
$create_statement
query T
SELECT @2 FROM [SHOW CREATE TABLE t]
----
CREATE TABLE public.t (
crdb_internal_a_shard_8 INT4 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(a)), 8:::INT8)) VIRTUAL,
a INT8 NOT NULL,
CONSTRAINT t_pkey PRIMARY KEY (a ASC) USING HASH WITH BUCKET_COUNT = 8,
FAMILY "primary" (a)
)
query T
EXPLAIN (OPT, CATALOG) SELECT * FROM t
----
TABLE t
├── crdb_internal_a_shard_8 int4 not null as (mod(fnv32(crdb_internal.datums_to_bytes(a)), 8:::INT8)) virtual [hidden]
├── a int not null
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── CHECK (crdb_internal_a_shard_8 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8))
├── PRIMARY INDEX t_pkey
│ ├── crdb_internal_a_shard_8 int4 not null as (mod(fnv32(crdb_internal.datums_to_bytes(a)), 8:::INT8)) virtual [hidden]
│ └── a int not null
└── UNIQUE WITHOUT INDEX (a)
scan t
├── check constraint expressions
│ └── crdb_internal_a_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7)
└── computed column expressions
└── crdb_internal_a_shard_8
└── mod(fnv32(crdb_internal.datums_to_bytes(a)), 8)
# Test to make sure unqiueness checks are omitted for unique without index
# constraints that are derived from hash-sharded indexes on primary key.
subtest test_hash_index_unique_constraint_pkey
statement ok
CREATE TABLE t_hash_indexed (
a INT8 PRIMARY KEY USING HASH WITH BUCKET_COUNT = 8,
b INT8 NOT NULL,
FAMILY (a, b)
);
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765)
----
distribution: local
vectorized: true
·
• insert fast path
columns: ()
estimated row count: 0 (missing stats)
into: t_hash_indexed(crdb_internal_a_shard_8, a, b)
auto commit
size: 4 columns, 1 row
row 0, expr 0: 1
row 0, expr 1: 4321
row 0, expr 2: 8765
row 0, expr 3: true
query T
EXPLAIN (VERBOSE) UPDATE t_hash_indexed SET a = 4321 WHERE a = 1234;
----
distribution: local
vectorized: true
·
• update
│ columns: ()
│ estimated row count: 0 (missing stats)
│ table: t_hash_indexed
│ set: crdb_internal_a_shard_8, a
│ auto commit
│
└── • render
│ columns: (crdb_internal_a_shard_8, a, b, crdb_internal_a_shard_8_cast, a_new, check1)
│ estimated row count: 1 (missing stats)
│ render check1: true
│ render crdb_internal_a_shard_8_cast: 1
│ render a_new: 4321
│ render crdb_internal_a_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(a)), 8)
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /6/1234/0
locking strength: for update
query T
EXPLAIN (VERBOSE) UPSERT INTO t_hash_indexed VALUES (4321, 8765);
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(crdb_internal_a_shard_8, a, b)
│ auto commit
│
└── • project
│ columns: (crdb_internal_a_shard_8_cast, column1, column2, column2, check1)
│
└── • values
columns: (column1, column2, crdb_internal_a_shard_8_cast, check1)
size: 4 columns, 1 row
row 0, expr 0: 4321
row 0, expr 1: 8765
row 0, expr 2: 1
row 0, expr 3: true
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT (a) DO UPDATE SET a = 4321
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(crdb_internal_a_shard_8, a, b)
│ auto commit
│ arbiter constraints: t_hash_indexed_pkey
│
└── • project
│ columns: (crdb_internal_a_shard_8_cast, column1, column2, crdb_internal_a_shard_8, a, b, upsert_crdb_internal_a_shard_8, upsert_a, crdb_internal_a_shard_8, check1)
│
└── • render
│ columns: (check1, column1, column2, crdb_internal_a_shard_8_cast, crdb_internal_a_shard_8, a, b, upsert_crdb_internal_a_shard_8, upsert_a)
│ estimated row count: 1 (missing stats)
│ render check1: upsert_crdb_internal_a_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_a_shard_8_cast: crdb_internal_a_shard_8_cast
│ render crdb_internal_a_shard_8: crdb_internal_a_shard_8
│ render a: a
│ render b: b
│ render upsert_crdb_internal_a_shard_8: upsert_crdb_internal_a_shard_8
│ render upsert_a: upsert_a
│
└── • render
│ columns: (upsert_crdb_internal_a_shard_8, upsert_a, column1, column2, crdb_internal_a_shard_8_cast, crdb_internal_a_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│ render upsert_crdb_internal_a_shard_8: CASE WHEN crdb_internal_a_shard_8 IS NULL THEN crdb_internal_a_shard_8_cast ELSE 1 END
│ render upsert_a: CASE WHEN crdb_internal_a_shard_8 IS NULL THEN column1 ELSE 4321 END
│ render column1: column1
│ render column2: column2
│ render crdb_internal_a_shard_8_cast: crdb_internal_a_shard_8_cast
│ render crdb_internal_a_shard_8: crdb_internal_a_shard_8
│ render a: a
│ render b: b
│
└── • cross join (left outer)
│ columns: (column1, column2, crdb_internal_a_shard_8_cast, crdb_internal_a_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_a_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 1
│
└── • render
│ columns: (crdb_internal_a_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│ render crdb_internal_a_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(a)), 8)
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /1/4321/0
# TODO (issue #75498): The `lookup join` in this test output is unnecessary
# since we're using unique without index on (a) as an arbiter and using the
# original hash sharded index as an arbiter is totally redundant.
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT DO NOTHING
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(crdb_internal_a_shard_8, a, b)
│ auto commit
│ arbiter indexes: t_hash_indexed_pkey
│ arbiter constraints: t_hash_indexed_pkey
│
└── • render
│ columns: (crdb_internal_a_shard_8_cast, column1, column2, check1)
│ estimated row count: 0 (missing stats)
│ render check1: crdb_internal_a_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_a_shard_8_cast: crdb_internal_a_shard_8_cast
│
└── • lookup join (anti)
│ columns: (column1, column2, crdb_internal_a_shard_8_cast)
│ estimated row count: 0 (missing stats)
│ table: t_hash_indexed@t_hash_indexed_pkey
│ equality cols are key
│ lookup condition: (column1 = a) AND (crdb_internal_a_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7))
│
└── • cross join (anti)
│ columns: (column1, column2, crdb_internal_a_shard_8_cast)
│ estimated row count: 0 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_a_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 1
│
└── • project
│ columns: ()
│ estimated row count: 1 (missing stats)
│
└── • scan
columns: (a)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /1/4321/0
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT (a) DO NOTHING
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(crdb_internal_a_shard_8, a, b)
│ auto commit
│ arbiter constraints: t_hash_indexed_pkey
│
└── • render
│ columns: (crdb_internal_a_shard_8_cast, column1, column2, check1)
│ estimated row count: 0 (missing stats)
│ render check1: crdb_internal_a_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_a_shard_8_cast: crdb_internal_a_shard_8_cast
│
└── • cross join (anti)
│ columns: (column1, column2, crdb_internal_a_shard_8_cast)
│ estimated row count: 0 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_a_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 1
│
└── • project
│ columns: ()
│ estimated row count: 1 (missing stats)
│
└── • scan
columns: (a)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /1/4321/0
# Test to make sure unqiueness checks are omitted for unique without index
# constraints that are derived from hash-sharded indexes on secondary index.
subtest test_hash_index_unique_constraint_sec_key
statement ok
DROP TABLE IF EXISTS t_hash_indexed;
statement ok
CREATE TABLE t_hash_indexed (
a INT8 PRIMARY KEY,
b INT8 NOT NULL,
FAMILY (a, b)
);
statement ok
CREATE UNIQUE INDEX idx_t_hash_indexed ON t_hash_indexed (b) USING HASH WITH BUCKET_COUNT = 8;
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765)
----
distribution: local
vectorized: true
·
• insert fast path
columns: ()
estimated row count: 0 (missing stats)
into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
auto commit
size: 4 columns, 1 row
row 0, expr 0: 4321
row 0, expr 1: 8765
row 0, expr 2: 3
row 0, expr 3: true
query T
EXPLAIN (VERBOSE) UPDATE t_hash_indexed SET b = 8765 WHERE a = 4321;
----
distribution: local
vectorized: true
·
• update
│ columns: ()
│ estimated row count: 0 (missing stats)
│ table: t_hash_indexed
│ set: b, crdb_internal_b_shard_8
│ auto commit
│
└── • render
│ columns: (a, b, crdb_internal_b_shard_8, b_new, crdb_internal_b_shard_8_cast, check1)
│ estimated row count: 1 (missing stats)
│ render check1: true
│ render crdb_internal_b_shard_8_cast: 3
│ render b_new: 8765
│ render crdb_internal_b_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(b)), 8)
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /4321/0
locking strength: for update
query T
EXPLAIN (VERBOSE) UPSERT INTO t_hash_indexed VALUES (4321, 8765);
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter indexes: t_hash_indexed_pkey
│
└── • project
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8, column2, crdb_internal_b_shard_8_cast, a, check1)
│
└── • render
│ columns: (check1, column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8)
│ estimated row count: 1 (missing stats)
│ render check1: crdb_internal_b_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│ render crdb_internal_b_shard_8: crdb_internal_b_shard_8
│
└── • cross join (left outer)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, crdb_internal_b_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 3
│
└── • render
│ columns: (crdb_internal_b_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│ render crdb_internal_b_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(b)), 8)
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /4321/0
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT (a) DO UPDATE SET b = 8765
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter indexes: t_hash_indexed_pkey
│
└── • project
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8, upsert_b, upsert_crdb_internal_b_shard_8, a, check1)
│
└── • render
│ columns: (check1, column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8, upsert_b, upsert_crdb_internal_b_shard_8)
│ estimated row count: 1 (missing stats)
│ render check1: upsert_crdb_internal_b_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│ render crdb_internal_b_shard_8: crdb_internal_b_shard_8
│ render upsert_b: upsert_b
│ render upsert_crdb_internal_b_shard_8: upsert_crdb_internal_b_shard_8
│
└── • render
│ columns: (upsert_b, upsert_crdb_internal_b_shard_8, column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8)
│ estimated row count: 1 (missing stats)
│ render upsert_b: CASE WHEN a IS NULL THEN column2 ELSE 8765 END
│ render upsert_crdb_internal_b_shard_8: CASE WHEN a IS NULL THEN crdb_internal_b_shard_8_cast ELSE 3 END
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│ render crdb_internal_b_shard_8: crdb_internal_b_shard_8
│
└── • cross join (left outer)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, crdb_internal_b_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 3
│
└── • render
│ columns: (crdb_internal_b_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│ render crdb_internal_b_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(b)), 8)
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@t_hash_indexed_pkey
spans: /4321/0
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT (b) DO UPDATE SET b = 8765
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter constraints: idx_t_hash_indexed
│
└── • project
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8, upsert_b, upsert_crdb_internal_b_shard_8, a, check1)
│
└── • render
│ columns: (check1, column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8, upsert_b, upsert_crdb_internal_b_shard_8)
│ estimated row count: 1 (missing stats)
│ render check1: upsert_crdb_internal_b_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│ render crdb_internal_b_shard_8: crdb_internal_b_shard_8
│ render upsert_b: upsert_b
│ render upsert_crdb_internal_b_shard_8: upsert_crdb_internal_b_shard_8
│
└── • render
│ columns: (upsert_b, upsert_crdb_internal_b_shard_8, column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8)
│ estimated row count: 1 (missing stats)
│ render upsert_b: CASE WHEN a IS NULL THEN column2 ELSE 8765 END
│ render upsert_crdb_internal_b_shard_8: CASE WHEN a IS NULL THEN crdb_internal_b_shard_8_cast ELSE 3 END
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│ render crdb_internal_b_shard_8: crdb_internal_b_shard_8
│
└── • cross join (left outer)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, crdb_internal_b_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 3
│
└── • render
│ columns: (crdb_internal_b_shard_8, a, b)
│ estimated row count: 1 (missing stats)
│ render crdb_internal_b_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(b)), 8)
│ render a: a
│ render b: b
│
└── • scan
columns: (a, b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@idx_t_hash_indexed
spans: /3/8765/0
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (111, 222), (333, 444) ON CONFLICT (b) DO UPDATE SET b = excluded.b
----
distribution: local
vectorized: true
·
• upsert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter constraints: idx_t_hash_indexed
│
└── • project
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8, column2, crdb_internal_b_shard_8_cast, a, check1)
│
└── • render
│ columns: (check1, column1, column2, crdb_internal_b_shard_8_cast, a, b, crdb_internal_b_shard_8)
│ estimated row count: 2 (missing stats)
│ render check1: crdb_internal_b_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│ render crdb_internal_b_shard_8: crdb_internal_b_shard_8
│
└── • render
│ columns: (crdb_internal_b_shard_8, column1, column2, crdb_internal_b_shard_8_cast, a, b)
│ estimated row count: 2 (missing stats)
│ render crdb_internal_b_shard_8: CASE a IS NULL WHEN true THEN CAST(NULL AS INT8) ELSE mod(fnv32(crdb_internal.datums_to_bytes(b)), 8) END
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│ render a: a
│ render b: b
│
└── • project
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, a, b)
│ estimated row count: 2 (missing stats)
│
└── • lookup join (left outer)
│ columns: (crdb_internal_b_shard_8_cast, column1, column2, a, b, crdb_internal_b_shard_8)
│ estimated row count: 2 (missing stats)
│ table: t_hash_indexed@idx_t_hash_indexed
│ equality cols are key
│ lookup condition: (column2 = b) AND (crdb_internal_b_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7))
│ locking strength: for update
│
└── • render
│ columns: (crdb_internal_b_shard_8_cast, column1, column2)
│ estimated row count: 2
│ render crdb_internal_b_shard_8_cast: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column2)), 8), NULL::INT4)
│ render column1: column1
│ render column2: column2
│
└── • values
columns: (column1, column2)
size: 2 columns, 2 rows
row 0, expr 0: 111
row 0, expr 1: 222
row 1, expr 0: 333
row 1, expr 1: 444
# TODO (issue #75498): we're using unique without index on (a) as an arbiter and
# using the original hash sharded index as an arbiter is not necessary.
# TODO(mgartner): There is a full scan because we do not generate lookup
# anti-joins on indexes with virtual columns.
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT DO NOTHING
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter indexes: t_hash_indexed_pkey, idx_t_hash_indexed
│ arbiter constraints: idx_t_hash_indexed
│
└── • render
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, check1)
│ estimated row count: 0 (missing stats)
│ render check1: crdb_internal_b_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│
└── • cross join (right anti)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ estimated row count: 0 (missing stats)
│
├── • project
│ │ columns: ()
│ │ estimated row count: 1 (missing stats)
│ │
│ └── • scan
│ columns: (a)
│ estimated row count: 1 (missing stats)
│ table: t_hash_indexed@t_hash_indexed_pkey
│ spans: /4321/0
│
└── • lookup join (anti)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ estimated row count: 0 (missing stats)
│ table: t_hash_indexed@idx_t_hash_indexed
│ equality cols are key
│ lookup condition: (column2 = b) AND (crdb_internal_b_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7))
│
└── • hash join (right anti)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ estimated row count: 0 (missing stats)
│ equality: (b, crdb_internal_b_shard_8) = (column2, crdb_internal_b_shard_8_cast)
│ left cols are key
│ right cols are key
│
├── • render
│ │ columns: (crdb_internal_b_shard_8, b)
│ │ estimated row count: 1,000 (missing stats)
│ │ render crdb_internal_b_shard_8: mod(fnv32(crdb_internal.datums_to_bytes(b)), 8)
│ │ render b: b
│ │
│ └── • scan
│ columns: (b)
│ estimated row count: 1,000 (missing stats)
│ table: t_hash_indexed@t_hash_indexed_pkey
│ spans: FULL SCAN
│
└── • values
columns: (column1, column2, crdb_internal_b_shard_8_cast)
size: 3 columns, 1 row
row 0, expr 0: 4321
row 0, expr 1: 8765
row 0, expr 2: 3
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (4321, 8765) ON CONFLICT (b) DO NOTHING
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter constraints: idx_t_hash_indexed
│
└── • render
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, check1)
│ estimated row count: 0 (missing stats)
│ render check1: crdb_internal_b_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│
└── • cross join (anti)
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ estimated row count: 0 (missing stats)
│
├── • values
│ columns: (column1, column2, crdb_internal_b_shard_8_cast)
│ size: 3 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 8765
│ row 0, expr 2: 3
│
└── • project
│ columns: ()
│ estimated row count: 1 (missing stats)
│
└── • scan
columns: (b)
estimated row count: 1 (missing stats)
table: t_hash_indexed@idx_t_hash_indexed
spans: /3/8765/0
query T
EXPLAIN (VERBOSE) INSERT INTO t_hash_indexed VALUES (111, 222), (333, 444) ON CONFLICT (b) DO NOTHING
----
distribution: local
vectorized: true
·
• insert
│ columns: ()
│ estimated row count: 0 (missing stats)
│ into: t_hash_indexed(a, b, crdb_internal_b_shard_8)
│ auto commit
│ arbiter constraints: idx_t_hash_indexed
│
└── • render
│ columns: (column1, column2, crdb_internal_b_shard_8_cast, check1)
│ estimated row count: 0 (missing stats)
│ render check1: crdb_internal_b_shard_8_cast IN (0, 1, 2, 3, 4, 5, 6, 7)
│ render column1: column1
│ render column2: column2
│ render crdb_internal_b_shard_8_cast: crdb_internal_b_shard_8_cast
│
└── • lookup join (anti)
│ columns: (crdb_internal_b_shard_8_cast, column1, column2)
│ estimated row count: 0 (missing stats)
│ table: t_hash_indexed@idx_t_hash_indexed
│ equality cols are key
│ lookup condition: (column2 = b) AND (crdb_internal_b_shard_8 IN (0, 1, 2, 3, 4, 5, 6, 7))
│
└── • render
│ columns: (crdb_internal_b_shard_8_cast, column1, column2)
│ estimated row count: 2
│ render crdb_internal_b_shard_8_cast: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column2)), 8), NULL::INT4)
│ render column1: column1
│ render column2: column2
│
└── • values
columns: (column1, column2)
size: 2 columns, 2 rows
row 0, expr 0: 111
row 0, expr 1: 222
row 1, expr 0: 333
row 1, expr 1: 444