Navigation Menu

Skip to content

Commit

Permalink
Support ambuildempty
Browse files Browse the repository at this point in the history
It's not tested but it will work.
  • Loading branch information
kou committed Jan 17, 2015
1 parent 65dc39b commit fc3fd75
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pgroonga--0.2.0.sql
Expand Up @@ -32,6 +32,7 @@ CREATE FUNCTION pgroonga.getbitmap(internal) RETURNS bigint AS 'MODULE_PATHNAME'
CREATE FUNCTION pgroonga.rescan(internal) RETURNS void AS 'MODULE_PATHNAME','pgroonga_rescan' LANGUAGE C;
CREATE FUNCTION pgroonga.endscan(internal) RETURNS void AS 'MODULE_PATHNAME','pgroonga_endscan' LANGUAGE C;
CREATE FUNCTION pgroonga.build(internal) RETURNS internal AS 'MODULE_PATHNAME','pgroonga_build' LANGUAGE C;
CREATE FUNCTION pgroonga.buildempty(internal) RETURNS internal AS 'MODULE_PATHNAME','pgroonga_buildempty' LANGUAGE C;
CREATE FUNCTION pgroonga.bulkdelete(internal) RETURNS internal AS 'MODULE_PATHNAME','pgroonga_bulkdelete' LANGUAGE C;
CREATE FUNCTION pgroonga.vacuumcleanup(internal) RETURNS internal AS 'MODULE_PATHNAME','pgroonga_vacuumcleanup' LANGUAGE C;
CREATE FUNCTION pgroonga.costestimate(internal) RETURNS internal AS 'MODULE_PATHNAME','pgroonga_costestimate' LANGUAGE C;
Expand Down Expand Up @@ -84,7 +85,7 @@ INSERT INTO pg_catalog.pg_am VALUES(
0, -- ammarkpos,
0, -- amrestrpos,
'pgroonga.build', -- ambuild
0, -- ambuildempty
'pgroonga.buildempty', -- ambuildempty
'pgroonga.bulkdelete', -- ambulkdelete
'pgroonga.vacuumcleanup', -- amvacuumcleanup
0, -- amcanreturn
Expand Down
35 changes: 33 additions & 2 deletions pgroonga.c
Expand Up @@ -50,6 +50,7 @@ PG_FUNCTION_INFO_V1(pgroonga_getbitmap);
PG_FUNCTION_INFO_V1(pgroonga_rescan);
PG_FUNCTION_INFO_V1(pgroonga_endscan);
PG_FUNCTION_INFO_V1(pgroonga_build);
PG_FUNCTION_INFO_V1(pgroonga_buildempty);
PG_FUNCTION_INFO_V1(pgroonga_bulkdelete);
PG_FUNCTION_INFO_V1(pgroonga_vacuumcleanup);
PG_FUNCTION_INFO_V1(pgroonga_costestimate);
Expand Down Expand Up @@ -936,6 +937,36 @@ pgroonga_build(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(result);
}

/**
* pgroonga.buildempty() -- ambuildempty
*/
Datum
pgroonga_buildempty(PG_FUNCTION_ARGS)
{
Relation index = (Relation) PG_GETARG_POINTER(0);
grn_obj *idsTable = NULL;
grn_obj *lexicon = NULL;
grn_obj *indexColumn = NULL;

PG_TRY();
{
GrnCreate(index, &idsTable, &lexicon, &indexColumn);
}
PG_CATCH();
{
if (indexColumn)
grn_obj_remove(ctx, indexColumn);
if (lexicon)
grn_obj_remove(ctx, lexicon);
if (idsTable)
grn_obj_remove(ctx, idsTable);
PG_RE_THROW();
}
PG_END_TRY();

PG_RETURN_VOID();
}

static IndexBulkDeleteResult *
GrnBulkDeleteResult(IndexVacuumInfo *info, grn_obj *idsTable)
{
Expand Down Expand Up @@ -989,12 +1020,12 @@ pgroonga_bulkdelete(PG_FUNCTION_ARGS)
while (grn_table_cursor_next(ctx, cursor) != GRN_ID_NIL)
{
ItemPointerData ctid;
uint64 key;
uint64 *key;

CHECK_FOR_INTERRUPTS();

grn_table_cursor_get_key(ctx, cursor, (void **) &key);
ctid = UInt64ToCtid(key);
ctid = UInt64ToCtid(*key);
if (callback(&ctid, callback_state))
{
GrnLock(index, ExclusiveLock);
Expand Down
1 change: 1 addition & 0 deletions pgroonga.h
Expand Up @@ -47,6 +47,7 @@ extern Datum PGDLLEXPORT pgroonga_getbitmap(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_rescan(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_endscan(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_build(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_buildempty(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_bulkdelete(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_vacuumcleanup(PG_FUNCTION_ARGS);
extern Datum PGDLLEXPORT pgroonga_costestimate(PG_FUNCTION_ARGS);
Expand Down

0 comments on commit fc3fd75

Please sign in to comment.