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

Commitd714560

Browse files
committed
Add rtee box index discussion.
1 parent5859215 commitd714560

File tree

1 file changed

+316
-0
lines changed

1 file changed

+316
-0
lines changed

‎doc/TODO.detail/rtree

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
From pgsql-bugs-owner+M10740=pgman=candle.pha.pa.us@postgresql.org Mon Jan 24 18:00:00 2005
2+
Return-path: <pgsql-bugs-owner+M10740=pgman=candle.pha.pa.us@postgresql.org>
3+
Received: from svr1.postgresql.org (svr1.postgresql.org [200.46.204.71])
4+
by candle.pha.pa.us (8.11.6/8.11.6) with ESMTP id j0ONxxw11019
5+
for <pgman@candle.pha.pa.us>; Mon, 24 Jan 2005 18:59:59 -0500 (EST)
6+
Received: from localhost (unknown [200.46.204.144])
7+
by svr1.postgresql.org (Postfix) with ESMTP id 182703A4CB1
8+
for <pgman@candle.pha.pa.us>; Mon, 24 Jan 2005 23:59:55 +0000 (GMT)
9+
Received: from svr1.postgresql.org ([200.46.204.71])
10+
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
11+
with ESMTP id 38013-02 for <pgman@candle.pha.pa.us>;
12+
Mon, 24 Jan 2005 23:59:53 +0000 (GMT)
13+
Received: from postgresql.org (svr1.postgresql.org [200.46.204.71])
14+
by svr1.postgresql.org (Postfix) with ESMTP id 4B17E3A4B12
15+
for <pgman@candle.pha.pa.us>; Mon, 24 Jan 2005 23:59:54 +0000 (GMT)
16+
X-Original-To: pgsql-bugs-postgresql.org@localhost.postgresql.org
17+
Received: from localhost (unknown [200.46.204.144])
18+
by svr1.postgresql.org (Postfix) with ESMTP id E7E323A53D0
19+
for <pgsql-bugs-postgresql.org@localhost.postgresql.org>; Mon, 24 Jan 2005 23:44:58 +0000 (GMT)
20+
Received: from svr1.postgresql.org ([200.46.204.71])
21+
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
22+
with ESMTP id 14037-08
23+
for <pgsql-bugs-postgresql.org@localhost.postgresql.org>;
24+
Mon, 24 Jan 2005 23:44:45 +0000 (GMT)
25+
Received: by svr1.postgresql.org (Postfix, from userid 1001)
26+
id 1C2D53A585A; Tue, 25 Jan 2005 00:59:20 +0000 (GMT)
27+
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.250.190.2])
28+
by svr1.postgresql.org (Postfix) with ESMTP id C0CB23A573E
29+
for <pgsql-bugs@postgresql.org>; Mon, 24 Jan 2005 23:29:17 +0000 (GMT)
30+
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
31+
id EF14E31D91; Tue, 25 Jan 2005 00:29:16 +0100 (MET)
32+
From: Andrew - Supernews <andrew+nonews@supernews.com>
33+
X-Newsgroups: pgsql.bugs
34+
Subject: [BUGS] incorrect index behaviour with rtree on box values
35+
Date: Mon, 24 Jan 2005 23:29:12 -0000
36+
Organization: http://www.supernews.com - all your nntp are belong to us
37+
Message-ID: <slrncvb167.5vn.andrew+nonews@trinity.supernews.net>
38+
Reply-To: andrew@supernews.com
39+
User-Agent: slrn/0.9.8.0 (FreeBSD)
40+
X-Complaints-To: abuse@supernews.com
41+
Lines: 56
42+
To: pgsql-bugs@postgresql.org
43+
X-Virus-Scanned: by amavisd-new at hub.org
44+
X-Mailing-List: pgsql-bugs
45+
Precedence: bulk
46+
Sender: pgsql-bugs-owner@postgresql.org
47+
X-Virus-Scanned: by amavisd-new at hub.org
48+
X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on
49+
candle.pha.pa.us
50+
X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham
51+
version=2.61
52+
Status: OR
53+
54+
Testcase:
55+
56+
create table boxtest (a box);
57+
create index boxtest_idx on boxtest using rtree (a);
58+
59+
create function gen_data() returns void as '
60+
begin for i in 1..200 loop
61+
insert into boxtest
62+
values (box(point((i*2-1)::float,0),point((i*2)::float,1)));
63+
end loop;
64+
return;
65+
end;' language plpgsql;
66+
67+
select gen_data();
68+
analyze boxtest;
69+
70+
set enable_seqscan = false;
71+
set enable_bitmapscan = true;
72+
set enable_indexscan = true;
73+
select * from boxtest where a << '(3,0),(3,1)'::box;
74+
set enable_seqscan = true;
75+
set enable_bitmapscan = false;
76+
set enable_indexscan = false;
77+
select * from boxtest where a << '(3,0),(3,1)'::box;
78+
79+
80+
Those two selects at the end should clearly return the same result, a
81+
single row. In fact, what happens is that the second returns no rows at
82+
all; I tested this on 7.4.6, but others have confirmed this on everything
83+
from 7.3 to latest.
84+
85+
The problem is that the semantics of the &< and &> operators for the box
86+
type are not what rtree needs for the "OverLeft" and "OverRight" slots of
87+
the operator class. Specifically, what rtree needs is this:
88+
89+
if X << K or X &< K
90+
then for all A where A is a union of values including X,
91+
then A &< K
92+
93+
(the designation "&<" is of course arbitrary, what matters is what operator
94+
is placed in the applicable slot of the opclass. Same goes for >> and &>.)
95+
96+
This is because rtree converts (see rtstrat.c) the original "Left" operator
97+
to an "OverLeft" when comparing against internal nodes of the index, which
98+
contain values which are the union of all values in their subtree. In the
99+
testcase, the top node of the tree contains as its first entry a union
100+
value of the form (184,1),(1,0), which the scan then rejects since
101+
(184,1),(1,0) &< (3,0),(3,1) is false.
102+
103+
I can see three possible approaches to fixing this:
104+
105+
1) change the semantics of &< and &> to match rtree's expectations
106+
107+
2) replace &< and &> in the opclass with operators that behave as rtree
108+
expects (this will have the side effect of rendering &< and &> un-indexable)
109+
110+
3) change rtree's behaviour in some way.
111+
112+
--
113+
Andrew, Supernews
114+
http://www.supernews.com - individual and corporate NNTP services
115+
116+
---------------------------(end of broadcast)---------------------------
117+
TIP 2: you can get off all lists at once with the unregister command
118+
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
119+
120+
From pgsql-bugs-owner+M10748=pgman=candle.pha.pa.us@postgresql.org Mon Jan 24 18:57:46 2005
121+
Return-path: <pgsql-bugs-owner+M10748=pgman=candle.pha.pa.us@postgresql.org>
122+
Received: from svr1.postgresql.org (svr1.postgresql.org [200.46.204.71])
123+
by candle.pha.pa.us (8.11.6/8.11.6) with ESMTP id j0P0vjw18152
124+
for <pgman@candle.pha.pa.us>; Mon, 24 Jan 2005 19:57:45 -0500 (EST)
125+
Received: from localhost (unknown [200.46.204.144])
126+
by svr1.postgresql.org (Postfix) with ESMTP id 1CD183A52F3
127+
for <pgman@candle.pha.pa.us>; Tue, 25 Jan 2005 00:57:41 +0000 (GMT)
128+
Received: from svr1.postgresql.org ([200.46.204.71])
129+
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
130+
with ESMTP id 43652-07 for <pgman@candle.pha.pa.us>;
131+
Tue, 25 Jan 2005 00:57:39 +0000 (GMT)
132+
Received: from postgresql.org (svr1.postgresql.org [200.46.204.71])
133+
by svr1.postgresql.org (Postfix) with ESMTP id 9FEA63A52C5
134+
for <pgman@candle.pha.pa.us>; Tue, 25 Jan 2005 00:57:40 +0000 (GMT)
135+
X-Original-To: pgsql-bugs-postgresql.org@localhost.postgresql.org
136+
Received: from localhost (unknown [200.46.204.144])
137+
by svr1.postgresql.org (Postfix) with ESMTP id 3E2AF3A1A35
138+
for <pgsql-bugs-postgresql.org@localhost.postgresql.org>; Tue, 25 Jan 2005 00:09:47 +0000 (GMT)
139+
Received: from svr1.postgresql.org ([200.46.204.71])
140+
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
141+
with ESMTP id 39621-06
142+
for <pgsql-bugs-postgresql.org@localhost.postgresql.org>;
143+
Tue, 25 Jan 2005 00:09:42 +0000 (GMT)
144+
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
145+
by svr1.postgresql.org (Postfix) with ESMTP id CAB643A19B8
146+
for <pgsql-bugs@postgresql.org>; Tue, 25 Jan 2005 00:09:41 +0000 (GMT)
147+
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
148+
by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j0P09fcc027307;
149+
Mon, 24 Jan 2005 19:09:42 -0500 (EST)
150+
To: andrew@supernews.com
151+
cc: pgsql-bugs@postgresql.org
152+
Subject: Re: [BUGS] incorrect index behaviour with rtree on box values
153+
In-Reply-To: <slrncvb167.5vn.andrew+nonews@trinity.supernews.net>
154+
References: <slrncvb167.5vn.andrew+nonews@trinity.supernews.net>
155+
Comments: In-reply-to Andrew - Supernews <andrew+nonews@supernews.com>
156+
message dated "Mon, 24 Jan 2005 23:29:12 +0000"
157+
Date: Mon, 24 Jan 2005 19:09:41 -0500
158+
Message-ID: <27306.1106611781@sss.pgh.pa.us>
159+
From: Tom Lane <tgl@sss.pgh.pa.us>
160+
X-Virus-Scanned: by amavisd-new at hub.org
161+
X-Mailing-List: pgsql-bugs
162+
Precedence: bulk
163+
Sender: pgsql-bugs-owner@postgresql.org
164+
X-Virus-Scanned: by amavisd-new at hub.org
165+
Status: OR
166+
167+
Andrew - Supernews <andrew+nonews@supernews.com> writes:
168+
> The problem is that the semantics of the &< and &> operators for the box
169+
> type are not what rtree needs for the "OverLeft" and "OverRight" slots of
170+
> the operator class.
171+
172+
This was observed nearly a year ago, see this thread:
173+
http://archives.postgresql.org/pgsql-general/2004-03/msg01135.php
174+
175+
but apparently no one cares enough to fix it. Are you volunteering?
176+
177+
regards, tom lane
178+
179+
---------------------------(end of broadcast)---------------------------
180+
TIP 8: explain analyze is your friend
181+
182+
From pgsql-bugs-owner+M10762=pgman=candle.pha.pa.us@postgresql.org Wed Jan 26 08:56:08 2005
183+
Return-path: <pgsql-bugs-owner+M10762=pgman=candle.pha.pa.us@postgresql.org>
184+
Received: from svr1.postgresql.org (svr1.postgresql.org [200.46.204.71])
185+
by candle.pha.pa.us (8.11.6/8.11.6) with ESMTP id j0QEu6w07027
186+
for <pgman@candle.pha.pa.us>; Wed, 26 Jan 2005 09:56:07 -0500 (EST)
187+
Received: from localhost (unknown [200.46.204.144])
188+
by svr1.postgresql.org (Postfix) with ESMTP id 86BC83A5C12
189+
for <pgman@candle.pha.pa.us>; Wed, 26 Jan 2005 14:56:02 +0000 (GMT)
190+
Received: from svr1.postgresql.org ([200.46.204.71])
191+
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
192+
with ESMTP id 26111-04 for <pgman@candle.pha.pa.us>;
193+
Wed, 26 Jan 2005 14:55:58 +0000 (GMT)
194+
Received: from postgresql.org (svr1.postgresql.org [200.46.204.71])
195+
by svr1.postgresql.org (Postfix) with ESMTP id 5329B3A5C0B
196+
for <pgman@candle.pha.pa.us>; Wed, 26 Jan 2005 14:56:02 +0000 (GMT)
197+
X-Original-To: pgsql-bugs-postgresql.org@localhost.postgresql.org
198+
Received: from localhost (unknown [200.46.204.144])
199+
by svr1.postgresql.org (Postfix) with ESMTP id 3C43C3A5801
200+
for <pgsql-bugs-postgresql.org@localhost.postgresql.org>; Wed, 26 Jan 2005 14:54:51 +0000 (GMT)
201+
Received: from svr1.postgresql.org ([200.46.204.71])
202+
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
203+
with ESMTP id 25627-10
204+
for <pgsql-bugs-postgresql.org@localhost.postgresql.org>;
205+
Wed, 26 Jan 2005 14:54:39 +0000 (GMT)
206+
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.250.190.2])
207+
by svr1.postgresql.org (Postfix) with ESMTP id 17AD33A516B
208+
for <pgsql-bugs@postgresql.org>; Wed, 26 Jan 2005 14:54:42 +0000 (GMT)
209+
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
210+
id F3BF931D93; Wed, 26 Jan 2005 15:54:43 +0100 (MET)
211+
From: Andrew - Supernews <andrew+nonews@supernews.com>
212+
X-Newsgroups: pgsql.bugs
213+
Subject: Re: [BUGS] incorrect index behaviour with rtree on box values
214+
Date: Wed, 26 Jan 2005 14:54:41 -0000
215+
Organization: http://www.supernews.com - all your nntp are belong to us
216+
Message-ID: <slrncvfbph.5vn.andrew+nonews@trinity.supernews.net>
217+
References: <slrncvb167.5vn.andrew+nonews@trinity.supernews.net> <27306.1106611781@sss.pgh.pa.us>
218+
Reply-To: andrew@supernews.com
219+
User-Agent: slrn/0.9.8.0 (FreeBSD)
220+
X-Complaints-To: abuse@supernews.com
221+
Lines: 79
222+
To: pgsql-bugs@postgresql.org
223+
X-Virus-Scanned: by amavisd-new at hub.org
224+
X-Mailing-List: pgsql-bugs
225+
Precedence: bulk
226+
Sender: pgsql-bugs-owner@postgresql.org
227+
X-Virus-Scanned: by amavisd-new at hub.org
228+
X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on
229+
candle.pha.pa.us
230+
X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham
231+
version=2.61
232+
Status: OR
233+
234+
On 2005-01-25, Tom Lane <tgl@sss.pgh.pa.us> wrote:
235+
> Andrew - Supernews <andrew+nonews@supernews.com> writes:
236+
>> The problem is that the semantics of the &< and &> operators for the box
237+
>> type are not what rtree needs for the "OverLeft" and "OverRight" slots of
238+
>> the operator class.
239+
>
240+
> This was observed nearly a year ago, see this thread:
241+
> http://archives.postgresql.org/pgsql-general/2004-03/msg01135.php
242+
>
243+
> but apparently no one cares enough to fix it. Are you volunteering?
244+
245+
Possibly. I don't feel comfortable with changing anything specific to the
246+
geometric operators, since (a) I don't actually use them (I discovered
247+
this issue when adding rtree support to a type of my own) and (b) the
248+
compatibility implications are obvious. But I think there is a solution
249+
that involves only changes to the rtree strategy code.
250+
251+
Looking at the earlier discussion: it seems to have ended with the
252+
conclusion that &< should mean "does not extend to the right of", which
253+
matches the current implementation for box, but not for some other types.
254+
255+
So for box values, we seem (and someone please correct me if I'm wrong) to
256+
have the following semantics:
257+
258+
a << b - a is strictly left of b, i.e. a.right < b.left
259+
a &< b - a is no further right than b, i.e. a.right <= b.right
260+
a &> b - a is no further left than b, i.e. a.left >= b.left
261+
a >> b - a is strictly right of b, i.e. a.left > b.right
262+
263+
For rtree to work as apparently intended, it needs four more operators,
264+
to use for inner nodes when the scan operator is one of the above four.
265+
However, a small modification to the way that the internal scan key is
266+
initialised should eliminate the requirement to explicitly specify these
267+
operators, which strikes me as the solution which preserves maximum
268+
compatibility. The four operators required are:
269+
270+
NOT (a &> b) (used when the scan operator is (a << b))
271+
NOT (a >> b) (used when the scan operator is (a &< b))
272+
NOT (a << b) (used when the scan operator is (a &> b))
273+
NOT (a &< b) (used when the scan operator is (a >> b))
274+
275+
(This won't fix rtree on contrib/seg or contrib/cube, but those appear to be
276+
broken already since they have different, and equally incorrect, definitions
277+
of &> and &<. Fixing those would require slightly more complex operators,
278+
such as NOT (a &> b OR a >> b) and so on. The more complex operators would
279+
work for box too, so it might be worth using them anyway, but I don't yet
280+
understand the scan key handling well enough to know if these can be
281+
constructed rather than supplied in the opclass.)
282+
283+
Proof:
284+
285+
Let V be the scan key, i.e. the value we are searching for in the index.
286+
Let U be a union over a set of values.
287+
Let X be some value for which X OP V holds.
288+
289+
Consider an internal node entry with union U. We require that the following
290+
holds: if U contains some value X where X OP V holds, then U OP' V must be
291+
true. (But not the converse; U OP' V may be true even if no such X exists in
292+
U. However, we wish it to be false as much as possible for efficiency.)
293+
294+
When OP is << :
295+
296+
X << V, therefore X.right < V.left, therefore X.left < V.left
297+
therefore NOT (X &> V)
298+
299+
If U contains X, then U &> V is true iff U.left >= V.left
300+
301+
U.left <= min(E.left) for all elements E of U, and therefore for X if X in U
302+
303+
So if X in U, then U.left <= X.left < V.left, and therefore NOT (U &> V)
304+
305+
When OP is &< :
306+
307+
X &< V, therefore X.right <= V.right, therefore X.left <= V.right
308+
therefore NOT (X >> V), and similar reasoning for U containing X as above.
309+
310+
--
311+
Andrew, Supernews
312+
http://www.supernews.com - individual and corporate NNTP services
313+
314+
---------------------------(end of broadcast)---------------------------
315+
TIP 7: don't forget to increase your free space map settings
316+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp