Skip to content

Commit 0f8c311

Browse files
committed
Update README. Add information about array ops.
1 parent 6838aa2 commit 0f8c311

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: README.md

+32
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,38 @@ For type: `anyarray`
227227

228228
This operator class stores `anyarrray` elements with length of the array.
229229
Supports operators `&&`, `@>`, `<@`, `=`, `%` operators. Supports ordering by `<=>` operator.
230+
For example we have the table:
231+
232+
```sql
233+
CREATE TABLE test_array (i int2[]);
234+
235+
INSERT INTO test_array VALUES ('{}'), ('{0}'), ('{1,2,3,4}'), ('{1,2,3}'), ('{1,2}'), ('{1}');
236+
237+
CREATE INDEX idx_array ON test_array USING rum (i rum_anyarray_ops);
238+
```
239+
240+
Now we can execute the query using index scan:
241+
242+
```sql
243+
SET enable_seqscan TO off;
244+
245+
EXPLAIN (COSTS OFF) SELECT * FROM test_array WHERE i && '{1}' ORDER BY i <=> '{1}' ASC;
246+
QUERY PLAN
247+
------------------------------------------
248+
Index Scan using idx_array on test_array
249+
Index Cond: (i && '{1}'::smallint[])
250+
Order By: (i <=> '{1}'::smallint[])
251+
(3 rows
252+
253+
SELECT * FROM test_array WHERE i && '{1}' ORDER BY i <=> '{1}' ASC;
254+
i
255+
-----------
256+
{1}
257+
{1,2}
258+
{1,2,3}
259+
{1,2,3,4}
260+
(4 rows)
261+
```
230262

231263
### rum_anyarray_addon_ops
232264

0 commit comments

Comments
 (0)