Skip to content

Commit f7e0d94

Browse files
committed
add orderby initial test
1 parent 47bd24b commit f7e0d94

File tree

6 files changed

+555
-3
lines changed

6 files changed

+555
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ EXTENSION = rum
1111
DATA = rum--1.0.sql
1212
PGFILEDESC = "RUM index access method"
1313

14-
REGRESS = rum timestamp
14+
REGRESS = rum timestamp orderby
1515

1616
ifdef USE_PGXS
1717
PG_CONFIG = pg_config

data/tsts.data

Lines changed: 508 additions & 0 deletions
Large diffs are not rendered by default.

expected/orderby.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE tsts (id int, t tsvector, d timestamp);
2+
\copy tsts from 'data/tsts.data'
3+
CREATE INDEX tsts_idx ON tsts USING rum (t rum_tsvector_ops, d) WITH (orderby = 'd');

rum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ typedef struct RumOptions
294294
{
295295
int32 vl_len_; /* varlena header (do not touch directly!) */
296296
bool useFastUpdate; /* use fast updates? */
297+
int orderByColumn;
297298
} RumOptions;
298299

299300
#define RUM_DEFAULT_USE_FASTUPDATE false
@@ -315,6 +316,7 @@ typedef struct RumState
315316
{
316317
Relation index;
317318
bool oneCol; /* true if single-column index */
319+
AttrNumber attrnOrderByColumn;
318320

319321
/*
320322
* origTupDesc is the nominal tuple descriptor of the index, ie, the i'th

rumutil.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "storage/lmgr.h"
2121
#include "utils/guc.h"
2222
#include "utils/index_selfuncs.h"
23+
#include "utils/lsyscache.h"
2324

2425
#include "rum.h"
2526

@@ -29,6 +30,8 @@ void _PG_init(void);
2930

3031
PG_FUNCTION_INFO_V1(rumhandler);
3132

33+
/* Kind of relation optioms for rum index */
34+
static relopt_kind rum_relopt_kind;
3235
/*
3336
* Module load callback
3437
*/
@@ -43,6 +46,12 @@ _PG_init(void)
4346
0, 0, INT_MAX,
4447
PGC_USERSET, 0,
4548
NULL, NULL, NULL);
49+
50+
rum_relopt_kind = add_reloption_kind();
51+
52+
add_string_reloption(rum_relopt_kind, "orderby",
53+
"Column name to order by operation",
54+
NULL, NULL);
4655
}
4756

4857
/*
@@ -242,6 +251,29 @@ initRumState(RumState *state, Relation index)
242251
else
243252
state->supportCollation[i] = DEFAULT_COLLATION_OID;
244253
}
254+
255+
state->attrnOrderByColumn = InvalidAttrNumber;
256+
257+
if (index->rd_options)
258+
{
259+
RumOptions *options = (RumOptions*) index->rd_options;
260+
261+
if (options->orderByColumn > 0)
262+
{
263+
char *colname = (char *) options + options->orderByColumn;
264+
AttrNumber attrnOrderByHeapColumn;
265+
266+
attrnOrderByHeapColumn = get_attnum(index->rd_index->indrelid, colname);
267+
268+
if (!AttributeNumberIsValid(attrnOrderByHeapColumn))
269+
elog(ERROR, "attribute \"%s\" is not found in table", colname);
270+
271+
state->attrnOrderByColumn = get_attnum(index->rd_id, colname);
272+
273+
if (!AttributeNumberIsValid(state->attrnOrderByColumn))
274+
elog(ERROR, "attribute \"%s\" is not found in index", colname);
275+
}
276+
}
245277
}
246278

247279
/*
@@ -685,10 +717,11 @@ rumoptions(Datum reloptions, bool validate)
685717
RumOptions *rdopts;
686718
int numoptions;
687719
static const relopt_parse_elt tab[] = {
688-
{"fastupdate", RELOPT_TYPE_BOOL, offsetof(RumOptions, useFastUpdate)}
720+
{"fastupdate", RELOPT_TYPE_BOOL, offsetof(RumOptions, useFastUpdate)},
721+
{"orderby", RELOPT_TYPE_STRING, offsetof(RumOptions, orderByColumn)}
689722
};
690723

691-
options = parseRelOptions(reloptions, validate, RELOPT_KIND_GIN,
724+
options = parseRelOptions(reloptions, validate, rum_relopt_kind,
692725
&numoptions);
693726

694727
/* if none set, we're done */

sql/orderby.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE tsts (id int, t tsvector, d timestamp);
2+
3+
\copy tsts from 'data/tsts.data'
4+
5+
CREATE INDEX tsts_idx ON tsts USING rum (t rum_tsvector_ops, d) WITH (orderby = 'd');
6+

0 commit comments

Comments
 (0)