@@ -79,6 +79,7 @@ typedef struct pg_indexEntry
79
79
{
80
80
Oid indexrelid ;
81
81
char * name ;
82
+ char * namespace ;
82
83
bool heapallindexed_is_supported ;
83
84
/* schema where amcheck extention is located */
84
85
char * amcheck_nspname ;
@@ -98,6 +99,8 @@ pg_indexEntry_free(void *index)
98
99
99
100
if (index_ptr -> name )
100
101
free (index_ptr -> name );
102
+ if (index_ptr -> name )
103
+ free (index_ptr -> namespace );
101
104
if (index_ptr -> amcheck_nspname )
102
105
free (index_ptr -> amcheck_nspname );
103
106
@@ -324,7 +327,7 @@ check_indexes(void *arg)
324
327
if (progress )
325
328
elog (INFO , "Thread [%d]. Progress: (%d/%d). Amchecking index '%s.%s'" ,
326
329
arguments -> thread_num , i + 1 , n_indexes ,
327
- ind -> amcheck_nspname , ind -> name );
330
+ ind -> namespace , ind -> name );
328
331
329
332
if (arguments -> conn_arg .conn == NULL )
330
333
{
@@ -362,7 +365,7 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
362
365
PGconn * db_conn )
363
366
{
364
367
PGresult * res ;
365
- char * nspname = NULL ;
368
+ char * amcheck_nspname = NULL ;
366
369
int i ;
367
370
bool heapallindexed_is_supported = false;
368
371
parray * index_list = NULL ;
@@ -391,8 +394,8 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
391
394
return NULL ;
392
395
}
393
396
394
- nspname = pgut_malloc (strlen (PQgetvalue (res , 0 , 1 )) + 1 );
395
- strcpy (nspname , PQgetvalue (res , 0 , 1 ));
397
+ amcheck_nspname = pgut_malloc (strlen (PQgetvalue (res , 0 , 1 )) + 1 );
398
+ strcpy (amcheck_nspname , PQgetvalue (res , 0 , 1 ));
396
399
397
400
/* heapallindexed_is_supported is database specific */
398
401
if (strcmp (PQgetvalue (res , 0 , 2 ), "1.0" ) != 0 &&
@@ -419,24 +422,28 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
419
422
if (first_db_with_amcheck )
420
423
{
421
424
422
- res = pgut_execute (db_conn , "SELECT cls.oid, cls.relname "
423
- "FROM pg_index idx "
424
- "JOIN pg_class cls ON idx.indexrelid=cls.oid "
425
- "JOIN pg_am am ON cls.relam=am.oid "
426
- "WHERE am.amname='btree' AND cls.relpersistence != 't'" ,
425
+ res = pgut_execute (db_conn , "SELECT cls.oid, cls.relname, nmspc.nspname "
426
+ "FROM pg_catalog.pg_index idx "
427
+ "LEFT JOIN pg_catalog.pg_class cls ON idx.indexrelid=cls.oid "
428
+ "LEFT JOIN pg_catalog.pg_namespace nmspc ON cls.relnamespace=nmspc.oid "
429
+ "LEFT JOIN pg_catalog.pg_am am ON cls.relam=am.oid "
430
+ "WHERE am.amname='btree' AND cls.relpersistence != 't' "
431
+ "ORDER BY nmspc.nspname DESC" ,
427
432
0 , NULL );
428
433
}
429
434
else
430
435
{
431
436
432
- res = pgut_execute (db_conn , "SELECT cls.oid, cls.relname "
433
- "FROM pg_index idx "
434
- "JOIN pg_class cls ON idx.indexrelid=cls.oid "
435
- "JOIN pg_am am ON cls.relam=am.oid "
436
- "LEFT JOIN pg_tablespace tbl "
437
- "ON cls.reltablespace=tbl.oid "
438
- "AND tbl.spcname <> 'pg_global' "
439
- "WHERE am.amname='btree' AND cls.relpersistence != 't'" ,
437
+ res = pgut_execute (db_conn , "SELECT cls.oid, cls.relname, nmspc.nspname "
438
+ "FROM pg_catalog.pg_index idx "
439
+ "LEFT JOIN pg_catalog.pg_class cls ON idx.indexrelid=cls.oid "
440
+ "LEFT JOIN pg_catalog.pg_namespace nmspc ON cls.relnamespace=nmspc.oid "
441
+ "LEFT JOIN pg_catalog.pg_am am ON cls.relam=am.oid "
442
+ "WHERE am.amname='btree' AND cls.relpersistence != 't' AND "
443
+ "(cls.reltablespace IN "
444
+ "(SELECT oid from pg_catalog.pg_tablespace where spcname <> 'pg_global') "
445
+ "OR cls.reltablespace = 0) "
446
+ "ORDER BY nmspc.nspname DESC" ,
440
447
0 , NULL );
441
448
}
442
449
@@ -445,15 +452,24 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
445
452
{
446
453
pg_indexEntry * ind = (pg_indexEntry * ) pgut_malloc (sizeof (pg_indexEntry ));
447
454
char * name = NULL ;
455
+ char * namespace = NULL ;
448
456
457
+ /* index oid */
449
458
ind -> indexrelid = atoi (PQgetvalue (res , i , 0 ));
459
+
460
+ /* index relname */
450
461
name = PQgetvalue (res , i , 1 );
451
462
ind -> name = pgut_malloc (strlen (name ) + 1 );
452
463
strcpy (ind -> name , name ); /* enough buffer size guaranteed */
453
464
465
+ /* index namespace */
466
+ namespace = PQgetvalue (res , i , 2 );
467
+ ind -> namespace = pgut_malloc (strlen (namespace ) + 1 );
468
+ strcpy (ind -> namespace , namespace ); /* enough buffer size guaranteed */
469
+
454
470
ind -> heapallindexed_is_supported = heapallindexed_is_supported ;
455
- ind -> amcheck_nspname = pgut_malloc (strlen (nspname ) + 1 );
456
- strcpy (ind -> amcheck_nspname , nspname );
471
+ ind -> amcheck_nspname = pgut_malloc (strlen (amcheck_nspname ) + 1 );
472
+ strcpy (ind -> amcheck_nspname , amcheck_nspname );
457
473
pg_atomic_clear_flag (& ind -> lock );
458
474
459
475
if (index_list == NULL )
@@ -509,7 +525,7 @@ amcheck_one_index(check_indexes_arg *arguments,
509
525
{
510
526
elog (WARNING , "Thread [%d]. Amcheck failed in database '%s' for index: '%s.%s': %s" ,
511
527
arguments -> thread_num , arguments -> conn_opt .pgdatabase ,
512
- ind -> amcheck_nspname , ind -> name , PQresultErrorMessage (res ));
528
+ ind -> namespace , ind -> name , PQresultErrorMessage (res ));
513
529
514
530
pfree (params [0 ]);
515
531
pfree (query );
@@ -519,7 +535,7 @@ amcheck_one_index(check_indexes_arg *arguments,
519
535
else
520
536
elog (LOG , "Thread [%d]. Amcheck succeeded in database '%s' for index: '%s.%s'" ,
521
537
arguments -> thread_num ,
522
- arguments -> conn_opt .pgdatabase , ind -> amcheck_nspname , ind -> name );
538
+ arguments -> conn_opt .pgdatabase , ind -> namespace , ind -> name );
523
539
524
540
pfree (params [0 ]);
525
541
pfree (query );
0 commit comments