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

Commit5a1b5f5

Browse files
committed
Disallow to create index using ordering over pass-by-reference AddInfo
Currently RUM has bogus behaviour when one creates an index usingordering over pass-by-reference AddInfo. This is due to the factthat posting trees have fixed length right bound and fixed lengthnon-leaf posting items.
1 parentcd89098 commit5a1b5f5

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

‎expected/text.out

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,18 @@ SELECT id FROM test_text_o WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
125125
(8 rows)
126126

127127
CREATE TABLE test_text_a AS SELECT id::text, t FROM tsts;
128+
-- Should fail, temporarly it isn't allowed to order an index over pass-by-reference column
128129
CREATE INDEX test_text_a_idx ON test_text_a USING rum
129130
(t rum_tsvector_addon_ops, id)
130131
WITH (attach = 'id', to = 't', order_by_attach='t');
132+
ERROR: doesn't support order index over pass-by-reference column
131133
EXPLAIN (costs off)
132134
SELECT count(*) FROM test_text_a WHERE id < '400';
133-
QUERY PLAN
134-
-------------------------------------------------------
135+
QUERY PLAN
136+
------------------------------------
135137
Aggregate
136-
->Index Scan using test_text_a_idx on test_text_a
137-
Index Cond: (id < '400'::text)
138+
->Seq Scan on test_text_a
139+
Filter: (id < '400'::text)
138140
(3 rows)
139141

140142
SELECT count(*) FROM test_text_a WHERE id < '400';
@@ -145,12 +147,12 @@ SELECT count(*) FROM test_text_a WHERE id < '400';
145147

146148
EXPLAIN (costs off)
147149
SELECT id FROM test_text_a WHERE t @@ 'wr&qh' AND id <= '400' ORDER BY id;
148-
QUERY PLAN
149-
---------------------------------------------------------------------------------
150+
QUERY PLAN
151+
-----------------------------------------------------------------------------
150152
Sort
151153
Sort Key: id
152-
->Index Scan using test_text_a_idx on test_text_a
153-
Index Cond: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id <= '400'::text))
154+
->Seq Scan on test_text_a
155+
Filter: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id <= '400'::text))
154156
(4 rows)
155157

156158
SELECT id FROM test_text_a WHERE t @@ 'wr&qh' AND id <= '400' ORDER BY id;
@@ -169,12 +171,12 @@ SELECT id FROM test_text_a WHERE t @@ 'wr&qh' AND id <= '400' ORDER BY id;
169171

170172
EXPLAIN (costs off)
171173
SELECT id FROM test_text_a WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
172-
QUERY PLAN
173-
---------------------------------------------------------------------------------
174+
QUERY PLAN
175+
-----------------------------------------------------------------------------
174176
Sort
175177
Sort Key: id
176-
->Index Scan using test_text_a_idx on test_text_a
177-
Index Cond: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id >= '400'::text))
178+
->Seq Scan on test_text_a
179+
Filter: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id >= '400'::text))
178180
(4 rows)
179181

180182
SELECT id FROM test_text_a WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
@@ -242,16 +244,18 @@ SELECT id FROM test_text_h_o WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
242244
(8 rows)
243245

244246
CREATE TABLE test_text_h_a AS SELECT id::text, t FROM tsts;
247+
-- Should fail, temporarly it isn't allowed to order an index over pass-by-reference column
245248
CREATE INDEX test_text_h_a_idx ON test_text_h_a USING rum
246249
(t rum_tsvector_hash_addon_ops, id)
247250
WITH (attach = 'id', to = 't', order_by_attach='t');
251+
ERROR: doesn't support order index over pass-by-reference column
248252
EXPLAIN (costs off)
249253
SELECT count(*) FROM test_text_h_a WHERE id < '400';
250-
QUERY PLAN
251-
-----------------------------------------------------------
254+
QUERY PLAN
255+
------------------------------------
252256
Aggregate
253-
->Index Scan using test_text_h_a_idx on test_text_h_a
254-
Index Cond: (id < '400'::text)
257+
->Seq Scan on test_text_h_a
258+
Filter: (id < '400'::text)
255259
(3 rows)
256260

257261
SELECT count(*) FROM test_text_h_a WHERE id < '400';
@@ -262,12 +266,12 @@ SELECT count(*) FROM test_text_h_a WHERE id < '400';
262266

