Skip to content

Commit 71e1f53

Browse files
committed
Please apply patches for contrib/ltree.
ltree_73.patch.gz - for 7.3 : Fix ~ operation bug: eg '1.1.1' ~ '*.1' ltree_74.patch.gz - for current CVS Fix ~ operation bug: eg '1.1.1' ~ '*.1' Add ? operation Optimize index storage Last change needs drop/create all ltree indexes, so only for 7.4 Teodor Sigaev
1 parent a286f73 commit 71e1f53

File tree

9 files changed

+509
-128
lines changed

9 files changed

+509
-128
lines changed

contrib/ltree/README.ltree

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ ltree <@ ltree
110110
equal).
111111
ltree ~ lquery, lquery ~ ltree
112112
- return TRUE if node represented by ltree satisfies lquery.
113+
ltree ? lquery[], lquery ? ltree[]
114+
- return TRUE if node represented by ltree satisfies at least one lquery
115+
from array.
113116
ltree @ ltxtquery, ltxtquery @ ltree
114117
- return TRUE if node represented by ltree satisfies ltxtquery.
115118
ltree || ltree, ltree || text, text || ltree
@@ -123,6 +126,9 @@ ltree @> ltree[], ltree[] <@ ltree
123126
- returns TRUE if array ltree[] contains a descendant of ltree.
124127
ltree[] ~ lquery, lquery ~ ltree[]
125128
- returns TRUE if array ltree[] contains label paths matched lquery.
129+
ltree[] ? lquery[], lquery[] ? ltree[]
130+
- returns TRUE if array ltree[] contains label paths matched atleaset one
131+
lquery from array.
126132
ltree[] @ ltxtquery, ltxtquery @ ltree[]
127133
- returns TRUE if array ltree[] contains label paths matched ltxtquery
128134
(full text search).
@@ -142,11 +148,11 @@ Various indices could be created to speed up execution of operations:
142148
* B-tree index over ltree:
143149
<, <=, =, =>, >
144150
* GiST index over ltree:
145-
<, <=, =, =>, >, @>, <@, @, ~
151+
<, <=, =, =>, >, @>, <@, @, ~, ?
146152
Example:
147153
create index path_gist_idx on test using gist (path);
148154
* GiST index over ltree[]:
149-
ltree[]<@ ltree, ltree @> ltree[], @, ~.
155+
ltree[]<@ ltree, ltree @> ltree[], @, ~, ?.
150156
Example:
151157
create index path_gist_idx on test using gist (array_path);
152158
Notices: This index is lossy.
@@ -426,6 +432,10 @@ appreciate your input. So far, below some (rather obvious) results:
426432

427433
CHANGES
428434

435+
Feb 7, 2003
436+
Add ? operation
437+
Fix ~ operation bug: eg '1.1.1' ~ '*.1'
438+
Optimize index storage
429439
Aug 9, 2002
430440
Fixed very stupid but important bug :-)
431441
July 31, 2002

contrib/ltree/_ltree_gist.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
9696
entry->rel, entry->page,
9797
entry->offset, key->len, FALSE);
9898
}
99-
else
99+
else if ( !LTG_ISALLTRUE(entry->key) )
100100
{
101101
int4 i,
102102
len;
@@ -105,10 +105,9 @@ _ltree_compress(PG_FUNCTION_ARGS)
105105
BITVECP sign = LTG_SIGN(DatumGetPointer(entry->key));
106106

107107
ALOOPBYTE(
108-
if (sign[i] != 0xff)
108+
if ((sign[i]&0xff) != 0xff)
109109
PG_RETURN_POINTER(retval);
110110
);
111-
112111
len = LTG_HDRSIZE;
113112
key = (ltree_gist *) palloc(len);
114113
key->len = len;
@@ -222,7 +221,7 @@ _ltree_penalty(PG_FUNCTION_ARGS)
222221

223222
if (LTG_ISALLTRUE(origval))
224223
{
225-
*penalty = 0.0;
224+
*penalty = 0.1;
226225
PG_RETURN_POINTER(penalty);
227226
}
228227

@@ -489,7 +488,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
489488
);
490489
}
491490

492-
if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.1))
491+
if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.00001))
493492
{
494493
if (!LTG_ISALLTRUE(datum_l))
495494
{
@@ -613,6 +612,22 @@ gist_qe(ltree_gist * key, lquery * query)
613612
return true;
614613
}
615614

615+
static bool
616+
_arrq_cons(ltree_gist *key, ArrayType *_query) {
617+
lquery *query = (lquery *) ARR_DATA_PTR(_query);
618+
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
619+
620+
if (ARR_NDIM(_query) != 1)
621+
elog(ERROR, "Dimension of array != 1");
622+
623+
while (num > 0) {
624+
if ( gist_qe(key, query) )
625+
return true;
626+
num--;
627+
query = (lquery*)NEXTVAL(query);
628+
}
629+
return false;
630+
}
616631

617632
Datum
618633
_ltree_consistent(PG_FUNCTION_ARGS)
@@ -641,6 +656,10 @@ _ltree_consistent(PG_FUNCTION_ARGS)
641656
case 15:
642657
res = gist_qtxt(key, (ltxtquery *) query);
643658
break;
659+
case 16:
660+
case 17:
661+
res = _arrq_cons(key, (ArrayType *) query);
662+
break;
644663
default:
645664
elog(ERROR, "Unknown StrategyNumber: %d", strategy);
646665
}

contrib/ltree/_ltree_op.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PG_FUNCTION_INFO_V1(_ltree_risparent);
1313
PG_FUNCTION_INFO_V1(_ltree_r_risparent);
1414
PG_FUNCTION_INFO_V1(_ltq_regex);
1515
PG_FUNCTION_INFO_V1(_ltq_rregex);
16+
PG_FUNCTION_INFO_V1(_lt_q_regex);
17+
PG_FUNCTION_INFO_V1(_lt_q_rregex);
1618
PG_FUNCTION_INFO_V1(_ltxtq_exec);
1719
PG_FUNCTION_INFO_V1(_ltxtq_rexec);
1820

@@ -126,6 +128,42 @@ _ltq_rregex(PG_FUNCTION_ARGS)
126128
));
127129
}
128130

131+
Datum
132+
_lt_q_regex(PG_FUNCTION_ARGS)
133+
{
134+
ArrayType *_tree = PG_GETARG_ARRAYTYPE_P(0);
135+
ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
136+
lquery *query = (lquery *) ARR_DATA_PTR(_query);
137+
bool res = false;
138+
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
139+
140+
if (ARR_NDIM(_query) != 1)
141+
elog(ERROR, "Dimension of array != 1");
142+
143+
while (num > 0) {
144+
if ( array_iterator(_tree, ltq_regex, (void*)query, NULL) ) {
145+
res = true;
146+
break;
147+
}
148+
num--;
149+
query = (lquery*)NEXTVAL(query);
150+
}
151+
152+
PG_FREE_IF_COPY(_tree, 0);
153+
PG_FREE_IF_COPY(_query, 1);
154+
PG_RETURN_BOOL(res);
155+
}
156+
157+
Datum
158+
_lt_q_rregex(PG_FUNCTION_ARGS)
159+
{
160+
PG_RETURN_DATUM(DirectFunctionCall2(_lt_q_regex,
161+
PG_GETARG_DATUM(1),
162+
PG_GETARG_DATUM(0)
163+
));
164+
}
165+
166+
129167
Datum
130168
_ltxtq_exec(PG_FUNCTION_ARGS)
131169
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy