Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d0e1e86

Browse files
committed
add to RumConfig knowledge about scan direction depending on strategy
1 parent d0dd137 commit d0e1e86

File tree

7 files changed

+48
-4
lines changed

7 files changed

+48
-4
lines changed

expected/rum.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
8787
'def <2> fgr');
8888
count
8989
-------
90-
2
90+
1
9191
(1 row)
9292

9393
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way')), *

rum--1.0.sql

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ RETURNS int4
119119
AS 'MODULE_PATHNAME'
120120
LANGUAGE C STRICT IMMUTABLE;
121121

122+
CREATE FUNCTION rum_timestamp_config(internal)
123+
RETURNS void
124+
AS 'MODULE_PATHNAME'
125+
LANGUAGE C IMMUTABLE STRICT;
126+
122127
CREATE FUNCTION rum_timestamp_extract_query(timestamp,internal,smallint,internal,internal,internal,internal)
123128
RETURNS internal
124129
AS 'MODULE_PATHNAME'
@@ -148,6 +153,7 @@ AS
148153
FUNCTION 3 rum_timestamp_extract_query(timestamp,internal,smallint,internal,internal,internal,internal),
149154
FUNCTION 4 rum_timestamp_consistent(internal,smallint,timestamp,int,internal,internal,internal,internal),
150155
FUNCTION 5 rum_timestamp_compare_prefix(timestamp,timestamp,smallint,internal),
156+
FUNCTION 6 rum_timestamp_config(internal),
151157
-- support to timestamp disttance in rum_tsvector_timestamp_ops
152158
FUNCTION 9 rum_timestamp_outer_distance(timestamp, timestamp, smallint),
153159
OPERATOR 20 <=> (timestamp,timestamp) FOR ORDER BY pg_catalog.float_ops,

rum.h

-2
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,4 @@ extern Datum FunctionCall10Coll(FmgrInfo *flinfo, Oid collation,
985985
Datum arg6, Datum arg7, Datum arg8,
986986
Datum arg9, Datum arg10);
987987

988-
#define FROM_STRATEGY (21)
989-
990988
#endif /* __RUM_H__ */

rum_timestamp.c

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <limits.h>
44

55
#include "access/stratnum.h"
6+
#include "rum.h"
67
#include "utils/builtins.h"
78
#include "utils/timestamp.h"
89

@@ -270,3 +271,20 @@ rum_timestamp_outer_distance(PG_FUNCTION_ARGS)
270271

271272
PG_RETURN_DATUM(diff);
272273
}
274+
275+
PG_FUNCTION_INFO_V1(rum_timestamp_config);
276+
Datum
277+
rum_timestamp_config(PG_FUNCTION_ARGS)
278+
{
279+
RumConfig *config = (RumConfig *) PG_GETARG_POINTER(0);
280+
281+
config->addInfoTypeOid = InvalidOid;
282+
283+
config->strategyInfo[0].strategy = RUM_TMST_LEFT_DISTANCE;
284+
config->strategyInfo[0].direction = ForwardScanDirection;
285+
286+
config->strategyInfo[1].strategy = InvalidStrategy;
287+
288+
PG_RETURN_VOID();
289+
}
290+

rum_ts_utils.c

+2
Original file line numberDiff line numberDiff line change
@@ -1202,5 +1202,7 @@ rum_tsvector_config(PG_FUNCTION_ARGS)
12021202
RumConfig *config = (RumConfig *) PG_GETARG_POINTER(0);
12031203

12041204
config->addInfoTypeOid = BYTEAOID;
1205+
config->strategyInfo[0].strategy = InvalidStrategy;
1206+
12051207
PG_RETURN_VOID();
12061208
}

rumscan.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ initScanKey(RumScanOpaque so, ScanKey skey, bool *hasNullQuery)
391391
(skey->sk_flags & SK_ORDER_BY) ? true : false);
392392
}
393393

394+
static ScanDirection
395+
lookupScanDirection(RumState *state, AttrNumber attno, StrategyNumber strategy)
396+
{
397+
int i;
398+
RumConfig *rumConfig = state->rumConfig + attno - 1;
399+
400+
for(i = 0; rumConfig->strategyInfo[i].strategy != InvalidStrategy &&
401+
i < MAX_STRATEGIES; i++)
402+
{
403+
if (rumConfig->strategyInfo[i].strategy == strategy)
404+
return rumConfig->strategyInfo[i].direction;
405+
406+
}
407+
408+
return NoMovementScanDirection;
409+
}
410+
394411
static void
395412
fillMarkAddInfo(RumScanOpaque so, RumScanKey orderKey)
396413
{
@@ -405,7 +422,8 @@ fillMarkAddInfo(RumScanOpaque so, RumScanKey orderKey)
405422

406423
if (scanKey->attnum == so->rumstate.attrnAddToColumn &&
407424
orderKey->attnum == so->rumstate.attrnAddToColumn &&
408-
orderKey->strategy == FROM_STRATEGY /* FIXME teodor */)
425+
lookupScanDirection(&so->rumstate, orderKey->attnumOrig,
426+
orderKey->strategy) == ForwardScanDirection)
409427
{
410428
int j;
411429

rumtsquery.c

+2
Original file line numberDiff line numberDiff line change
@@ -629,5 +629,7 @@ ruminv_tsquery_config(PG_FUNCTION_ARGS)
629629
RumConfig *config = (RumConfig *) PG_GETARG_POINTER(0);
630630

631631
config->addInfoTypeOid = BYTEAOID;
632+
config->strategyInfo[0].strategy = InvalidStrategy;
633+
632634
PG_RETURN_VOID();
633635
}

0 commit comments

Comments
 (0)