Kouhei Sutou
null+****@clear*****
Wed Feb 3 00:13:49 JST 2016
Kouhei Sutou 2016-02-03 00:13:49 +0900 (Wed, 03 Feb 2016) New Revision: ef48f9e483040f16e014233110906a84021eee2d https://github.com/pgroonga/pgroonga/commit/ef48f9e483040f16e014233110906a84021eee2d Message: Fix a bug that valid tables/columns are removed by VACUUM/ANALYZE It's caused after you use REINDEX. [groonga-dev,03850] Reported by Naoki Takami. Thanks!!! Added files: expected/reindex/analyze.out sql/reindex/analyze.sql Modified files: src/pgrn_jsonb.c src/pgrn_jsonb.h src/pgroonga.c Added: expected/reindex/analyze.out (+62 -0) 100644 =================================================================== --- /dev/null +++ expected/reindex/analyze.out 2016-02-03 00:13:49 +0900 (9b947f7) @@ -0,0 +1,62 @@ +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); +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT oid + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; + ?column? +---------- + true +(1 row) + +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT relfilenode + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; + ?column? +---------- + true +(1 row) + +REINDEX INDEX pgrn_index; +ANALYZE; +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT oid + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; + ?column? +---------- + false +(1 row) + +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT relfilenode + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; + ?column? +---------- + true +(1 row) + +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; Added: sql/reindex/analyze.sql (+46 -0) 100644 =================================================================== --- /dev/null +++ sql/reindex/analyze.sql 2016-02-03 00:13:49 +0900 (d8076fb) @@ -0,0 +1,46 @@ +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); + +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT oid + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT relfilenode + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; + +REINDEX INDEX pgrn_index; + +ANALYZE; + +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT oid + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; +SELECT pgroonga.command( + 'object_exist ' || + 'Sources' || (SELECT relfilenode + FROM pg_class + WHERE relname = 'pgrn_index'))::jsonb->1; + +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; Modified: src/pgrn_jsonb.c (+10 -10) =================================================================== --- src/pgrn_jsonb.c 2016-01-29 01:48:29 +0900 (faf4052) +++ src/pgrn_jsonb.c 2016-02-03 00:13:49 +0900 (0092885) @@ -1334,36 +1334,36 @@ PGrnRemoveJSONValueLexiconTable(const char *typeName, unsigned int relationID) #endif void -PGrnJSONBRemoveUnusedTables(Oid relationID) +PGrnJSONBRemoveUnusedTables(Oid relationFileNodeID) { #ifdef JSONBOID - PGrnRemoveJSONValueLexiconTable("FullTextSearch", relationID); - PGrnRemoveJSONValueLexiconTable("String", relationID); - PGrnRemoveJSONValueLexiconTable("Number", relationID); - PGrnRemoveJSONValueLexiconTable("Boolean", relationID); - PGrnRemoveJSONValueLexiconTable("Size", relationID); + PGrnRemoveJSONValueLexiconTable("FullTextSearch", relationFileNodeID); + PGrnRemoveJSONValueLexiconTable("String", relationFileNodeID); + PGrnRemoveJSONValueLexiconTable("Number", relationFileNodeID); + PGrnRemoveJSONValueLexiconTable("Boolean", relationFileNodeID); + PGrnRemoveJSONValueLexiconTable("Size", relationFileNodeID); { char name[GRN_TABLE_MAX_KEY_SIZE]; snprintf(name, sizeof(name), PGrnJSONPathsTableNameFormat ".%s", - relationID, 0, PGrnIndexColumnName); + relationFileNodeID, 0, PGrnIndexColumnName); PGrnRemoveObject(name); snprintf(name, sizeof(name), PGrnJSONValuesTableNameFormat, - relationID, 0); + relationFileNodeID, 0); PGrnRemoveObject(name); snprintf(name, sizeof(name), PGrnJSONPathsTableNameFormat, - relationID, 0); + relationFileNodeID, 0); PGrnRemoveObject(name); snprintf(name, sizeof(name), PGrnJSONTypesTableNameFormat, - relationID, 0); + relationFileNodeID, 0); PGrnRemoveObject(name); } #endif Modified: src/pgrn_jsonb.h (+1 -1) =================================================================== --- src/pgrn_jsonb.h 2016-01-29 01:48:29 +0900 (343f07d) +++ src/pgrn_jsonb.h 2016-02-03 00:13:49 +0900 (5903078) @@ -42,4 +42,4 @@ void PGrnJSONBBulkDeleteInit(PGrnJSONBBulkDeleteData *data); void PGrnJSONBBulkDeleteRecord(PGrnJSONBBulkDeleteData *data); void PGrnJSONBBulkDeleteFin(PGrnJSONBBulkDeleteData *data); -void PGrnJSONBRemoveUnusedTables(Oid relationID); +void PGrnJSONBRemoveUnusedTables(Oid relationFileNodeID); Modified: src/pgroonga.c (+18 -11) =================================================================== --- src/pgroonga.c 2016-01-29 01:48:29 +0900 (d953c98) +++ src/pgroonga.c 2016-02-03 00:13:49 +0900 (0309312) @@ -26,6 +26,7 @@ #include <utils/array.h> #include <utils/builtins.h> #include <utils/lsyscache.h> +#include <utils/relfilenodemap.h> #include <utils/selfuncs.h> #include <utils/syscache.h> #include <utils/timestamp.h> @@ -3134,30 +3135,36 @@ PGrnRemoveUnusedTables(void) char *name; char *nameEnd; int nameSize; + Oid relationFileNodeID; Oid relationID; - Relation relation; unsigned int i; nameSize = grn_table_cursor_get_key(ctx, cursor, (void **)&name); nameEnd = name + nameSize; - relationID = strtol(name + strlen(min), &nameEnd, 10); + relationFileNodeID = strtol(name + strlen(min), &nameEnd, 10); if (nameEnd[0] == '.') continue; - LockRelationOid(relationID, AccessShareLock); - relation = RelationIdGetRelation(relationID); - if (RelationIsValid(relation)) + relationID = RelidByRelfilenode(MyDatabaseTableSpace, + relationFileNodeID); + if (OidIsValid(relationID)) { - RelationClose(relation); - UnlockRelationOid(relationID, AccessShareLock); - continue; + Relation relation; + LockRelationOid(relationID, AccessShareLock); + relation = RelationIdGetRelation(relationID); + if (RelationIsValid(relation)) + { + RelationClose(relation); + UnlockRelationOid(relationID, AccessShareLock); + continue; + } } for (i = 0; true; i++) { char tableName[GRN_TABLE_MAX_KEY_SIZE]; snprintf(tableName, sizeof(tableName), - PGrnLexiconNameFormat, relationID, i); + PGrnLexiconNameFormat, relationFileNodeID, i); if (!PGrnRemoveObject(tableName)) break; } @@ -3165,11 +3172,11 @@ PGrnRemoveUnusedTables(void) { char tableName[GRN_TABLE_MAX_KEY_SIZE]; snprintf(tableName, sizeof(tableName), - PGrnSourcesTableNameFormat, relationID); + PGrnSourcesTableNameFormat, relationFileNodeID); PGrnRemoveObject(tableName); } - PGrnJSONBRemoveUnusedTables(relationID); + PGrnJSONBRemoveUnusedTables(relationFileNodeID); } grn_table_cursor_close(ctx, cursor); } -------------- next part -------------- HTML����������������������������... Descargar