@@ -79,6 +79,7 @@ typedef struct pg_indexEntry
7979{
8080Oid indexrelid ;
8181char * name ;
82+ char * namespace ;
8283bool heapallindexed_is_supported ;
8384/* schema where amcheck extention is located */
8485char * amcheck_nspname ;
@@ -98,6 +99,8 @@ pg_indexEntry_free(void *index)
9899
99100if (index_ptr -> name )
100101free (index_ptr -> name );
102+ if (index_ptr -> name )
103+ free (index_ptr -> namespace );
101104if (index_ptr -> amcheck_nspname )
102105free (index_ptr -> amcheck_nspname );
103106
@@ -324,7 +327,7 @@ check_indexes(void *arg)
324327if (progress )
325328elog (INFO ,"Thread [%d]. Progress: (%d/%d). Amchecking index '%s.%s'" ,
326329arguments -> thread_num ,i + 1 ,n_indexes ,
327- ind -> amcheck_nspname ,ind -> name );
330+ ind -> namespace ,ind -> name );
328331
329332if (arguments -> conn_arg .conn == NULL )
330333{
@@ -362,7 +365,7 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
362365PGconn * db_conn )
363366{
364367PGresult * res ;
365- char * nspname = NULL ;
368+ char * amcheck_nspname = NULL ;
366369int i ;
367370bool heapallindexed_is_supported = false;
368371parray * index_list = NULL ;
@@ -391,8 +394,8 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
391394return NULL ;
392395}
393396
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 ));
396399
397400/* heapallindexed_is_supported is database specific */
398401if (strcmp (PQgetvalue (res ,0 ,2 ),"1.0" )!= 0 &&
@@ -419,24 +422,28 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
419422if (first_db_with_amcheck )
420423{
421424
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" ,
4274320 ,NULL );
428433}
429434else
430435{
431436
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" ,
4404470 ,NULL );
441448}
442449
@@ -445,15 +452,24 @@ get_index_list(const char *dbname, bool first_db_with_amcheck,
445452{
446453pg_indexEntry * ind = (pg_indexEntry * )pgut_malloc (sizeof (pg_indexEntry ));
447454char * name = NULL ;
455+ char * namespace = NULL ;
448456
457+ /* index oid */
449458ind -> indexrelid = atoi (PQgetvalue (res ,i ,0 ));
459+
460+ /* index relname */
450461name = PQgetvalue (res ,i ,1 );
451462ind -> name = pgut_malloc (strlen (name )+ 1 );
452463strcpy (ind -> name ,name );/* enough buffer size guaranteed */
453464
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+
454470ind -> 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 );
457473pg_atomic_clear_flag (& ind -> lock );
458474
459475if (index_list == NULL )
@@ -509,7 +525,7 @@ amcheck_one_index(check_indexes_arg *arguments,
509525{
510526elog (WARNING ,"Thread [%d]. Amcheck failed in database '%s' for index: '%s.%s': %s" ,
511527arguments -> thread_num ,arguments -> conn_opt .pgdatabase ,
512- ind -> amcheck_nspname ,ind -> name ,PQresultErrorMessage (res ));
528+ ind -> namespace ,ind -> name ,PQresultErrorMessage (res ));
513529
514530pfree (params [0 ]);
515531pfree (query );
@@ -519,7 +535,7 @@ amcheck_one_index(check_indexes_arg *arguments,
519535else
520536elog (LOG ,"Thread [%d]. Amcheck succeeded in database '%s' for index: '%s.%s'" ,
521537arguments -> thread_num ,
522- arguments -> conn_opt .pgdatabase ,ind -> amcheck_nspname ,ind -> name );
538+ arguments -> conn_opt .pgdatabase ,ind -> namespace ,ind -> name );
523539
524540pfree (params [0 ]);
525541pfree (query );