Kouhei Sutou
null+****@clear*****
Sun Nov 6 00:14:35 JST 2016
Kouhei Sutou 2016-11-06 00:14:35 +0900 (Sun, 06 Nov 2016) New Revision: ffbfbbcb344e7ebf5779096e1046df3dc8a21022 https://github.com/pgroonga/pgroonga/commit/ffbfbbcb344e7ebf5779096e1046df3dc8a21022 Message: Support index only scan availability check for TOAST data Modified files: src/pgrn_jsonb.c src/pgrn_jsonb.h src/pgroonga.c Modified: src/pgrn_jsonb.c (+4 -1) =================================================================== --- src/pgrn_jsonb.c 2016-11-04 17:56:45 +0900 (d27bfc4) +++ src/pgrn_jsonb.c 2016-11-06 00:14:35 +0900 (9595f1e) @@ -1157,7 +1157,7 @@ PGrnJSONBInsertRecord(Relation index, } #endif -void +uint32_t PGrnJSONBInsert(Relation index, grn_obj *sourcesTable, grn_obj *sourcesCtidColumn, @@ -1165,6 +1165,7 @@ PGrnJSONBInsert(Relation index, bool *isnull, uint64_t packedCtid) { + uint32_t recordSize = 0; /* always 0 */ #ifdef PGRN_SUPPORT_JSONB PGrnJSONBInsertData data; unsigned int nthValue = 0; @@ -1190,6 +1191,8 @@ PGrnJSONBInsert(Relation index, PGrnJSONBInsertDataFin(&data); #endif + + return recordSize; } #ifdef PGRN_SUPPORT_JSONB Modified: src/pgrn_jsonb.h (+6 -6) =================================================================== --- src/pgrn_jsonb.h 2016-11-04 17:56:45 +0900 (c484eb3) +++ src/pgrn_jsonb.h 2016-11-06 00:14:35 +0900 (e2fa326) @@ -40,12 +40,12 @@ grn_obj *PGrnJSONBLookupSizeLexicon(Relation index, grn_obj *PGrnJSONBSetSource(Relation index, unsigned int i); -void PGrnJSONBInsert(Relation index, - grn_obj *sourcesTable, - grn_obj *sourcesCtidColumn, - Datum *values, - bool *isnull, - uint64_t packedCtid); +uint32_t PGrnJSONBInsert(Relation index, + grn_obj *sourcesTable, + grn_obj *sourcesCtidColumn, + Datum *values, + bool *isnull, + uint64_t packedCtid); bool PGrnJSONBBuildSearchCondition(PGrnSearchData *data, ScanKey key, Modified: src/pgroonga.c (+36 -41) =================================================================== --- src/pgroonga.c 2016-11-04 17:56:45 +0900 (59256b9) +++ src/pgroonga.c 2016-11-06 00:14:35 +0900 (6ff61cd) @@ -1957,13 +1957,15 @@ PGrnNeedMaxRecordSizeUpdate(Relation index) return nVarCharColumns >= 2; } +#define PGRN_INDEX_ONLY_SCAN_THRESHOLD_SIZE (INDEX_SIZE_MASK * 0.9) + static void -PGrnUpdateMaxRecordSizeRaw(Relation index, - uint32_t recordSize) +PGrnUpdateMaxRecordSize(Relation index, + uint32_t recordSize) { uint32_t currentMaxRecordSize; - if (recordSize < INDEX_SIZE_MASK) + if (recordSize < PGRN_INDEX_ONLY_SCAN_THRESHOLD_SIZE) return; currentMaxRecordSize = PGrnIndexStatusGetMaxRecordSize(index); @@ -1973,19 +1975,7 @@ PGrnUpdateMaxRecordSizeRaw(Relation index, PGrnIndexStatusSetMaxRecordSize(index, recordSize); } -static void -PGrnUpdateMaxRecordSize(Relation index, - Datum *values, - bool *isnull) -{ - TupleDesc desc = RelationGetDescr(index); - Size recordSize; - - recordSize = heap_compute_data_size(desc, values, isnull); - PGrnUpdateMaxRecordSizeRaw(index, recordSize); -} - -static void +static uint32_t PGrnInsert(Relation index, grn_obj *sourcesTable, grn_obj *sourcesCtidColumn, @@ -1997,16 +1987,16 @@ PGrnInsert(Relation index, grn_id id; PGrnWALData *walData; unsigned int i; + uint32_t recordSize = 0; if (desc->natts == 1 && PGrnAttributeIsJSONB(desc->attrs[0]->atttypid)) { - PGrnJSONBInsert(index, - sourcesTable, - sourcesCtidColumn, - values, - isnull, - CtidToUInt64(ht_ctid)); - return; + return PGrnJSONBInsert(index, + sourcesTable, + sourcesCtidColumn, + values, + isnull, + CtidToUInt64(ht_ctid)); } id = grn_table_add(ctx, sourcesTable, NULL, 0, NULL); @@ -2037,6 +2027,7 @@ PGrnInsert(Relation index, grn_obj_reinit(ctx, buffer, domain, flags); PGrnConvertFromData(values[i], attribute->atttypid, buffer); grn_obj_set_value(ctx, dataColumn, id, buffer, GRN_OBJ_SET); + recordSize += GRN_BULK_VSIZE(buffer); PGrnWALInsertColumn(walData, dataColumn, buffer); grn_obj_unlink(ctx, dataColumn); if (!PGrnCheck("failed to set column value")) { @@ -2046,6 +2037,8 @@ PGrnInsert(Relation index, PGrnWALInsertFinish(walData); PGrnWALFinish(walData); + + return recordSize; } static bool @@ -2058,13 +2051,18 @@ pgroonga_insert_raw(Relation index, { grn_obj *sourcesTable; grn_obj *sourcesCtidColumn; + uint32_t recordSize; sourcesTable = PGrnLookupSourcesTable(index, ERROR); sourcesCtidColumn = PGrnLookupSourcesCtidColumn(index, ERROR); - PGrnInsert(index, sourcesTable, sourcesCtidColumn, - values, isnull, ctid); + recordSize = PGrnInsert(index, + sourcesTable, + sourcesCtidColumn, + values, + isnull, + ctid); if (PGrnNeedMaxRecordSizeUpdate(index)) - PGrnUpdateMaxRecordSize(index, values, isnull); + PGrnUpdateMaxRecordSize(index, recordSize); grn_db_touch(ctx, grn_ctx_db(ctx)); return false; @@ -3606,22 +3604,21 @@ PGrnBuildCallbackRaw(Relation index, void *state) { PGrnBuildState bs = (PGrnBuildState) state; + uint32_t recordSize; if (!tupleIsAlive) return; - PGrnInsert(index, bs->sourcesTable, bs->sourcesCtidColumn, - values, isnull, ctid); - if (bs->needMaxRecordSizeUpdate) + recordSize = PGrnInsert(index, + bs->sourcesTable, + bs->sourcesCtidColumn, + values, + isnull, + ctid); + if (bs->needMaxRecordSizeUpdate && + recordSize > bs->maxRecordSize) { - TupleDesc desc = RelationGetDescr(index); - Size recordSize; - - recordSize = heap_compute_data_size(desc, values, isnull); - if (recordSize > bs->maxRecordSize) - { - bs->maxRecordSize = recordSize; - } + bs->maxRecordSize = recordSize; } bs->nIndexedTuples++; } @@ -3678,9 +3675,7 @@ pgroonga_build_raw(Relation heap, bs.sourcesTable = NULL; bs.nIndexedTuples = 0.0; - bs.needMaxRecordSizeUpdate = - (PGrnNeedMaxRecordSizeUpdate(index) && - PGrnIndexStatusGetMaxRecordSize(index) < INDEX_SIZE_MASK); + bs.needMaxRecordSizeUpdate = PGrnNeedMaxRecordSizeUpdate(index); bs.maxRecordSize = 0; GRN_PTR_INIT(&supplementaryTables, GRN_OBJ_VECTOR, GRN_ID_NIL); @@ -3733,7 +3728,7 @@ pgroonga_build_raw(Relation heap, if (bs.needMaxRecordSizeUpdate) { - PGrnUpdateMaxRecordSizeRaw(index, bs.maxRecordSize); + PGrnUpdateMaxRecordSize(index, bs.maxRecordSize); } return result; -------------- next part -------------- HTML����������������������������... 下载