Kouhei Sutou
null+****@clear*****
Fri Oct 28 16:51:04 JST 2016
Kouhei Sutou 2016-10-28 16:51:04 +0900 (Fri, 28 Oct 2016) New Revision: 4d849b75ca8e420bbcc831e22efe97310401c4dc https://github.com/pgroonga/pgroonga/commit/4d849b75ca8e420bbcc831e22efe97310401c4dc Message: Fix a bug that living PGroonga indexes are removed on VACUUM GitHub: fix #27 It's caused when PGroonga index is created with non default table space. Reported by pavelpopovgmail. Thanks!!! Added files: expected/vacuum/tablespace.out.in sql/vacuum/tablespace.sql.in Modified files: .gitignore Makefile appveyor.yml src/pgroonga.c Modified: .gitignore (+2 -0) =================================================================== --- .gitignore 2016-10-28 14:42:57 +0900 (62d5bff) +++ .gitignore 2016-10-28 16:51:04 +0900 (189f0a7) @@ -6,6 +6,8 @@ pgroonga--*.sql !pgroonga--*--*.sql /examples/completion/edict.gz /regression.* +/sql/vaccum/tablespace.sql +/expected/vaccum/tablespace.out /results/ /packages/source/ /packages/apt/.vagrant/ Modified: Makefile (+14 -1) =================================================================== --- Makefile 2016-10-28 14:42:57 +0900 (ddacbb0) +++ Makefile 2016-10-28 16:51:04 +0900 (a01e918) @@ -50,7 +50,20 @@ EXPECTED_FILES = \ sed -e 's,^sql/,expected/,' \ -e 's,sql$$,out,') -installcheck: $(RESULT_DIRS) $(EXPECTED_DIRS) $(EXPECTED_FILES) +installcheck: prepare-regress +installcheck: $(RESULT_DIRS) +installcheck: $(EXPECTED_DIRS) +installcheck: $(EXPECTED_FILES) + +prepare-regress: + @rm -rf tmp + @mkdir -p tmp/space + @sed -e "s, �� TMP_DIR@,$(PWD)/tmp,g" \ + sql/vacuum/tablespace.sql.in > \ + sql/vacuum/tablespace.sql + @sed -e "s, �� TMP_DIR@,$(PWD)/tmp,g" \ + expected/vacuum/tablespace.out.in > \ + expected/vacuum/tablespace.out $(RESULT_DIRS) $(EXPECTED_DIRS): @mkdir -p $@ Modified: appveyor.yml (+7 -0) =================================================================== --- appveyor.yml 2016-10-28 14:42:57 +0900 (e558f6a) +++ appveyor.yml 2016-10-28 16:51:04 +0900 (fd1db31) @@ -50,6 +50,13 @@ notifications: on_build_status_changed: true test_script: + - mkdir -p tmp\space + - sed -e 's, �� TMP_DIR@,C:\\projects\\pgroonga\\tmp,g' + sql\vacuum\tablespace.sql.in > + sql\vacuum\tablespace.sql + - sed -e 's, �� TMP_DIR@,C:\\projects\\pgroonga\\tmp,g' + expected\vacuum\tablespace.out.in > + expected\vacuum\tablespace.out - find sql/* -type d | sed -e 's,^sql,results,' | xargs mkdir -p - find sql -name '*.sql' | sed -e 's,^sql/,test:\ ,g' | Added: expected/vacuum/tablespace.out.in (+23 -0) 100644 =================================================================== --- /dev/null +++ expected/vacuum/tablespace.out.in 2016-10-28 16:51:04 +0900 (2386c37) @@ -0,0 +1,23 @@ +CREATE TABLESPACE fast LOCATION '@TMP_DIR@/space'; +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX pgrn_index ON memos USING pgroonga (content) TABLESPACE fast; +VACUUM; +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content %% 'PGroonga' AND content %% 'Groonga'; + id | content +----+------------------------------------------------------- + 3 | PGroonga is a PostgreSQL extension that uses Groonga. +(1 row) + +DROP TABLE memos; +DROP TABLESPACE fast; Added: sql/vacuum/tablespace.sql.in (+26 -0) 100644 =================================================================== --- /dev/null +++ sql/vacuum/tablespace.sql.in 2016-10-28 16:51:04 +0900 (4abd814) @@ -0,0 +1,26 @@ +CREATE TABLESPACE fast LOCATION '@TMP_DIR@/space'; + +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX pgrn_index ON memos USING pgroonga (content) TABLESPACE fast; + +VACUUM; + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content %% 'PGroonga' AND content %% 'Groonga'; + +DROP TABLE memos; + +DROP TABLESPACE fast; Modified: src/pgroonga.c (+44 -15) =================================================================== --- src/pgroonga.c 2016-10-28 14:42:57 +0900 (ceb9b2a) +++ src/pgroonga.c 2016-10-28 16:51:04 +0900 (8bf7781) @@ -3846,6 +3846,48 @@ pgroonga_bulkdelete(PG_FUNCTION_ARGS) PG_RETURN_POINTER(stats); } +#ifdef PGRN_SUPPORT_FILE_NODE_ID_TO_RELATION_ID +static bool +PGrnIsValidRelationFileNodeID(Oid relationFileNodeID) +{ + bool valid = false; + Relation tableSpaces; + HeapScanDesc scan; + + tableSpaces = heap_open(TableSpaceRelationId, AccessShareLock); + scan = heap_beginscan_catalog(tableSpaces, 0, NULL); + while (!valid) + { + HeapTuple tuple; + Oid relationID; + Relation relation; + + tuple = heap_getnext(scan, ForwardScanDirection); + + if (!HeapTupleIsValid(tuple)) + break; + + relationID = RelidByRelfilenode(HeapTupleGetOid(tuple), + relationFileNodeID); + if (!OidIsValid(relationID)) + continue; + + LockRelationOid(relationID, AccessShareLock); + relation = RelationIdGetRelation(relationID); + if (RelationIsValid(relation)) + { + RelationClose(relation); + valid = true; + } + UnlockRelationOid(relationID, AccessShareLock); + } + heap_endscan(scan); + heap_close(tableSpaces, AccessShareLock); + + return valid; +} +#endif + static void PGrnRemoveUnusedTables(void) { @@ -3863,7 +3905,6 @@ PGrnRemoveUnusedTables(void) char *nameEnd; int nameSize; Oid relationFileNodeID; - Oid relationID; unsigned int i; nameSize = grn_table_cursor_get_key(ctx, cursor, (void **)&name); @@ -3872,20 +3913,8 @@ PGrnRemoveUnusedTables(void) if (nameEnd[0] == '.') continue; - relationID = RelidByRelfilenode(MyDatabaseTableSpace, - relationFileNodeID); - if (OidIsValid(relationID)) - { - Relation relation; - LockRelationOid(relationID, AccessShareLock); - relation = RelationIdGetRelation(relationID); - if (RelationIsValid(relation)) - { - RelationClose(relation); - UnlockRelationOid(relationID, AccessShareLock); - continue; - } - } + if (PGrnIsValidRelationFileNodeID(relationFileNodeID)) + continue; for (i = 0; true; i++) { -------------- next part -------------- HTML����������������������������...Download