Skip to content

Commit

Permalink
jsonb: reduce needless lexicon
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Sep 24, 2015
1 parent 2b39467 commit bb61580
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions pgroonga.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,15 @@ PGrnCreateIndexColumnForJSON(PGrnCreateData *data,
static void
PGrnCreateIndexColumnsForJSON(PGrnCreateData *data)
{
PGrnCreateColumn(data->jsonValuesTable,
PGrnIndexColumnName,
GRN_OBJ_COLUMN_INDEX,
data->sourcesTable);
PGrnCreateColumn(data->jsonPathsTable,
PGrnIndexColumnName,
GRN_OBJ_COLUMN_INDEX,
data->jsonValuesTable);

/* TODO: 4KiB over string value can't be searched. */
/* TODO: Should we also support full text search against string value? */
PGrnCreateIndexColumnForJSON(data,
Expand Down Expand Up @@ -1248,17 +1253,17 @@ PGrnCreate(Relation index,
data.forFullTextSearch = false;
data.attributeTypeID = grn_obj_id(ctx, data.jsonValuesTable);
data.attributeFlags = GRN_OBJ_VECTOR;
PGrnCreateDataColumn(&data);
}
else
#endif
{
data.forFullTextSearch = PGrnIsForFullTextSearchIndex(index, data.i);
data.attributeTypeID = PGrnGetType(index, data.i,
&(data.attributeFlags));
PGrnCreateDataColumn(&data);
PGrnCreateIndexColumn(&data);
}

PGrnCreateDataColumn(&data);
PGrnCreateIndexColumn(&data);
}
}

Expand Down Expand Up @@ -1308,14 +1313,13 @@ PGrnSetSourceForJSON(Relation index,

static void
PGrnSetSourcesForJSON(Relation index,
grn_obj *jsonValuesTable,
unsigned int nthAttribute,
grn_obj *sourceIDs)
{
grn_obj *jsonPathsTable;
grn_obj *jsonValuesTable;

jsonPathsTable = PGrnLookupJSONPathsTable(index, nthAttribute, ERROR);
jsonValuesTable = PGrnLookupJSONValuesTable(index, nthAttribute, ERROR);

{
grn_obj *source;
Expand All @@ -1338,7 +1342,6 @@ PGrnSetSourcesForJSON(Relation index,
PGrnSetSourceForJSON(index, jsonValuesTable, "size", "Size",
nthAttribute, sourceIDs);

grn_obj_unlink(ctx, jsonValuesTable);
grn_obj_unlink(ctx, jsonPathsTable);
}
#endif
Expand All @@ -1362,12 +1365,22 @@ PGrnSetSources(Relation index, grn_obj *sourcesTable)
#ifdef JSONBOID
if (attribute->atttypid == JSONBOID)
{
PGrnSetSourcesForJSON(index, i, &sourceIDs);
grn_obj *jsonValuesTable;

jsonValuesTable = PGrnLookupJSONValuesTable(index, i, ERROR);
PGrnSetSourcesForJSON(index, jsonValuesTable, i, &sourceIDs);
indexColumn = PGrnLookupColumn(jsonValuesTable,
PGrnIndexColumnName,
ERROR);
grn_obj_unlink(ctx, jsonValuesTable);
}
else
#endif
{
indexColumn = PGrnLookupIndexColumn(index, i, ERROR);
}

source = PGrnLookupColumn(sourcesTable, name->data, ERROR);
indexColumn = PGrnLookupIndexColumn(index, i, ERROR);
PGrnSetSource(indexColumn, source, &sourceIDs);
grn_obj_unlink(ctx, source);
grn_obj_unlink(ctx, indexColumn);
Expand Down

0 comments on commit bb61580

Please sign in to comment.