@@ -37,13 +37,16 @@ use crate::error::{
37
37
use crate :: information_schema:: { InformationTable , Predicates } ;
38
38
use crate :: CatalogManager ;
39
39
40
- const CONSTRAINT_SCHEMA : & str = "constraint_schema" ;
41
- const CONSTRAINT_NAME : & str = "constraint_name" ;
42
- const TABLE_CATALOG : & str = "table_catalog" ;
43
- const TABLE_SCHEMA : & str = "table_schema" ;
44
- const TABLE_NAME : & str = "table_name" ;
45
- const COLUMN_NAME : & str = "column_name" ;
46
- const ORDINAL_POSITION : & str = "ordinal_position" ;
40
+ pub const CONSTRAINT_SCHEMA : & str = "constraint_schema" ;
41
+ pub const CONSTRAINT_NAME : & str = "constraint_name" ;
42
+ // It's always `def` in MySQL
43
+ pub const TABLE_CATALOG : & str = "table_catalog" ;
44
+ // The real catalog name for this key column.
45
+ pub const REAL_TABLE_CATALOG : & str = "real_table_catalog" ;
46
+ pub const TABLE_SCHEMA : & str = "table_schema" ;
47
+ pub const TABLE_NAME : & str = "table_name" ;
48
+ pub const COLUMN_NAME : & str = "column_name" ;
49
+ pub const ORDINAL_POSITION : & str = "ordinal_position" ;
47
50
const INIT_CAPACITY : usize = 42 ;
48
51
49
52
/// The virtual table implementation for `information_schema.KEY_COLUMN_USAGE`.
@@ -76,6 +79,11 @@ impl InformationSchemaKeyColumnUsage {
76
79
) ,
77
80
ColumnSchema :: new( CONSTRAINT_NAME , ConcreteDataType :: string_datatype( ) , false ) ,
78
81
ColumnSchema :: new( TABLE_CATALOG , ConcreteDataType :: string_datatype( ) , false ) ,
82
+ ColumnSchema :: new(
83
+ REAL_TABLE_CATALOG ,
84
+ ConcreteDataType :: string_datatype( ) ,
85
+ false ,
86
+ ) ,
79
87
ColumnSchema :: new( TABLE_SCHEMA , ConcreteDataType :: string_datatype( ) , false ) ,
80
88
ColumnSchema :: new( TABLE_NAME , ConcreteDataType :: string_datatype( ) , false ) ,
81
89
ColumnSchema :: new( COLUMN_NAME , ConcreteDataType :: string_datatype( ) , false ) ,
@@ -158,6 +166,7 @@ struct InformationSchemaKeyColumnUsageBuilder {
158
166
constraint_schema : StringVectorBuilder ,
159
167
constraint_name : StringVectorBuilder ,
160
168
table_catalog : StringVectorBuilder ,
169
+ real_table_catalog : StringVectorBuilder ,
161
170
table_schema : StringVectorBuilder ,
162
171
table_name : StringVectorBuilder ,
163
172
column_name : StringVectorBuilder ,
@@ -179,6 +188,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
179
188
constraint_schema : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
180
189
constraint_name : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
181
190
table_catalog : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
191
+ real_table_catalog : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
182
192
table_schema : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
183
193
table_name : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
184
194
column_name : StringVectorBuilder :: with_capacity ( INIT_CAPACITY ) ,
@@ -223,6 +233,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
223
233
& predicates,
224
234
& schema_name,
225
235
"TIME INDEX" ,
236
+ & catalog_name,
226
237
& schema_name,
227
238
& table_name,
228
239
& column. name ,
@@ -231,6 +242,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
231
242
}
232
243
if keys. contains ( & idx) {
233
244
primary_constraints. push ( (
245
+ catalog_name. clone ( ) ,
234
246
schema_name. clone ( ) ,
235
247
table_name. clone ( ) ,
236
248
column. name . clone ( ) ,
@@ -244,13 +256,14 @@ impl InformationSchemaKeyColumnUsageBuilder {
244
256
}
245
257
}
246
258
247
- for ( i, ( schema_name, table_name, column_name) ) in
259
+ for ( i, ( catalog_name , schema_name, table_name, column_name) ) in
248
260
primary_constraints. into_iter ( ) . enumerate ( )
249
261
{
250
262
self . add_key_column_usage (
251
263
& predicates,
252
264
& schema_name,
253
265
"PRIMARY" ,
266
+ & catalog_name,
254
267
& schema_name,
255
268
& table_name,
256
269
& column_name,
@@ -269,6 +282,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
269
282
predicates : & Predicates ,
270
283
constraint_schema : & str ,
271
284
constraint_name : & str ,
285
+ table_catalog : & str ,
272
286
table_schema : & str ,
273
287
table_name : & str ,
274
288
column_name : & str ,
@@ -277,6 +291,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
277
291
let row = [
278
292
( CONSTRAINT_SCHEMA , & Value :: from ( constraint_schema) ) ,
279
293
( CONSTRAINT_NAME , & Value :: from ( constraint_name) ) ,
294
+ ( REAL_TABLE_CATALOG , & Value :: from ( table_catalog) ) ,
280
295
( TABLE_SCHEMA , & Value :: from ( table_schema) ) ,
281
296
( TABLE_NAME , & Value :: from ( table_name) ) ,
282
297
( COLUMN_NAME , & Value :: from ( column_name) ) ,
@@ -291,6 +306,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
291
306
self . constraint_schema . push ( Some ( constraint_schema) ) ;
292
307
self . constraint_name . push ( Some ( constraint_name) ) ;
293
308
self . table_catalog . push ( Some ( "def" ) ) ;
309
+ self . real_table_catalog . push ( Some ( table_catalog) ) ;
294
310
self . table_schema . push ( Some ( table_schema) ) ;
295
311
self . table_name . push ( Some ( table_name) ) ;
296
312
self . column_name . push ( Some ( column_name) ) ;
@@ -310,6 +326,7 @@ impl InformationSchemaKeyColumnUsageBuilder {
310
326
Arc :: new( self . constraint_schema. finish( ) ) ,
311
327
Arc :: new( self . constraint_name. finish( ) ) ,
312
328
Arc :: new( self . table_catalog. finish( ) ) ,
329
+ Arc :: new( self . real_table_catalog. finish( ) ) ,
313
330
Arc :: new( self . table_schema. finish( ) ) ,
314
331
Arc :: new( self . table_name. finish( ) ) ,
315
332
Arc :: new( self . column_name. finish( ) ) ,
0 commit comments