@@ -21,6 +21,13 @@ init(void)
2121LWLockRelease (load_config_lock );
2222}
2323
24+ static bool
25+ check_extension ()
26+ {
27+ SPI_exec ("SELECT * FROM pg_extension WHERE extname = 'pathman'" ,0 );
28+ return SPI_processed > 0 ;
29+ }
30+
2431void
2532load_part_relations_hashtable ()
2633{
@@ -32,61 +39,65 @@ load_part_relations_hashtable()
3239List * part_oids = NIL ;
3340ListCell * lc ;
3441
35- /* if hashtable is empty */
36- // if (hash_get_num_entries(relations) == 0)
37- // {
38- SPI_connect ();
39- ret = SPI_exec ("SELECT pg_class.relfilenode, pg_attribute.attnum, pg_pathman_rels.parttype, pg_attribute.atttypid "
40- "FROM pg_pathman_rels "
41- "JOIN pg_class ON pg_class.relname = pg_pathman_rels.relname "
42- "JOIN pg_attribute ON pg_attribute.attname = pg_pathman_rels.attname "
43- "AND attrelid = pg_class.relfilenode" ,0 );
44- proc = SPI_processed ;
45-
46- if (ret > 0 && SPI_tuptable != NULL )
47- {
48- TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
49- SPITupleTable * tuptable = SPI_tuptable ;
50-
51- for (i = 0 ;i < proc ;i ++ )
52- {
53- HeapTuple tuple = tuptable -> vals [i ];
42+ SPI_connect ();
5443
55- int oid = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,1 ,& isnull ));
56- prinfo = (PartRelationInfo * )
57- hash_search (relations , (const void * )& oid ,HASH_ENTER ,NULL );
58- prinfo -> oid = oid ;
59- prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
60- prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
61- prinfo -> atttype = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,4 ,& isnull ));
44+ /* if extension wasn't created then just quit */
45+ if (!check_extension ())
46+ {
47+ SPI_finish ();
48+ return ;
49+ }
6250
63- part_oids = lappend_int (part_oids ,oid );
51+ ret = SPI_exec ("SELECT pg_class.relfilenode, pg_attribute.attnum, pg_pathman_rels.parttype, pg_attribute.atttypid "
52+ "FROM pg_pathman_rels "
53+ "JOIN pg_class ON pg_class.relname = pg_pathman_rels.relname "
54+ "JOIN pg_attribute ON pg_attribute.attname = pg_pathman_rels.attname "
55+ "AND attrelid = pg_class.relfilenode" ,0 );
56+ proc = SPI_processed ;
6457
65- /* children will be filled in later */
66- // prinfo->children = NIL;
67- }
68- }
58+ if ( ret > 0 && SPI_tuptable != NULL )
59+ {
60+ TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
61+ SPITupleTable * tuptable = SPI_tuptable ;
6962
70- /* load children information */
71- foreach (lc ,part_oids )
63+ for (i = 0 ;i < proc ;i ++ )
7264{
73- Oid oid = ( int ) lfirst_int ( lc ) ;
65+ HeapTuple tuple = tuptable -> vals [ i ] ;
7466
67+ int oid = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,1 ,& isnull ));
7568prinfo = (PartRelationInfo * )
76- hash_search (relations , (const void * )& oid ,HASH_FIND ,NULL );
69+ hash_search (relations , (const void * )& oid ,HASH_ENTER ,NULL );
70+ prinfo -> oid = oid ;
71+ prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
72+ prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
73+ prinfo -> atttype = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,4 ,& isnull ));
7774
78- switch (prinfo -> parttype )
79- {
80- case PT_RANGE :
81- load_range_restrictions (oid );
82- break ;
83- case PT_HASH :
84- load_hash_restrictions (oid );
85- break ;
86- }
75+ part_oids = lappend_int (part_oids ,oid );
76+
77+ /* children will be filled in later */
78+ // prinfo->children = NIL;
8779}
88- SPI_finish ();
89- // }
80+ }
81+
82+ /* load children information */
83+ foreach (lc ,part_oids )
84+ {
85+ Oid oid = (int )lfirst_int (lc );
86+
87+ prinfo = (PartRelationInfo * )
88+ hash_search (relations , (const void * )& oid ,HASH_FIND ,NULL );
89+
90+ switch (prinfo -> parttype )
91+ {
92+ case PT_RANGE :
93+ load_range_restrictions (oid );
94+ break ;
95+ case PT_HASH :
96+ load_hash_restrictions (oid );
97+ break ;
98+ }
99+ }
100+ SPI_finish ();
90101}
91102
92103void