Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
de1f586f
Commit
de1f586f
authored
May 28, 2002
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a bug with building rtree_gist indexes.
Patch from Teodor Sigaev.
parent
a71a5307
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
20 deletions
+65
-20
contrib/rtree_gist/rtree_gist.c
contrib/rtree_gist/rtree_gist.c
+65
-20
No files found.
contrib/rtree_gist/rtree_gist.c
View file @
de1f586f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/contrib/rtree_gist/Attic/rtree_gist.c,v 1.
4 2001/10/25 05:49:20 momjian
Exp $
* $Header: /cvsroot/pgsql/contrib/rtree_gist/Attic/rtree_gist.c,v 1.
5 2002/05/28 15:24:53 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -161,6 +161,22 @@ gbox_penalty(PG_FUNCTION_ARGS)
...
@@ -161,6 +161,22 @@ gbox_penalty(PG_FUNCTION_ARGS)
PG_RETURN_POINTER
(
result
);
PG_RETURN_POINTER
(
result
);
}
}
typedef
struct
{
BOX
*
key
;
int
pos
;
}
KBsort
;
static
int
compare_KB
(
const
void
*
a
,
const
void
*
b
)
{
BOX
*
abox
=
((
KBsort
*
)
a
)
->
key
;
BOX
*
bbox
=
((
KBsort
*
)
b
)
->
key
;
float
sa
=
(
abox
->
high
.
x
-
abox
->
low
.
x
)
*
(
abox
->
high
.
y
-
abox
->
low
.
y
);
float
sb
=
(
bbox
->
high
.
x
-
bbox
->
low
.
x
)
*
(
bbox
->
high
.
y
-
bbox
->
low
.
y
);
if
(
sa
==
sb
)
return
0
;
return
(
sa
>
sb
)
?
1
:
-
1
;
}
/*
/*
** The GiST PickSplit method
** The GiST PickSplit method
** New linear algorithm, see 'New Linear Node Splitting Algorithm for R-tree',
** New linear algorithm, see 'New Linear Node Splitting Algorithm for R-tree',
...
@@ -201,26 +217,22 @@ gbox_picksplit(PG_FUNCTION_ARGS)
...
@@ -201,26 +217,22 @@ gbox_picksplit(PG_FUNCTION_ARGS)
for
(
i
=
OffsetNumberNext
(
FirstOffsetNumber
);
i
<=
maxoff
;
i
=
OffsetNumberNext
(
i
))
for
(
i
=
OffsetNumberNext
(
FirstOffsetNumber
);
i
<=
maxoff
;
i
=
OffsetNumberNext
(
i
))
{
{
cur
=
DatumGetBoxP
(((
GISTENTRY
*
)
VARDATA
(
entryvec
))[
i
].
key
);
cur
=
DatumGetBoxP
(((
GISTENTRY
*
)
VARDATA
(
entryvec
))[
i
].
key
);
if
(
pageunion
.
high
.
x
<
cur
->
high
.
x
)
if
(
allisequal
==
true
&&
(
{
pageunion
.
high
.
x
!=
cur
->
high
.
x
||
pageunion
.
high
.
y
!=
cur
->
high
.
y
||
pageunion
.
low
.
x
!=
cur
->
low
.
x
||
pageunion
.
low
.
y
!=
cur
->
low
.
y
)
)
allisequal
=
false
;
allisequal
=
false
;
if
(
pageunion
.
high
.
x
<
cur
->
high
.
x
)
pageunion
.
high
.
x
=
cur
->
high
.
x
;
pageunion
.
high
.
x
=
cur
->
high
.
x
;
}
if
(
pageunion
.
low
.
x
>
cur
->
low
.
x
)
if
(
pageunion
.
low
.
x
>
cur
->
low
.
x
)
{
allisequal
=
false
;
pageunion
.
low
.
x
=
cur
->
low
.
x
;
pageunion
.
low
.
x
=
cur
->
low
.
x
;
}
if
(
pageunion
.
high
.
y
<
cur
->
high
.
y
)
if
(
pageunion
.
high
.
y
<
cur
->
high
.
y
)
{
allisequal
=
false
;
pageunion
.
high
.
y
=
cur
->
high
.
y
;
pageunion
.
high
.
y
=
cur
->
high
.
y
;
}
if
(
pageunion
.
low
.
y
>
cur
->
low
.
y
)
if
(
pageunion
.
low
.
y
>
cur
->
low
.
y
)
{
allisequal
=
false
;
pageunion
.
low
.
y
=
cur
->
low
.
y
;
pageunion
.
low
.
y
=
cur
->
low
.
y
;
}
}
}
nbytes
=
(
maxoff
+
2
)
*
sizeof
(
OffsetNumber
);
nbytes
=
(
maxoff
+
2
)
*
sizeof
(
OffsetNumber
);
...
@@ -264,7 +276,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
...
@@ -264,7 +276,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
unionB
=
(
BOX
*
)
palloc
(
sizeof
(
BOX
));
unionB
=
(
BOX
*
)
palloc
(
sizeof
(
BOX
));
unionT
=
(
BOX
*
)
palloc
(
sizeof
(
BOX
));
unionT
=
(
BOX
*
)
palloc
(
sizeof
(
BOX
));
#define ADDLIST( list, unionD, pos ) do { \
#define ADDLIST( list, unionD, pos
, num
) do { \
if ( pos ) { \
if ( pos ) { \
if ( unionD->high.x < cur->high.x ) unionD->high.x = cur->high.x; \
if ( unionD->high.x < cur->high.x ) unionD->high.x = cur->high.x; \
if ( unionD->low.x > cur->low.x ) unionD->low.x = cur->low.x; \
if ( unionD->low.x > cur->low.x ) unionD->low.x = cur->low.x; \
...
@@ -273,7 +285,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
...
@@ -273,7 +285,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
} else { \
} else { \
memcpy( (void*)unionD, (void*) cur, sizeof( BOX ) ); \
memcpy( (void*)unionD, (void*) cur, sizeof( BOX ) ); \
} \
} \
list[pos] =
i
; \
list[pos] =
num
; \
(pos)++; \
(pos)++; \
} while(0)
} while(0)
...
@@ -281,17 +293,50 @@ gbox_picksplit(PG_FUNCTION_ARGS)
...
@@ -281,17 +293,50 @@ gbox_picksplit(PG_FUNCTION_ARGS)
{
{
cur
=
DatumGetBoxP
(((
GISTENTRY
*
)
VARDATA
(
entryvec
))[
i
].
key
);
cur
=
DatumGetBoxP
(((
GISTENTRY
*
)
VARDATA
(
entryvec
))[
i
].
key
);
if
(
cur
->
low
.
x
-
pageunion
.
low
.
x
<
pageunion
.
high
.
x
-
cur
->
high
.
x
)
if
(
cur
->
low
.
x
-
pageunion
.
low
.
x
<
pageunion
.
high
.
x
-
cur
->
high
.
x
)
ADDLIST
(
listL
,
unionL
,
posL
);
ADDLIST
(
listL
,
unionL
,
posL
,
i
);
else
else
ADDLIST
(
listR
,
unionR
,
posR
);
ADDLIST
(
listR
,
unionR
,
posR
,
i
);
if
(
cur
->
low
.
y
-
pageunion
.
low
.
y
<
pageunion
.
high
.
y
-
cur
->
high
.
y
)
if
(
cur
->
low
.
y
-
pageunion
.
low
.
y
<
pageunion
.
high
.
y
-
cur
->
high
.
y
)
ADDLIST
(
listB
,
unionB
,
posB
);
ADDLIST
(
listB
,
unionB
,
posB
,
i
);
else
else
ADDLIST
(
listT
,
unionT
,
posT
);
ADDLIST
(
listT
,
unionT
,
posT
,
i
);
}
}
/* which split more optimal? */
/* bad disposition, sort by ascending and resplit */
if
(
(
posR
==
0
||
posL
==
0
)
&&
(
posT
==
0
||
posB
==
0
)
)
{
KBsort
*
arr
=
(
KBsort
*
)
palloc
(
sizeof
(
KBsort
)
*
maxoff
);
posL
=
posR
=
posB
=
posT
=
0
;
for
(
i
=
FirstOffsetNumber
;
i
<=
maxoff
;
i
=
OffsetNumberNext
(
i
))
{
arr
[
i
-
1
].
key
=
DatumGetBoxP
(((
GISTENTRY
*
)
VARDATA
(
entryvec
))[
i
].
key
);
arr
[
i
-
1
].
pos
=
i
;
}
qsort
(
arr
,
maxoff
,
sizeof
(
KBsort
),
compare_KB
);
for
(
i
=
FirstOffsetNumber
;
i
<=
maxoff
;
i
=
OffsetNumberNext
(
i
))
{
cur
=
arr
[
i
-
1
].
key
;
if
(
cur
->
low
.
x
-
pageunion
.
low
.
x
<
pageunion
.
high
.
x
-
cur
->
high
.
x
)
ADDLIST
(
listL
,
unionL
,
posL
,
arr
[
i
-
1
].
pos
);
else
if
(
cur
->
low
.
x
-
pageunion
.
low
.
x
==
pageunion
.
high
.
x
-
cur
->
high
.
x
)
{
if
(
posL
>
posR
)
ADDLIST
(
listR
,
unionR
,
posR
,
arr
[
i
-
1
].
pos
);
else
ADDLIST
(
listL
,
unionL
,
posL
,
arr
[
i
-
1
].
pos
);
}
else
ADDLIST
(
listR
,
unionR
,
posR
,
arr
[
i
-
1
].
pos
);
if
(
cur
->
low
.
y
-
pageunion
.
low
.
y
<
pageunion
.
high
.
y
-
cur
->
high
.
y
)
ADDLIST
(
listB
,
unionB
,
posB
,
arr
[
i
-
1
].
pos
);
else
if
(
cur
->
low
.
y
-
pageunion
.
low
.
y
==
pageunion
.
high
.
y
-
cur
->
high
.
y
)
{
if
(
posB
>
posT
)
ADDLIST
(
listT
,
unionT
,
posT
,
arr
[
i
-
1
].
pos
);
else
ADDLIST
(
listB
,
unionB
,
posB
,
arr
[
i
-
1
].
pos
);
}
else
ADDLIST
(
listT
,
unionT
,
posT
,
arr
[
i
-
1
].
pos
);
}
pfree
(
arr
);
}
/* which split more optimal? */
if
(
Max
(
posL
,
posR
)
<
Max
(
posB
,
posT
))
if
(
Max
(
posL
,
posR
)
<
Max
(
posB
,
posT
))
direction
=
'x'
;
direction
=
'x'
;
else
if
(
Max
(
posL
,
posR
)
>
Max
(
posB
,
posT
))
else
if
(
Max
(
posL
,
posR
)
>
Max
(
posB
,
posT
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment