Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62f9bf5

Browse files
committed
inserting
1 parentf7e0d94 commit62f9bf5

File tree

8 files changed

+206
-34
lines changed

8 files changed

+206
-34
lines changed

‎expected/orderby.out

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
CREATE TABLE tsts (id int, t tsvector, d timestamp);
22
\copy tsts from 'data/tsts.data'
3-
CREATE INDEX tsts_idx ON tsts USING rum (t rum_tsvector_ops, d) WITH (orderby = 'd');
3+
CREATE INDEX tsts_idx ON tsts USING rum (t rum_tsvector_timestamp_ops, d)
4+
WITH (orderby = 'd', addto = 't');
5+
INSERT INTO tsts VALUES (-1, 't1 t2', '2016-05-02 02:24:22.326724');
6+
INSERT INTO tsts VALUES (-2, 't1 t2 t3', '2016-05-02 02:26:22.326724');

‎rum--1.0.sql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ AS
6565
FUNCTION9 rum_tsquery_distance(internal,smallint,tsvector,int,internal,internal,internal,internal,internal),
6666
STORAGEtext;
6767

68-
6968
-- timestamp ops
7069

7170
CREATEFUNCTIONtimestamp_distance(timestamp,timestamp)
@@ -127,6 +126,11 @@ RETURNS bool
127126
AS'MODULE_PATHNAME'
128127
LANGUAGE C STRICT IMMUTABLE;
129128

129+
CREATEFUNCTIONrum_timestamp_outer_distance(timestamp,timestamp,smallint)
130+
RETURNS float8
131+
AS'MODULE_PATHNAME'
132+
LANGUAGE C STRICT IMMUTABLE;
133+
130134
CREATEOPERATOR CLASStimestamp_ops
131135
DEFAULT FOR TYPEtimestamp USING rum
132136
AS
@@ -135,10 +139,30 @@ AS
135139
OPERATOR3=,
136140
OPERATOR4>=,
137141
OPERATOR5>,
142+
OPERATOR20<-> FORORDER BYpg_catalog.float_ops,
143+
OPERATOR21<-| FORORDER BYpg_catalog.float_ops,
144+
OPERATOR22|-> FORORDER BYpg_catalog.float_ops,
138145
FUNCTION1 timestamp_cmp(timestamp,timestamp),
139146
FUNCTION2 rum_timestamp_extract_value(timestamp,internal,internal,internal,internal),
140147
FUNCTION3 rum_timestamp_extract_query(timestamp,internal,smallint,internal,internal,internal,internal),
141148
FUNCTION4 rum_timestamp_consistent(internal,smallint,timestamp,int,internal,internal,internal,internal),
142149
FUNCTION5 rum_timestamp_compare_prefix(timestamp,timestamp,smallint,internal),
150+
FUNCTION10 rum_timestamp_outer_distance(timestamp,timestamp,smallint),
143151
STORAGEtimestamp;
144152

153+
--together
154+
155+
CREATEOPERATOR CLASSrum_tsvector_timestamp_ops
156+
FOR TYPE tsvector USING rum
157+
AS
158+
OPERATOR1 @@ (tsvector, tsquery),
159+
FUNCTION1 gin_cmp_tslexeme(text,text),
160+
FUNCTION2 rum_extract_tsvector(tsvector,internal,internal,internal,internal),
161+
FUNCTION3 rum_extract_tsquery(tsquery,internal,smallint,internal,internal,internal,internal),
162+
FUNCTION4 rum_tsquery_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal),
163+
FUNCTION5 gin_cmp_prefix(text,text,smallint,internal),
164+
FUNCTION6 gin_tsquery_triconsistent(internal,smallint,tsvector,int,internal,internal,internal),
165+
FUNCTION8 rum_tsquery_pre_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal),
166+
STORAGEtext;
167+
168+

‎rum.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ typedef struct RumOptions
295295
int32vl_len_;/* varlena header (do not touch directly!) */
296296
booluseFastUpdate;/* use fast updates? */
297297
intorderByColumn;
298+
intaddToColumn;
298299
}RumOptions;
299300

300301
#defineRUM_DEFAULT_USE_FASTUPDATEfalse
@@ -317,6 +318,7 @@ typedef struct RumState
317318
Relationindex;
318319
booloneCol;/* true if single-column index */
319320
AttrNumberattrnOrderByColumn;
321+
AttrNumberattrnAddToColumn;
320322

321323
/*
322324
* origTupDesc is the nominal tuple descriptor of the index, ie, the i'th
@@ -345,12 +347,14 @@ typedef struct RumState
345347
FmgrInfoconfigFn[INDEX_MAX_KEYS];/* optional method */
346348
FmgrInfopreConsistentFn[INDEX_MAX_KEYS];/* optional method */
347349
FmgrInfoorderingFn[INDEX_MAX_KEYS];/* optional method */
350+
FmgrInfoouterOrderingFn[INDEX_MAX_KEYS];/* optional method */
348351
/* canPartialMatch[i] is true if comparePartialFn[i] is valid */
349352
boolcanPartialMatch[INDEX_MAX_KEYS];
350353
/* canPreConsistent[i] is true if preConsistentFn[i] is valid */
351354
boolcanPreConsistent[INDEX_MAX_KEYS];
352355
/* canOrdering[i] is true if orderingFn[i] is valid */
353356
boolcanOrdering[INDEX_MAX_KEYS];
357+
boolcanOuterOrdering[INDEX_MAX_KEYS];
354358
/* Collations to pass to the support functions */
355359
OidsupportCollation[INDEX_MAX_KEYS];
356360
}RumState;
@@ -738,7 +742,8 @@ extern void rumInsertCleanup(RumState *rumstate,
738742
#defineRUM_CONFIG_PROC7
739743
#defineRUM_PRE_CONSISTENT_PROC8
740744
#defineRUM_ORDERING_PROC9
741-
#defineRUMNProcs9
745+
#defineRUM_OUTER_ORDERING_PROC10
746+
#defineRUMNProcs10
742747

743748
externDatumrum_extract_tsvector(PG_FUNCTION_ARGS);
744749
externDatumrum_extract_tsquery(PG_FUNCTION_ARGS);

‎rum_timestamp.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,39 @@ timestamp_right_distance(PG_FUNCTION_ARGS)
215215
PG_RETURN_FLOAT8(diff);
216216
}
217217

218+
#defineRUM_TMST_DISTANCE20
219+
#defineRUM_TMST_LEFT_DISTANCE21
220+
#defineRUM_TMST_RIGHT_DISTANCE22
221+
222+
PG_FUNCTION_INFO_V1(rum_timestamp_outer_distance);
223+
Datum
224+
rum_timestamp_outer_distance(PG_FUNCTION_ARGS)
225+
{
226+
StrategyNumberstrategy=PG_GETARG_UINT16(2);
227+
Datumdiff;
228+
229+
switch(strategy)
230+
{
231+
caseRUM_TMST_DISTANCE:
232+
diff=DirectFunctionCall2(timestamp_distance,
233+
PG_GETARG_DATUM(0),
234+
PG_GETARG_DATUM(1));
235+
break;
236+
caseRUM_TMST_LEFT_DISTANCE:
237+
diff=DirectFunctionCall2(timestamp_left_distance,
238+
PG_GETARG_DATUM(0),
239+
PG_GETARG_DATUM(1));
240+
break;
241+
caseRUM_TMST_RIGHT_DISTANCE:
242+
diff=DirectFunctionCall2(timestamp_right_distance,
243+
PG_GETARG_DATUM(0),
244+
PG_GETARG_DATUM(1));
245+
break;
246+
default:
247+
elog(ERROR,"rum_timestamp_outer_distance: unknown strategy %u",
248+
strategy);
249+
}
250+
251+
PG_RETURN_DATUM(diff);
252+
}
218253

