CREATE INDEX message_rdtree_idx ON message USING GIST ( sections gist__int_ops);
Definitions
- A <emphasis>label> of a node is a sequence of one or more words
+ A <firstterm>label> of a node is a sequence of one or more words
separated by blank character '_' and containing letters and digits ( for
example, [a-zA-Z0-9] for C locale). The length of a label is limited by 256
bytes.
Example: 'Countries', 'Personal_Services'
- A <emphasis>label path> of a node is a sequence of one or more
+ A <firstterm>label path> of a node is a sequence of one or more
dot-separated labels l1.l2...ln, represents path from root to the node. The
- length of a label path is limited by 65Kb, but size <= 2Kb is preferrable.
+ length of a label path is limited by 65Kb, but size <= 2Kb is preferrable.
We consider it's not a strict limitation (maximal size of label path for
DMOZ catalogue -
, is about 240
bytes!)
% Don't account word separator '_' in label matching, that is
- 'Russian%' would match 'Russian_nations', but not 'Russian'
+ 'Russian%' would match 'Russian_nations', but not 'Russian'
the end of word. The meaning of modifiers are the same as for lquery.
- Example: 'Europe & Russia*@ & !Transportation'
+ Example: 'Europe & Russia*@ & !Transportation'
Search paths contain words 'Europe' and 'Russia*' (case-insensitive) and
- <,>,<=,>=,=, <>
+ <,>,<=,>=,=, <>
- Have their usual meanings. Comparison is doing in the order of direct
tree traversing, children of a node are sorted lexicographic.
- ltree @> ltree
+ ltree @> ltree
- returns TRUE if left argument is an ancestor of right argument (or
equal).
- ltree <@ ltree
+ ltree <@ ltree
- returns TRUE if left argument is a descendant of right argument (or
equal).
- ltree[] @> ltree, ltree <@ ltree[]
+ ltree[] @> ltree, ltree <@ ltree[]
- returns TRUE if array ltree[] contains an ancestor of ltree.
- ltree @> ltree[], ltree[] <@ ltree
+ ltree @> ltree[], ltree[] <@ ltree
- returns TRUE if array ltree[] contains a descendant of ltree.
- ltree[] ?@> ltree, ltree ?<@ ltree[], ltree[] ?~ lquery, ltree[] ?@ ltxtquery
+ ltree[] ?@> ltree, ltree ?<@ ltree[], ltree[] ?~ lquery, ltree[] ?@ ltxtquery
- returns first element of array ltree[] satisfies corresponding condition
and NULL in vice versa.
- ltree[]<@ ltree, ltree @> ltree[], @, ~, ?.
+ ltree[]<@ ltree, ltree @> ltree[], @, ~, ?.
Example:
Example
createdb ltreetest
- psql ltreetest < /usr/local/pgsql/share/contrib/ltree.sql
- psql ltreetest < ltreetest.sql
+ psql ltreetest < /usr/local/pgsql/share/contrib/ltree.sql
+ psql ltreetest < ltreetest.sql
-ltreetest=# select path from test where path <@ 'Top.Science';
+ltreetest=# select path from test where path <@ 'Top.Science';
path
------------------------------------
Top.Science
Full text search:
-ltreetest=# select path from test where path @ 'Astro*% & !pictures@';
+ltreetest=# select path from test where path @ 'Astro*% & !pictures@';
path
------------------------------------
Top.Science.Astronomy
Top.Hobbies.Amateurs_Astronomy
(4 rows)
-ltreetest=# select path from test where path @ 'Astro* & !pictures@';
+ltreetest=# select path from test where path @ 'Astro* & !pictures@';
path
------------------------------------
Top.Science.Astronomy
Using Functions:
-ltreetest=# select subpath(path,0,2)||'Space'||subpath(path,2) from test where path <@ 'Top.Science.Astronomy';
+ltreetest=# select subpath(path,0,2)||'Space'||subpath(path,2) from test where path <@ 'Top.Science.Astronomy';
?column?
------------------------------------------
Top.Science.Space.Astronomy
-ltreetest=# select ins_label(path,2,'Space') from test where path <@ 'Top.Science.Astronomy';
+ltreetest=# select ins_label(path,2,'Space') from test where path <@ 'Top.Science.Astronomy';
ins_label
------------------------------------------
Top.Science.Space.Astronomy
AS 'select subpath($1,0,nlevel($2)) || $3 || subpath($1,nlevel($2));'
LANGUAGE SQL IMMUTABLE;
-ltreetest=# select ins_label(path,'Top.Science'::ltree,'Space') from test where path <@ 'Top.Science.Astronomy';
+ltreetest=# select ins_label(path,'Top.Science'::ltree,'Space') from test where path <@ 'Top.Science.Astronomy';
ins_label
------------------------------------------
Top.Science.Space.Astronomy
Q2: The same as Q1 but with counting of successors
- select path as parentpath , (select count(*)-1 from dmoz where path <@
+ select path as parentpath , (select count(*)-1 from dmoz where path <@
p.path) as count from dmoz p where path ~ 'Top.Adult.Arts.Animation.*{1}';
parentpath | count
-----------------------------------+-------
Q3: Get all parents
- select path from dmoz where path @> 'Top.Adult.Arts.Animation' order by
+ select path from dmoz where path @> 'Top.Adult.Arts.Animation' order by
path asc;
path
--------------------------
Q4: Get all parents with counting of children
- select path, (select count(*)-1 from dmoz where path <@ p.path) as count
- from dmoz p where path @> 'Top.Adult.Arts.Animation' order by path asc;
+ select path, (select count(*)-1 from dmoz where path <@ p.path) as count
+ from dmoz p where path @> 'Top.Adult.Arts.Animation' order by path asc;
path | count
--------------------------+--------
Top | 300273
For ltree we store LPS in a B-tree, implemented using GiST. Each node entry is
represented by (left_bound, signature, right_bound), so that we could speedup
- operations <, <=, =, >=, > using left_bound, right_bound and prune branches of
+ operations <, <=, =, >=, > using left_bound, right_bound and prune branches of
a tree using signature.
-