-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
pg_catalog.go
4889 lines (4560 loc) · 182 KB
/
pg_catalog.go
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
// Copyright 2016 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package sql
import (
"bytes"
"context"
"encoding/binary"
"fmt"
"hash"
"hash/fnv"
"strings"
"time"
"unicode"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catenumpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catformat"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/funcdesc"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sem/builtins"
"github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinsregistry"
"github.com/cockroachdb/cockroach/pkg/sql/sem/cast"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
"github.com/cockroachdb/cockroach/pkg/sql/sem/semenumpb"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree/treecmp"
"github.com/cockroachdb/cockroach/pkg/sql/sem/volatility"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/sql/vtable"
"github.com/cockroachdb/cockroach/pkg/util/collatedstring"
"github.com/cockroachdb/cockroach/pkg/util/duration"
"github.com/cockroachdb/cockroach/pkg/util/iterutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
"github.com/lib/pq/oid"
)
var (
oidZero = tree.NewDOid(0)
zeroVal = tree.DZero
negOneVal = tree.NewDInt(-1)
passwdStarString = tree.NewDString("********")
)
const (
indexTypeForwardIndex = "prefix"
indexTypeInvertedIndex = "inverted"
)
// Bitmasks for pg_index.indoption. Each column in the index has a bitfield
// indicating how the columns are indexed. The constants below are the same as
// the ones in Postgres:
// https://github.com/postgres/postgres/blob/b6423e92abfadaa1ed9642319872aa1654403cd6/src/include/catalog/pg_index.h#L70-L76
const (
// indoptionDesc indicates that the values in the index are in reverse order.
indoptionDesc = 0x01
// indoptionNullsFirst indicates that NULLs appear first in the index.
indoptionNullsFirst = 0x02
)
// RewriteEvTypes could be a enumeration if rewrite rules gets implemented
type RewriteEvTypes string
const evTypeSelect RewriteEvTypes = "1"
// PGShDependType is an enumeration that lists pg_shdepend deptype column values
type PGShDependType string
const (
// sharedDependencyOwner is a deptype used to reference an object with the
// owner of the dependent object.
sharedDependencyOwner PGShDependType = "o"
// sharedDependencyACL in postgres The referenced object is mentioned in the
// ACL (access control list, i.e., privileges list) of the dependent object.
// (A SHARED_DEPENDENCY_ACL entry is not made for the owner of the object,
// since the owner will have a SHARED_DEPENDENCY_OWNER entry anyway.)
// For cockroachDB deptype is sharedDependencyACL if the role is not the
// owner neither a pinned role.
sharedDependencyACL PGShDependType = "a"
// sharedDependencyPin in postgres for this deptype there is no dependent
// object; this type of entry is a signal that the system itself depends on
// the referenced object, and so that object must never be deleted. Entries
// of this type are created only by initdb.
// In cockroachDB the similar roles are root and admin.
sharedDependencyPin PGShDependType = "p"
)
var forwardIndexOid = stringOid(indexTypeForwardIndex)
var invertedIndexOid = stringOid(indexTypeInvertedIndex)
// pgCatalog contains a set of system tables mirroring PostgreSQL's pg_catalog schema.
// This code attempts to comply as closely as possible to the system catalogs documented
// in https://www.postgresql.org/docs/9.6/static/catalogs.html.
var pgCatalog = virtualSchema{
name: pgCatalogName,
undefinedTables: buildStringSet(
// Generated with:
// select distinct '"'||table_name||'",' from information_schema.tables
// where table_schema='pg_catalog' order by table_name;
"pg_pltemplate",
),
tableDefs: map[descpb.ID]virtualSchemaDef{
catconstants.PgCatalogAggregateTableID: pgCatalogAggregateTable,
catconstants.PgCatalogAmTableID: pgCatalogAmTable,
catconstants.PgCatalogAmopTableID: pgCatalogAmopTable,
catconstants.PgCatalogAmprocTableID: pgCatalogAmprocTable,
catconstants.PgCatalogAttrDefTableID: pgCatalogAttrDefTable,
catconstants.PgCatalogAttributeTableID: pgCatalogAttributeTable,
catconstants.PgCatalogAuthIDTableID: pgCatalogAuthIDTable,
catconstants.PgCatalogAuthMembersTableID: pgCatalogAuthMembersTable,
catconstants.PgCatalogAvailableExtensionVersionsTableID: pgCatalogAvailableExtensionVersionsTable,
catconstants.PgCatalogAvailableExtensionsTableID: pgCatalogAvailableExtensionsTable,
catconstants.PgCatalogCastTableID: pgCatalogCastTable,
catconstants.PgCatalogClassTableID: pgCatalogClassTable,
catconstants.PgCatalogCollationTableID: pgCatalogCollationTable,
catconstants.PgCatalogConfigTableID: pgCatalogConfigTable,
catconstants.PgCatalogConstraintTableID: pgCatalogConstraintTable,
catconstants.PgCatalogConversionTableID: pgCatalogConversionTable,
catconstants.PgCatalogCursorsTableID: pgCatalogCursorsTable,
catconstants.PgCatalogDatabaseTableID: pgCatalogDatabaseTable,
catconstants.PgCatalogDbRoleSettingTableID: pgCatalogDbRoleSettingTable,
catconstants.PgCatalogDefaultACLTableID: pgCatalogDefaultACLTable,
catconstants.PgCatalogDependTableID: pgCatalogDependTable,
catconstants.PgCatalogDescriptionTableID: pgCatalogDescriptionTable,
catconstants.PgCatalogEnumTableID: pgCatalogEnumTable,
catconstants.PgCatalogEventTriggerTableID: pgCatalogEventTriggerTable,
catconstants.PgCatalogExtensionTableID: pgCatalogExtensionTable,
catconstants.PgCatalogFileSettingsTableID: pgCatalogFileSettingsTable,
catconstants.PgCatalogForeignDataWrapperTableID: pgCatalogForeignDataWrapperTable,
catconstants.PgCatalogForeignServerTableID: pgCatalogForeignServerTable,
catconstants.PgCatalogForeignTableTableID: pgCatalogForeignTableTable,
catconstants.PgCatalogGroupTableID: pgCatalogGroupTable,
catconstants.PgCatalogHbaFileRulesTableID: pgCatalogHbaFileRulesTable,
catconstants.PgCatalogIndexTableID: pgCatalogIndexTable,
catconstants.PgCatalogIndexesTableID: pgCatalogIndexesTable,
catconstants.PgCatalogInheritsTableID: pgCatalogInheritsTable,
catconstants.PgCatalogInitPrivsTableID: pgCatalogInitPrivsTable,
catconstants.PgCatalogLanguageTableID: pgCatalogLanguageTable,
catconstants.PgCatalogLargeobjectMetadataTableID: pgCatalogLargeobjectMetadataTable,
catconstants.PgCatalogLargeobjectTableID: pgCatalogLargeobjectTable,
catconstants.PgCatalogLocksTableID: pgCatalogLocksTable,
catconstants.PgCatalogMatViewsTableID: pgCatalogMatViewsTable,
catconstants.PgCatalogNamespaceTableID: pgCatalogNamespaceTable,
catconstants.PgCatalogOpclassTableID: pgCatalogOpclassTable,
catconstants.PgCatalogOperatorTableID: pgCatalogOperatorTable,
catconstants.PgCatalogOpfamilyTableID: pgCatalogOpfamilyTable,
catconstants.PgCatalogPartitionedTableTableID: pgCatalogPartitionedTableTable,
catconstants.PgCatalogPoliciesTableID: pgCatalogPoliciesTable,
catconstants.PgCatalogPolicyTableID: pgCatalogPolicyTable,
catconstants.PgCatalogPreparedStatementsTableID: pgCatalogPreparedStatementsTable,
catconstants.PgCatalogPreparedXactsTableID: pgCatalogPreparedXactsTable,
catconstants.PgCatalogProcTableID: pgCatalogProcTable,
catconstants.PgCatalogPublicationRelTableID: pgCatalogPublicationRelTable,
catconstants.PgCatalogPublicationTableID: pgCatalogPublicationTable,
catconstants.PgCatalogPublicationTablesTableID: pgCatalogPublicationTablesTable,
catconstants.PgCatalogRangeTableID: pgCatalogRangeTable,
catconstants.PgCatalogReplicationOriginStatusTableID: pgCatalogReplicationOriginStatusTable,
catconstants.PgCatalogReplicationOriginTableID: pgCatalogReplicationOriginTable,
catconstants.PgCatalogReplicationSlotsTableID: pgCatalogReplicationSlotsTable,
catconstants.PgCatalogRewriteTableID: pgCatalogRewriteTable,
catconstants.PgCatalogRolesTableID: pgCatalogRolesTable,
catconstants.PgCatalogRulesTableID: pgCatalogRulesTable,
catconstants.PgCatalogSecLabelsTableID: pgCatalogSecLabelsTable,
catconstants.PgCatalogSecurityLabelTableID: pgCatalogSecurityLabelTable,
catconstants.PgCatalogSequenceTableID: pgCatalogSequenceTable,
catconstants.PgCatalogSequencesTableID: pgCatalogSequencesTable,
catconstants.PgCatalogSettingsTableID: pgCatalogSettingsTable,
catconstants.PgCatalogShadowTableID: pgCatalogShadowTable,
catconstants.PgCatalogSharedDescriptionTableID: pgCatalogSharedDescriptionTable,
catconstants.PgCatalogSharedSecurityLabelTableID: pgCatalogSharedSecurityLabelTable,
catconstants.PgCatalogShdependTableID: pgCatalogShdependTable,
catconstants.PgCatalogShmemAllocationsTableID: pgCatalogShmemAllocationsTable,
catconstants.PgCatalogStatActivityTableID: pgCatalogStatActivityTable,
catconstants.PgCatalogStatAllIndexesTableID: pgCatalogStatAllIndexesTable,
catconstants.PgCatalogStatAllTablesTableID: pgCatalogStatAllTablesTable,
catconstants.PgCatalogStatArchiverTableID: pgCatalogStatArchiverTable,
catconstants.PgCatalogStatBgwriterTableID: pgCatalogStatBgwriterTable,
catconstants.PgCatalogStatDatabaseConflictsTableID: pgCatalogStatDatabaseConflictsTable,
catconstants.PgCatalogStatDatabaseTableID: pgCatalogStatDatabaseTable,
catconstants.PgCatalogStatGssapiTableID: pgCatalogStatGssapiTable,
catconstants.PgCatalogStatProgressAnalyzeTableID: pgCatalogStatProgressAnalyzeTable,
catconstants.PgCatalogStatProgressBasebackupTableID: pgCatalogStatProgressBasebackupTable,
catconstants.PgCatalogStatProgressClusterTableID: pgCatalogStatProgressClusterTable,
catconstants.PgCatalogStatProgressCreateIndexTableID: pgCatalogStatProgressCreateIndexTable,
catconstants.PgCatalogStatProgressVacuumTableID: pgCatalogStatProgressVacuumTable,
catconstants.PgCatalogStatReplicationTableID: pgCatalogStatReplicationTable,
catconstants.PgCatalogStatSlruTableID: pgCatalogStatSlruTable,
catconstants.PgCatalogStatSslTableID: pgCatalogStatSslTable,
catconstants.PgCatalogStatSubscriptionTableID: pgCatalogStatSubscriptionTable,
catconstants.PgCatalogStatSysIndexesTableID: pgCatalogStatSysIndexesTable,
catconstants.PgCatalogStatSysTablesTableID: pgCatalogStatSysTablesTable,
catconstants.PgCatalogStatUserFunctionsTableID: pgCatalogStatUserFunctionsTable,
catconstants.PgCatalogStatUserIndexesTableID: pgCatalogStatUserIndexesTable,
catconstants.PgCatalogStatUserTablesTableID: pgCatalogStatUserTablesTable,
catconstants.PgCatalogStatWalReceiverTableID: pgCatalogStatWalReceiverTable,
catconstants.PgCatalogStatXactAllTablesTableID: pgCatalogStatXactAllTablesTable,
catconstants.PgCatalogStatXactSysTablesTableID: pgCatalogStatXactSysTablesTable,
catconstants.PgCatalogStatXactUserFunctionsTableID: pgCatalogStatXactUserFunctionsTable,
catconstants.PgCatalogStatXactUserTablesTableID: pgCatalogStatXactUserTablesTable,
catconstants.PgCatalogStatioAllIndexesTableID: pgCatalogStatioAllIndexesTable,
catconstants.PgCatalogStatioAllSequencesTableID: pgCatalogStatioAllSequencesTable,
catconstants.PgCatalogStatioAllTablesTableID: pgCatalogStatioAllTablesTable,
catconstants.PgCatalogStatioSysIndexesTableID: pgCatalogStatioSysIndexesTable,
catconstants.PgCatalogStatioSysSequencesTableID: pgCatalogStatioSysSequencesTable,
catconstants.PgCatalogStatioSysTablesTableID: pgCatalogStatioSysTablesTable,
catconstants.PgCatalogStatioUserIndexesTableID: pgCatalogStatioUserIndexesTable,
catconstants.PgCatalogStatioUserSequencesTableID: pgCatalogStatioUserSequencesTable,
catconstants.PgCatalogStatioUserTablesTableID: pgCatalogStatioUserTablesTable,
catconstants.PgCatalogStatisticExtDataTableID: pgCatalogStatisticExtDataTable,
catconstants.PgCatalogStatisticExtTableID: pgCatalogStatisticExtTable,
catconstants.PgCatalogStatisticTableID: pgCatalogStatisticTable,
catconstants.PgCatalogStatsExtTableID: pgCatalogStatsExtTable,
catconstants.PgCatalogStatsTableID: pgCatalogStatsTable,
catconstants.PgCatalogSubscriptionRelTableID: pgCatalogSubscriptionRelTable,
catconstants.PgCatalogSubscriptionTableID: pgCatalogSubscriptionTable,
catconstants.PgCatalogTablesTableID: pgCatalogTablesTable,
catconstants.PgCatalogTablespaceTableID: pgCatalogTablespaceTable,
catconstants.PgCatalogTimezoneAbbrevsTableID: pgCatalogTimezoneAbbrevsTable,
catconstants.PgCatalogTimezoneNamesTableID: pgCatalogTimezoneNamesTable,
catconstants.PgCatalogTransformTableID: pgCatalogTransformTable,
catconstants.PgCatalogTriggerTableID: pgCatalogTriggerTable,
catconstants.PgCatalogTsConfigMapTableID: pgCatalogTsConfigMapTable,
catconstants.PgCatalogTsConfigTableID: pgCatalogTsConfigTable,
catconstants.PgCatalogTsDictTableID: pgCatalogTsDictTable,
catconstants.PgCatalogTsParserTableID: pgCatalogTsParserTable,
catconstants.PgCatalogTsTemplateTableID: pgCatalogTsTemplateTable,
catconstants.PgCatalogTypeTableID: pgCatalogTypeTable,
catconstants.PgCatalogUserMappingTableID: pgCatalogUserMappingTable,
catconstants.PgCatalogUserMappingsTableID: pgCatalogUserMappingsTable,
catconstants.PgCatalogUserTableID: pgCatalogUserTable,
catconstants.PgCatalogViewsTableID: pgCatalogViewsTable,
},
// Postgres's catalogs are ill-defined when there is no current
// database set. Simply reject any attempts to use them in that
// case.
validWithNoDatabaseContext: false,
containsTypes: true,
}
// The catalog pg_am stores information about relation access methods.
// It's important to note that this table changed drastically between Postgres
// versions 9.5 and 9.6. We currently support both versions of this table.
// See: https://www.postgresql.org/docs/9.5/static/catalog-pg-am.html and
// https://www.postgresql.org/docs/9.6/static/catalog-pg-am.html.
var pgCatalogAmTable = virtualSchemaTable{
comment: `index access methods (incomplete)
https://www.postgresql.org/docs/9.5/catalog-pg-am.html`,
schema: vtable.PGCatalogAm,
populate: func(_ context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
// add row for forward indexes
if err := addRow(
forwardIndexOid, // oid - all versions
tree.NewDName(indexTypeForwardIndex), // amname - all versions
zeroVal, // amstrategies - < v9.6
zeroVal, // amsupport - < v9.6
tree.DBoolTrue, // amcanorder - < v9.6
tree.DBoolFalse, // amcanorderbyop - < v9.6
tree.DBoolTrue, // amcanbackward - < v9.6
tree.DBoolTrue, // amcanunique - < v9.6
tree.DBoolTrue, // amcanmulticol - < v9.6
tree.DBoolTrue, // amoptionalkey - < v9.6
tree.DBoolTrue, // amsearcharray - < v9.6
tree.DBoolTrue, // amsearchnulls - < v9.6
tree.DBoolFalse, // amstorage - < v9.6
tree.DBoolFalse, // amclusterable - < v9.6
tree.DBoolFalse, // ampredlocks - < v9.6
oidZero, // amkeytype - < v9.6
tree.DNull, // aminsert - < v9.6
tree.DNull, // ambeginscan - < v9.6
oidZero, // amgettuple - < v9.6
oidZero, // amgetbitmap - < v9.6
tree.DNull, // amrescan - < v9.6
tree.DNull, // amendscan - < v9.6
tree.DNull, // ammarkpos - < v9.6
tree.DNull, // amrestrpos - < v9.6
tree.DNull, // ambuild - < v9.6
tree.DNull, // ambuildempty - < v9.6
tree.DNull, // ambulkdelete - < v9.6
tree.DNull, // amvacuumcleanup - < v9.6
tree.DNull, // amcanreturn - < v9.6
tree.DNull, // amcostestimate - < v9.6
tree.DNull, // amoptions - < v9.6
tree.DNull, // amhandler - > v9.6
tree.NewDString("i"), // amtype - > v9.6
); err != nil {
return err
}
// add row for inverted indexes
if err := addRow(
invertedIndexOid, // oid - all versions
tree.NewDName(indexTypeInvertedIndex), // amname - all versions
zeroVal, // amstrategies - < v9.6
zeroVal, // amsupport - < v9.6
tree.DBoolFalse, // amcanorder - < v9.6
tree.DBoolFalse, // amcanorderbyop - < v9.6
tree.DBoolFalse, // amcanbackward - < v9.6
tree.DBoolFalse, // amcanunique - < v9.6
tree.DBoolFalse, // amcanmulticol - < v9.6
tree.DBoolFalse, // amoptionalkey - < v9.6
tree.DBoolFalse, // amsearcharray - < v9.6
tree.DBoolTrue, // amsearchnulls - < v9.6
tree.DBoolFalse, // amstorage - < v9.6
tree.DBoolFalse, // amclusterable - < v9.6
tree.DBoolFalse, // ampredlocks - < v9.6
oidZero, // amkeytype - < v9.6
tree.DNull, // aminsert - < v9.6
tree.DNull, // ambeginscan - < v9.6
oidZero, // amgettuple - < v9.6
oidZero, // amgetbitmap - < v9.6
tree.DNull, // amrescan - < v9.6
tree.DNull, // amendscan - < v9.6
tree.DNull, // ammarkpos - < v9.6
tree.DNull, // amrestrpos - < v9.6
tree.DNull, // ambuild - < v9.6
tree.DNull, // ambuildempty - < v9.6
tree.DNull, // ambulkdelete - < v9.6
tree.DNull, // amvacuumcleanup - < v9.6
tree.DNull, // amcanreturn - < v9.6
tree.DNull, // amcostestimate - < v9.6
tree.DNull, // amoptions - < v9.6
tree.DNull, // amhandler - > v9.6
tree.NewDString("i"), // amtype - > v9.6
); err != nil {
return err
}
return nil
},
}
var pgCatalogAttrDefTable = makeAllRelationsVirtualTableWithDescriptorIDIndex(
`column default values
https://www.postgresql.org/docs/9.5/catalog-pg-attrdef.html`,
vtable.PGCatalogAttrDef,
virtualMany, false, /* includesIndexEntries */
func(ctx context.Context, p *planner, h oidHasher,
db catalog.DatabaseDescriptor, sc catalog.SchemaDescriptor, table catalog.TableDescriptor,
lookup simpleSchemaResolver,
addRow func(...tree.Datum) error,
) error {
for _, column := range table.PublicColumns() {
if !column.HasDefault() {
// pg_attrdef only expects rows for columns with default values.
continue
}
displayExpr, err := schemaexpr.FormatExprForDisplay(
ctx, table, column.GetDefaultExpr(), &p.semaCtx, p.SessionData(), tree.FmtPGCatalog,
)
if err != nil {
return err
}
defSrc := tree.NewDString(displayExpr)
if err := addRow(
h.ColumnOid(table.GetID(), column.GetID()), // oid
tableOid(table.GetID()), // adrelid
tree.NewDInt(tree.DInt(column.GetPGAttributeNum())), // adnum
defSrc, // adbin
defSrc, // adsrc
); err != nil {
return err
}
}
return nil
})
var pgCatalogAttributeTable = makeAllRelationsVirtualTableWithDescriptorIDIndex(
`table columns (incomplete - see also information_schema.columns)
https://www.postgresql.org/docs/12/catalog-pg-attribute.html`,
vtable.PGCatalogAttribute,
virtualMany, true, /* includesIndexEntries */
func(ctx context.Context, p *planner, h oidHasher, db catalog.DatabaseDescriptor, sc catalog.SchemaDescriptor,
table catalog.TableDescriptor,
lookup simpleSchemaResolver,
addRow func(...tree.Datum) error,
) error {
// addColumn adds either a table or an index column to the pg_attribute table.
addColumn := func(column catalog.Column, attRelID tree.Datum, attNum uint32) error {
colTyp := column.GetType()
// Sets the attgenerated column to 's' if the column is generated/
// computed stored, "v" if virtual, zero byte otherwise.
var isColumnComputed string
if column.IsComputed() && !column.IsVirtual() {
isColumnComputed = "s"
} else if column.IsComputed() {
isColumnComputed = "v"
} else {
isColumnComputed = ""
}
// Sets the attidentity column to 'a' if the column is generated
// always as identity, "b" if generated by default as identity,
// zero byte otherwise.
var generatedAsIdentityType string
if column.IsGeneratedAsIdentity() {
if column.IsGeneratedAlwaysAsIdentity() {
generatedAsIdentityType = "a"
} else if column.IsGeneratedByDefaultAsIdentity() {
generatedAsIdentityType = "d"
} else {
return errors.AssertionFailedf(
"column %s is of wrong generated as identity type (neither ALWAYS nor BY DEFAULT)",
column.GetName(),
)
}
} else {
generatedAsIdentityType = ""
}
return addRow(
attRelID, // attrelid
tree.NewDName(column.GetName()), // attname
typOid(colTyp), // atttypid
zeroVal, // attstattarget
typLen(colTyp), // attlen
tree.NewDInt(tree.DInt(attNum)), // attnum
zeroVal, // attndims
negOneVal, // attcacheoff
tree.NewDInt(tree.DInt(colTyp.TypeModifier())), // atttypmod
tree.DNull, // attbyval (see pg_type.typbyval)
tree.DNull, // attstorage
tree.DNull, // attalign
tree.MakeDBool(tree.DBool(!column.IsNullable())), // attnotnull
tree.MakeDBool(tree.DBool(column.HasDefault())), // atthasdef
tree.NewDString(generatedAsIdentityType), // attidentity
tree.NewDString(isColumnComputed), // attgenerated
tree.DBoolFalse, // attisdropped
tree.DBoolTrue, // attislocal
zeroVal, // attinhcount
typColl(colTyp, h), // attcollation
tree.DNull, // attacl
tree.DNull, // attoptions
tree.DNull, // attfdwoptions
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // atthasmissing
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // attmissingval
)
}
// Columns for table.
for _, column := range table.AccessibleColumns() {
tableID := tableOid(table.GetID())
if err := addColumn(column, tableID, uint32(column.GetPGAttributeNum())); err != nil {
return err
}
}
// Columns for each index.
columnIdxMap := catalog.ColumnIDToOrdinalMap(table.PublicColumns())
return catalog.ForEachIndex(table, catalog.IndexOpts{}, func(index catalog.Index) error {
idxID := h.IndexOid(table.GetID(), index.GetID())
for i := 0; i < index.NumKeyColumns(); i++ {
colID := index.GetKeyColumnID(i)
column := table.PublicColumns()[columnIdxMap.GetDefault(colID)]
// The attnum for columns in an index is the order it appears in the
// index definition and is not related to the attnum the column has in
// the table.
if err := addColumn(column, idxID, uint32(i+1)); err != nil {
return err
}
}
// pg_attribute only includes stored columns for secondary indexes, not
// for primary indexes
for i := 0; i < index.NumSecondaryStoredColumns(); i++ {
colID := index.GetStoredColumnID(i)
column := table.PublicColumns()[columnIdxMap.GetDefault(colID)]
// The attnum for columns in an index is the order it appears in the
// index definition and is not related to the attnum the column has in
// the table.
if err := addColumn(column, idxID, uint32(i+1+index.NumKeyColumns())); err != nil {
return err
}
}
return nil
})
})
var pgCatalogCastTable = virtualSchemaTable{
comment: `casts (empty - needs filling out)
https://www.postgresql.org/docs/9.6/catalog-pg-cast.html`,
schema: vtable.PGCatalogCast,
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
h := makeOidHasher()
cast.ForEachCast(func(src, tgt oid.Oid, cCtx cast.Context, ctxOrigin cast.ContextOrigin, _ volatility.V) {
if ctxOrigin == cast.ContextOriginPgCast {
castCtx := cCtx.PGString()
castFunc := tree.DNull
if srcTyp, ok := types.OidToType[src]; ok {
if v, ok := builtins.CastBuiltinOIDs[tgt][srcTyp.Family()]; ok {
castFunc = tree.NewDOid(v)
}
}
_ = addRow(
h.CastOid(src, tgt), // oid
tree.NewDOid(src), // cast source
tree.NewDOid(tgt), // casttarget
castFunc, // castfunc
tree.NewDString(castCtx), // castcontext
tree.DNull, // castmethod
)
}
})
return nil
},
}
func userIsSuper(
ctx context.Context, p *planner, userName username.SQLUsername,
) (tree.DBool, error) {
isSuper, err := p.UserHasAdminRole(ctx, userName)
return tree.DBool(isSuper), err
}
var pgCatalogAuthIDTable = virtualSchemaTable{
comment: `authorization identifiers - differs from postgres as we do not display passwords,
and thus do not require admin privileges for access.
https://www.postgresql.org/docs/9.5/catalog-pg-authid.html`,
schema: vtable.PGCatalogAuthID,
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
h := makeOidHasher()
return forEachRole(ctx, p, func(userName username.SQLUsername, isRole bool, options roleOptions, _ tree.Datum) error {
isRoot := tree.DBool(userName.IsRootUser() || userName.IsAdminRole())
// Currently, all users and roles inherit the privileges of roles they are
// members of. See https://github.com/cockroachdb/cockroach/issues/69583.
roleInherits := tree.DBool(true)
noLogin, err := options.noLogin()
if err != nil {
return err
}
roleCanLogin := !noLogin
createDB, err := options.createDB()
if err != nil {
return err
}
rolValidUntil, err := options.validUntil(p)
if err != nil {
return err
}
createRole, err := options.createRole()
if err != nil {
return err
}
isSuper, err := userIsSuper(ctx, p, userName)
if err != nil {
return err
}
return addRow(
h.UserOid(userName), // oid
tree.NewDName(userName.Normalized()), // rolname
tree.MakeDBool(isRoot || isSuper), // rolsuper
tree.MakeDBool(roleInherits), // rolinherit
tree.MakeDBool(isRoot || createRole), // rolcreaterole
tree.MakeDBool(isRoot || createDB), // rolcreatedb
tree.MakeDBool(roleCanLogin), // rolcanlogin.
tree.DBoolFalse, // rolreplication
tree.DBoolFalse, // rolbypassrls
negOneVal, // rolconnlimit
passwdStarString, // rolpassword
rolValidUntil, // rolvaliduntil
)
})
},
}
var pgCatalogAuthMembersTable = virtualSchemaTable{
comment: `role membership
https://www.postgresql.org/docs/9.5/catalog-pg-auth-members.html`,
schema: vtable.PGCatalogAuthMembers,
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
h := makeOidHasher()
return forEachRoleMembership(ctx, p.InternalSQLTxn(),
func(roleName, memberName username.SQLUsername, isAdmin bool) error {
return addRow(
h.UserOid(roleName), // roleid
h.UserOid(memberName), // member
tree.DNull, // grantor
tree.MakeDBool(tree.DBool(isAdmin)), // admin_option
)
})
},
}
var pgCatalogAvailableExtensionsTable = virtualSchemaTable{
comment: `available extensions
https://www.postgresql.org/docs/9.6/view-pg-available-extensions.html`,
schema: vtable.PGCatalogAvailableExtensions,
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
// We support no extensions.
return nil
},
unimplemented: true,
}
func getOwnerOID(ctx context.Context, p *planner, desc catalog.Descriptor) (tree.Datum, error) {
owner, err := p.getOwnerOfPrivilegeObject(ctx, desc)
if err != nil {
return nil, err
}
h := makeOidHasher()
return h.UserOid(owner), nil
}
func getOwnerName(ctx context.Context, p *planner, desc catalog.Descriptor) (tree.Datum, error) {
owner, err := p.getOwnerOfPrivilegeObject(ctx, desc)
if err != nil {
return nil, err
}
return tree.NewDName(owner.Normalized()), nil
}
var (
relKindTable = tree.NewDString("r")
relKindIndex = tree.NewDString("i")
relKindView = tree.NewDString("v")
relKindMaterializedView = tree.NewDString("m")
relKindSequence = tree.NewDString("S")
relPersistencePermanent = tree.NewDString("p")
relPersistenceTemporary = tree.NewDString("t")
)
var pgCatalogClassTable = makeAllRelationsVirtualTableWithDescriptorIDIndex(
`tables and relation-like objects (incomplete - see also information_schema.tables/sequences/views)
https://www.postgresql.org/docs/9.5/catalog-pg-class.html`,
vtable.PGCatalogClass,
virtualMany, true, /* includesIndexEntries */
func(ctx context.Context, p *planner, h oidHasher, db catalog.DatabaseDescriptor, sc catalog.SchemaDescriptor,
table catalog.TableDescriptor, _ simpleSchemaResolver, addRow func(...tree.Datum) error,
) error {
// The only difference between tables, views and sequences are the relkind and relam columns.
relKind := relKindTable
relAm := forwardIndexOid
if table.IsView() {
relKind = relKindView
if table.MaterializedView() {
relKind = relKindMaterializedView
}
relAm = oidZero
} else if table.IsSequence() {
relKind = relKindSequence
relAm = oidZero
}
relPersistence := relPersistencePermanent
if table.IsTemporary() {
relPersistence = relPersistenceTemporary
}
var relOptions tree.Datum = tree.DNull
if storageParams := table.GetStorageParams(false /* spaceBetweenEqual */); len(storageParams) > 0 {
relOptionsArr := tree.NewDArray(types.String)
for _, storageParam := range storageParams {
if err := relOptionsArr.Append(tree.NewDString(storageParam)); err != nil {
return err
}
}
relOptions = relOptionsArr
}
ownerOid, err := getOwnerOID(ctx, p, table)
if err != nil {
return err
}
implicitTypOID := typedesc.TableIDToImplicitTypeOID(table.GetID())
namespaceOid := schemaOid(sc.GetID())
if err := addRow(
tableOid(table.GetID()), // oid
tree.NewDName(table.GetName()), // relname
namespaceOid, // relnamespace
tree.NewDOid(implicitTypOID), // reltype (PG creates a composite type in pg_type for each table)
oidZero, // reloftype (used for type tables, which is unsupported)
ownerOid, // relowner
relAm, // relam
oidZero, // relfilenode
oidZero, // reltablespace
tree.DNull, // relpages
tree.DNull, // reltuples
zeroVal, // relallvisible
oidZero, // reltoastrelid
tree.MakeDBool(tree.DBool(table.IsPhysicalTable())), // relhasindex
tree.DBoolFalse, // relisshared
relPersistence, // relpersistence
tree.MakeDBool(tree.DBool(table.IsTemporary())), // relistemp
relKind, // relkind
tree.NewDInt(tree.DInt(len(table.AccessibleColumns()))), // relnatts
tree.NewDInt(tree.DInt(len(table.EnforcedCheckConstraints()))), // relchecks
tree.DBoolFalse, // relhasoids
tree.MakeDBool(tree.DBool(table.IsPhysicalTable())), // relhaspkey
tree.DBoolFalse, // relhasrules
tree.DBoolFalse, // relhastriggers
tree.DBoolFalse, // relhassubclass
zeroVal, // relfrozenxid
tree.DNull, // relacl
relOptions, // reloptions
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // relforcerowsecurity
tree.DNull, // relispartition
tree.DNull, // relispopulated
tree.DNull, // relreplident
tree.DNull, // relrewrite
tree.DNull, // relrowsecurity
tree.DNull, // relpartbound
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // relminmxid
); err != nil {
return err
}
// Skip adding indexes for sequences (their table descriptors have a primary
// index to make them comprehensible to backup/restore, but PG doesn't include
// an index in pg_class).
if table.IsSequence() {
return nil
}
// Indexes.
return catalog.ForEachIndex(table, catalog.IndexOpts{}, func(index catalog.Index) error {
indexType := forwardIndexOid
if index.GetType() == descpb.IndexDescriptor_INVERTED {
indexType = invertedIndexOid
}
ownerOid, err := getOwnerOID(ctx, p, table)
if err != nil {
return err
}
return addRow(
h.IndexOid(table.GetID(), index.GetID()), // oid
tree.NewDName(index.GetName()), // relname
namespaceOid, // relnamespace
oidZero, // reltype
oidZero, // reloftype
ownerOid, // relowner
indexType, // relam
oidZero, // relfilenode
oidZero, // reltablespace
tree.DNull, // relpages
tree.DNull, // reltuples
zeroVal, // relallvisible
oidZero, // reltoastrelid
tree.DBoolFalse, // relhasindex
tree.DBoolFalse, // relisshared
relPersistencePermanent, // relPersistence
tree.DBoolFalse, // relistemp
relKindIndex, // relkind
tree.NewDInt(tree.DInt(index.NumKeyColumns())), // relnatts
zeroVal, // relchecks
tree.DBoolFalse, // relhasoids
tree.DBoolFalse, // relhaspkey
tree.DBoolFalse, // relhasrules
tree.DBoolFalse, // relhastriggers
tree.DBoolFalse, // relhassubclass
zeroVal, // relfrozenxid
tree.DNull, // relacl
tree.DNull, // reloptions
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // relforcerowsecurity
tree.DNull, // relispartition
tree.DNull, // relispopulated
tree.DNull, // relreplident
tree.DNull, // relrewrite
tree.DNull, // relrowsecurity
tree.DNull, // relpartbound
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // relminmxid
)
})
})
var pgCatalogCollationTable = virtualSchemaTable{
comment: `available collations (incomplete)
https://www.postgresql.org/docs/9.5/catalog-pg-collation.html`,
schema: vtable.PGCatalogCollation,
populate: func(ctx context.Context, p *planner, dbContext catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
h := makeOidHasher()
return forEachDatabaseDesc(ctx, p, dbContext, false /* requiresPrivileges */, func(db catalog.DatabaseDescriptor) error {
namespaceOid := tree.NewDOid(catconstants.PgCatalogID)
add := func(collName string) error {
return addRow(
h.CollationOid(collName), // oid
tree.NewDString(collName), // collname
namespaceOid, // collnamespace
tree.DNull, // collowner
builtins.DatEncodingUTFId, // collencoding
// It's not clear how to translate a Go collation tag into the format
// required by LC_COLLATE and LC_CTYPE.
tree.DNull, // collcollate
tree.DNull, // collctype
// These columns were automatically created by pg_catalog_test's missing column generator.
tree.DNull, // collprovider
tree.DNull, // collversion
tree.DNull, // collisdeterministic
)
}
for _, tag := range collatedstring.Supported() {
if err := add(tag); err != nil {
return err
}
}
return nil
})
},
}
var (
conTypeCheck = tree.NewDString("c")
conTypeFK = tree.NewDString("f")
conTypePKey = tree.NewDString("p")
conTypeUnique = tree.NewDString("u")
conTypeTrigger = tree.NewDString("t")
conTypeExclusion = tree.NewDString("x")
// Avoid unused warning for constants.
_ = conTypeTrigger
_ = conTypeExclusion
fkActionNone = tree.NewDString("a")
fkActionRestrict = tree.NewDString("r")
fkActionCascade = tree.NewDString("c")
fkActionSetNull = tree.NewDString("n")
fkActionSetDefault = tree.NewDString("d")
fkActionMap = map[semenumpb.ForeignKeyAction]tree.Datum{
semenumpb.ForeignKeyAction_NO_ACTION: fkActionNone,
semenumpb.ForeignKeyAction_RESTRICT: fkActionRestrict,
semenumpb.ForeignKeyAction_CASCADE: fkActionCascade,
semenumpb.ForeignKeyAction_SET_NULL: fkActionSetNull,
semenumpb.ForeignKeyAction_SET_DEFAULT: fkActionSetDefault,
}
fkMatchTypeFull = tree.NewDString("f")
fkMatchTypePartial = tree.NewDString("p")
fkMatchTypeSimple = tree.NewDString("s")
fkMatchMap = map[semenumpb.Match]tree.Datum{
semenumpb.Match_SIMPLE: fkMatchTypeSimple,
semenumpb.Match_FULL: fkMatchTypeFull,
semenumpb.Match_PARTIAL: fkMatchTypePartial,
}
)
func populateTableConstraints(
ctx context.Context,
p *planner,
h oidHasher,
db catalog.DatabaseDescriptor,
sc catalog.SchemaDescriptor,
table catalog.TableDescriptor,
tableLookup simpleSchemaResolver,
addRow func(...tree.Datum) error,
) error {
namespaceOid := schemaOid(sc.GetID())
tblOid := tableOid(table.GetID())
for _, c := range table.AllConstraints() {
conoid := tree.DNull
contype := tree.DNull
conindid := oidZero
confrelid := oidZero
confupdtype := tree.DNull
confdeltype := tree.DNull
confmatchtype := tree.DNull
conkey := tree.DNull
confkey := tree.DNull
consrc := tree.DNull
conbin := tree.DNull
condef := tree.DNull
// Determine constraint kind-specific fields.
var err error
if uwi := c.AsUniqueWithIndex(); uwi != nil {
conindid = h.IndexOid(table.GetID(), uwi.GetID())
var err error
if conkey, err = colIDArrayToDatum(uwi.IndexDesc().KeyColumnIDs); err != nil {
return err
}
if uwi.Primary() {
if !p.SessionData().ShowPrimaryKeyConstraintOnNotVisibleColumns {
allHidden := true
for _, col := range table.IndexKeyColumns(uwi) {
if !col.IsHidden() {
allHidden = false
break
}
}
if allHidden {
continue
}
}
conoid = h.PrimaryKeyConstraintOid(db.GetID(), sc.GetID(), table.GetID(), uwi)
contype = conTypePKey
condef = tree.NewDString(tabledesc.PrimaryKeyString(table))
} else {
f := tree.NewFmtCtx(tree.FmtSimple)
conoid = h.UniqueConstraintOid(db.GetID(), sc.GetID(), table.GetID(), uwi)
contype = conTypeUnique
f.WriteString("UNIQUE (")
if err := catformat.FormatIndexElements(
ctx, table, uwi.IndexDesc(), f, p.SemaCtx(), p.SessionData(),
); err != nil {
return err
}
f.WriteByte(')')
if uwi.IsPartial() {
pred, err := schemaexpr.FormatExprForDisplay(ctx, table, uwi.GetPredicate(), p.SemaCtx(), p.SessionData(), tree.FmtPGCatalog)
if err != nil {
return err
}
f.WriteString(fmt.Sprintf(" WHERE (%s)", pred))
}
condef = tree.NewDString(f.CloseAndGetString())
}
} else if fk := c.AsForeignKey(); fk != nil {
conoid = h.ForeignKeyConstraintOid(db.GetID(), sc.GetID(), table.GetID(), fk)
contype = conTypeFK
// Foreign keys don't have a single linked index. Pick the first one
// that matches on the referenced table.
referencedTable, err := tableLookup.getTableByID(fk.GetReferencedTableID())
if err != nil {
return err
}
if refConstraint, err := catalog.FindFKReferencedUniqueConstraint(referencedTable, fk); err != nil {
// We couldn't find a unique constraint that matched. This shouldn't
// happen.
log.Warningf(ctx, "broken fk reference: %v", err)
} else if idx := refConstraint.AsUniqueWithIndex(); idx != nil {
conindid = h.IndexOid(referencedTable.GetID(), idx.GetID())
}
confrelid = tableOid(referencedTable.GetID())
if r, ok := fkActionMap[fk.OnUpdate()]; ok {
confupdtype = r
}
if r, ok := fkActionMap[fk.OnDelete()]; ok {
confdeltype = r
}
if r, ok := fkMatchMap[fk.Match()]; ok {
confmatchtype = r
}
if conkey, err = colIDArrayToDatum(fk.ForeignKeyDesc().OriginColumnIDs); err != nil {
return err
}
if confkey, err = colIDArrayToDatum(fk.ForeignKeyDesc().ReferencedColumnIDs); err != nil {
return err
}
var buf bytes.Buffer
if err := showForeignKeyConstraint(
&buf, db.GetName(),
table, fk.ForeignKeyDesc(),
tableLookup,
p.extendedEvalCtx.SessionData().SearchPath,
); err != nil {
return err
}
condef = tree.NewDString(buf.String())
} else if uwoi := c.AsUniqueWithoutIndex(); uwoi != nil {
contype = conTypeUnique
f := tree.NewFmtCtx(tree.FmtSimple)
conoid = h.UniqueWithoutIndexConstraintOid(
db.GetID(), sc.GetID(), table.GetID(), uwoi,
)
f.WriteString("UNIQUE WITHOUT INDEX (")
colNames, err := catalog.ColumnNamesForIDs(table, uwoi.UniqueWithoutIndexDesc().ColumnIDs)
if err != nil {
return err
}
f.WriteString(strings.Join(colNames, ", "))
f.WriteByte(')')
if !uwoi.IsConstraintValidated() {
f.WriteString(" NOT VALID")
}
if uwoi.GetPredicate() != "" {
pred, err := schemaexpr.FormatExprForDisplay(ctx, table, uwoi.GetPredicate(), p.SemaCtx(), p.SessionData(), tree.FmtPGCatalog)