263267
EXPLAIN (costs off)
264268
SELECT id FROM test_text_h_a WHERE t @@ 'wr&qh' AND id <= '400' ORDER BY id;
265-
QUERY PLAN
266-
---------------------------------------------------------------------------------
269+
QUERY PLAN
270+
-----------------------------------------------------------------------------
267271
Sort
268272
Sort Key: id
269-
->Index Scan using test_text_h_a_idx on test_text_h_a
270-
Index Cond: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id <= '400'::text))
273+
->Seq Scan on test_text_h_a
274+
Filter: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id <= '400'::text))
271275
(4 rows)
272276

273277
SELECT id FROM test_text_h_a WHERE t @@ 'wr&qh' AND id <= '400' ORDER BY id;
@@ -286,12 +290,12 @@ SELECT id FROM test_text_h_a WHERE t @@ 'wr&qh' AND id <= '400' ORDER BY id;
286290

287291
EXPLAIN (costs off)
288292
SELECT id FROM test_text_h_a WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
289-
QUERY PLAN
290-
---------------------------------------------------------------------------------
293+
QUERY PLAN
294+
-----------------------------------------------------------------------------
291295
Sort
292296
Sort Key: id
293-
->Index Scan using test_text_h_a_idx on test_text_h_a
294-
Index Cond: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id >= '400'::text))
297+
->Seq Scan on test_text_h_a
298+
Filter: ((t @@ '''wr'' & ''qh'''::tsquery) AND (id >= '400'::text))
295299
(4 rows)
296300

297301
SELECT id FROM test_text_h_a WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;

‎sql/text.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SELECT id FROM test_text_o WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
3737

3838
CREATETABLEtest_text_aASSELECT id::text, tFROM tsts;
3939

40+
-- Should fail, temporarly it isn't allowed to order an index over pass-by-reference column
4041
CREATEINDEXtest_text_a_idxON test_text_a USING rum
4142
(t rum_tsvector_addon_ops, id)
4243
WITH (attach='id', to='t', order_by_attach='t');
@@ -67,6 +68,7 @@ SELECT id FROM test_text_h_o WHERE t @@ 'wr&qh' AND id >= '400' ORDER BY id;
6768

6869
CREATETABLEtest_text_h_aASSELECT id::text, tFROM tsts;
6970

71+
-- Should fail, temporarly it isn't allowed to order an index over pass-by-reference column
7072
CREATEINDEXtest_text_h_a_idxON test_text_h_a USING rum
7173
(t rum_tsvector_hash_addon_ops, id)
7274
WITH (attach='id', to='t', order_by_attach='t');

‎src/rum.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ typedef signed char RumNullCategory;
262262
/*
263263
* Data (posting tree) pages
264264
*/
265+
/*
266+
* FIXME -- Currently RumItem is placed as a pages right bound and PostingItem
267+
* is placed as a non-leaf pages item. Both RumItem and PostingItem stores
268+
* AddInfo as a raw Datum, which is bogus. It is fine for pass-by-value
269+
* attributes, but it isn't for pass-by-reference, which may have variable
270+
* length of data. This AddInfo is used only by order_by_attach indexes, so it
271+
* isn't allowed to create index using ordering over pass-by-reference AddInfo,
272+
* see initRumState(). This can be solved by having non-fixed length right bound
273+
* and non-fixed non-leaf posting tree item.
274+
*/
265275
#defineRumDataPageGetRightBound(page)((RumItem*) PageGetContents(page))
266276
#defineRumDataPageGetData(page)\
267277
(PageGetContents(page) + MAXALIGN(sizeof(RumItem)))

‎src/rumutil.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ initRumState(RumState * state, Relation index)
239239
if (OidIsValid(rumConfig->addInfoTypeOid))
240240
elog(ERROR,"AddTo could should not have AddInfo");
241241

242+
if (state->useAlternativeOrder&&origAddAttr->attbyval== false)
243+
elog(ERROR,"doesn't support order index over pass-by-reference column");
244+
242245
rumConfig->addInfoTypeOid=origAddAttr->atttypid;
243246
}
244247

@@ -565,6 +568,7 @@ RumInitPage(Page page, uint32 f, Size pageSize)
565568
opaque->flags=f;
566569
opaque->leftlink=InvalidBlockNumber;
567570
opaque->rightlink=InvalidBlockNumber;
571+
RumItemSetMin(RumDataPageGetRightBound(page));
568572
}
569573

570574
void

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp