Skip to content

Commit 2f38bd2

Browse files
committed
* bugs fixed
* Makefile: "make check" fixed * schema-qualified names arent mandatory anymore
1 parent 702d966 commit 2f38bd2

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ endif
2424

2525
$(EXTENSION)--$(EXTVERSION).sql: sql/init.sql sql/hash.sql sql/range.sql
2626
cat $^ > $@
27+
check: EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add

conf.add

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shared_preload_libraries='pathman'

expected/pathman.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ NOTICE: function test.hash_rel_hash_update_trigger_func() does not exist, skipp
333333
(1 row)
334334

335335
DROP TABLE test.hash_rel CASCADE;
336-
NOTICE: drop cascades to 3 other objects
337336
SELECT pathman.drop_range_partitions('test.num_range_rel');
338337
drop_range_partitions
339338
-----------------------

init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ get_extension_schema()
4949
bool isnull;
5050

5151
ret = SPI_exec("SELECT extnamespace::regnamespace::text FROM pg_extension WHERE extname = 'pathman'", 0);
52-
if (ret > 0 && SPI_tuptable != NULL)
52+
if (ret > 0 && SPI_tuptable != NULL && SPI_processed > 0)
5353
{
5454
TupleDesc tupdesc = SPI_tuptable->tupdesc;
5555
SPITupleTable *tuptable = SPI_tuptable;
@@ -295,7 +295,7 @@ load_check_constraints(Oid parent_oid)
295295
{
296296
if (ranges[i].max > ranges[i+1].min)
297297
{
298-
elog(WARNING, "Partitions %u and %u overlap. Disabling pathman for relation %u..",
298+
elog(WARNING, "Partitions %u and %u overlap. Disabling pathman for relation %u...",
299299
ranges[i].child_oid, ranges[i+1].child_oid, parent_oid);
300300
hash_search(relations, (const void *) &parent_oid, HASH_REMOVE, &found);
301301
}

pathman.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pathman.h"
22
#include "postgres.h"
33
#include "fmgr.h"
4+
#include "miscadmin.h"
45
#include "nodes/nodeFuncs.h"
56
#include "nodes/pg_list.h"
67
#include "nodes/relation.h"
@@ -100,6 +101,14 @@ static void set_pathkeys(PlannerInfo *root, RelOptInfo *childrel, Path *path);
100101
void
101102
_PG_init(void)
102103
{
104+
if (IsUnderPostmaster)
105+
{
106+
elog(ERROR, "Pathman module must be initialized in postmaster. "
107+
"Put the following line to configuration file: "
108+
"shared_preload_library = 'pathman'");
109+
initialization_needed = false;
110+
}
111+
103112
set_rel_pathlist_hook_original = set_rel_pathlist_hook;
104113
set_rel_pathlist_hook = pathman_set_rel_pathlist_hook;
105114
shmem_startup_hook_original = shmem_startup_hook;

sql/hash.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ DECLARE
108108
rec RECORD;
109109
num INTEGER := 0;
110110
BEGIN
111+
relation := @[email protected]_relname(relation);
112+
111113
/* Drop trigger first */
112114
PERFORM @[email protected]_hash_triggers(relation);
113115
DELETE FROM @[email protected]_config WHERE relname = relation;
114-
-- EXECUTE format('DROP TABLE %s CASCADE', relation);
115-
116+
117+
FOR rec in (SELECT * FROM pg_inherits WHERE inhparent = relation::regclass::oid)
118+
LOOP
119+
EXECUTE format('DROP TABLE %s', rec.inhrelid::regclass::text);
120+
END LOOP;
121+
116122
-- FOR rec in (SELECT * FROM pg_inherits WHERE inhparent = relation::regclass::oid)
117123
-- LOOP
118124
-- EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_update_trigger_func() CASCADE'

sql/init.sql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,23 @@ LANGUAGE plpgsql;
110110
CREATE OR REPLACE FUNCTION @[email protected]_relname(relname TEXT)
111111
RETURNS TEXT AS
112112
$$
113-
DECLARE
114-
ret TEXT := lower(relname);
115113
BEGIN
116-
IF NOT ret ~ '^([a-z_]+[a-z0-9_]*)\.([a-z_]+[a-z0-9_]*)$' THEN
117-
RAISE EXCEPTION 'Incorrect relation name. It must be fully qualified: <schema>.<relname>';
118-
END IF;
119-
RETURN ret;
114+
RETURN @[email protected]_schema_qualified_name(relname::regclass, '.');
120115
END
121116
$$
122117
LANGUAGE plpgsql;
123118

124119

125120
/*
126-
*
121+
* Returns schema-qualified name for table
127122
*/
128-
CREATE OR REPLACE FUNCTION @[email protected]_schema_qualified_name(cls regclass)
123+
CREATE OR REPLACE FUNCTION @[email protected]_schema_qualified_name(
124+
cls REGCLASS
125+
, delimiter TEXT DEFAULT '_')
129126
RETURNS TEXT AS
130127
$$
131128
BEGIN
132-
RETURN relnamespace::regnamespace || '_' || relname FROM pg_class WHERE oid = cls::oid;
129+
RETURN relnamespace::regnamespace || delimiter || relname FROM pg_class WHERE oid = cls::oid;
133130
END
134131
$$
135132
LANGUAGE plpgsql;

sql/range.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ DECLARE
477477
EXECUTE format(''INSERT INTO %%s SELECT $1.*'', v_part_relid::regclass)
478478
USING NEW;
479479
ELSE
480-
RAISE EXCEPTION ''ERROR: Cannot determine approprite partition'';
480+
RAISE EXCEPTION ''ERROR: Cannot find partition'';
481481
END IF;
482482
END IF;
483483
RETURN NULL;

0 commit comments

Comments
 (0)