‎ruminsert.c

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ rumEntryInsert(RumState *rumstate,
492492
staticvoid
493493
rumHeapTupleBulkInsert(RumBuildState*buildstate,OffsetNumberattnum,
494494
Datumvalue,boolisNull,
495-
ItemPointerheapptr)
495+
ItemPointerheapptr,
496+
DatumouterAddInfo,
497+
boolouterAddInfoIsNull)
496498
{
497499
Datum*entries;
498500
RumNullCategory*categories;
@@ -508,6 +510,19 @@ rumHeapTupleBulkInsert(RumBuildState *buildstate, OffsetNumber attnum,
508510
value,isNull,
509511
&nentries,&categories,
510512
&addInfo,&addInfoIsNull);
513+
514+
if (attnum==buildstate->rumstate.attrnAddToColumn)
515+
{
516+
addInfo=palloc(sizeof(*addInfo)*nentries);
517+
addInfoIsNull=palloc(sizeof(*addInfoIsNull)*nentries);
518+
519+
for(i=0;i<nentries;i++)
520+
{
521+
addInfo[i]=outerAddInfo;
522+
addInfoIsNull[i]=outerAddInfoIsNull;
523+
}
524+
}
525+
511526
MemoryContextSwitchTo(oldCtx);
512527
for (i=0;i<nentries;i++)
513528
{
@@ -532,13 +547,22 @@ rumBuildCallback(Relation index, HeapTuple htup, Datum *values,
532547
RumBuildState*buildstate= (RumBuildState*)state;
533548
MemoryContextoldCtx;
534549
inti;
550+
DatumouterAddInfo= (Datum)0;
551+
boolouterAddInfoIsNull= true;
552+
553+
if (AttributeNumberIsValid(buildstate->rumstate.attrnOrderByColumn))
554+
{
555+
outerAddInfo=values[buildstate->rumstate.attrnOrderByColumn-1];
556+
outerAddInfoIsNull=isnull[buildstate->rumstate.attrnOrderByColumn-1];
557+
}
535558

536559
oldCtx=MemoryContextSwitchTo(buildstate->tmpCtx);
537560

538561
for (i=0;i<buildstate->rumstate.origTupdesc->natts;i++)
539562
rumHeapTupleBulkInsert(buildstate, (OffsetNumber) (i+1),
540563
values[i],isnull[i],
541-
&htup->t_self);
564+
&htup->t_self,
565+
outerAddInfo,outerAddInfoIsNull);
542566

543567
/* If we've maxed out our available memory, dump everything to the index */
544568
if (buildstate->accum.allocatedMemory >=maintenance_work_mem*1024L)
@@ -732,7 +756,9 @@ rumbuildempty(Relation index)
732756
staticvoid
733757
rumHeapTupleInsert(RumState*rumstate,OffsetNumberattnum,
734758
Datumvalue,boolisNull,
735-
ItemPointeritem)
759+
ItemPointeritem,
760+
DatumouterAddInfo,
761+
boolouterAddInfoIsNull)
736762
{
737763
Datum*entries;
738764
RumNullCategory*categories;
@@ -744,6 +770,18 @@ rumHeapTupleInsert(RumState *rumstate, OffsetNumber attnum,
744770
entries=rumExtractEntries(rumstate,attnum,value,isNull,
745771
&nentries,&categories,&addInfo,&addInfoIsNull);
746772

773+
if (attnum==rumstate->attrnAddToColumn)
774+
{
775+
addInfo=palloc(sizeof(*addInfo)*nentries);
776+
addInfoIsNull=palloc(sizeof(*addInfoIsNull)*nentries);
777+
778+
for(i=0;i<nentries;i++)
779+
{
780+
addInfo[i]=outerAddInfo;
781+
addInfoIsNull[i]=outerAddInfoIsNull;
782+
}
783+
}
784+
747785
for (i=0;i<nentries;i++)
748786
rumEntryInsert(rumstate,attnum,entries[i],categories[i],
749787
item,&addInfo[i],&addInfoIsNull[i],1,NULL);
@@ -758,6 +796,8 @@ ruminsert(Relation index, Datum *values, bool *isnull,
758796
MemoryContextoldCtx;
759797
MemoryContextinsertCtx;
760798
inti;
799+
DatumouterAddInfo= (Datum)0;
800+
boolouterAddInfoIsNull= true;
761801

762802
insertCtx=AllocSetContextCreate(CurrentMemoryContext,
763803
"Rum insert temporary context",
@@ -769,6 +809,12 @@ ruminsert(Relation index, Datum *values, bool *isnull,
769809

770810
initRumState(&rumstate,index);
771811

812+
if (AttributeNumberIsValid(rumstate.attrnOrderByColumn))
813+
{
814+
outerAddInfo=values[rumstate.attrnOrderByColumn-1];
815+
outerAddInfoIsNull=isnull[rumstate.attrnOrderByColumn-1];
816+
}
817+
772818
if (RumGetUseFastUpdate(index))
773819
{
774820
RumTupleCollectorcollector;
@@ -788,7 +834,8 @@ ruminsert(Relation index, Datum *values, bool *isnull,
788834
for (i=0;i<rumstate.origTupdesc->natts;i++)
789835
rumHeapTupleInsert(&rumstate, (OffsetNumber) (i+1),
790836
values[i],isnull[i],
791-
ht_ctid);
837+
ht_ctid,
838+
outerAddInfo,outerAddInfoIsNull);
792839
}
793840

794841
MemoryContextSwitchTo(oldCtx);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp