Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
b8cf9f6a
Commit
b8cf9f6a
authored
Jun 02, 2004
by
hf@deer.(none)
Browse files
Options
Browse Files
Download
Plain Diff
Merging
parents
4cb62eb0
7cf1d259
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
423 additions
and
286 deletions
+423
-286
include/myisampack.h
include/myisampack.h
+7
-0
myisam/rt_index.c
myisam/rt_index.c
+82
-2
myisam/rt_index.h
myisam/rt_index.h
+1
-1
myisam/rt_key.c
myisam/rt_key.c
+2
-44
myisam/rt_key.h
myisam/rt_key.h
+1
-2
myisam/rt_mbr.c
myisam/rt_mbr.c
+252
-224
myisam/rt_mbr.h
myisam/rt_mbr.h
+2
-0
myisam/rt_split.c
myisam/rt_split.c
+5
-5
myisam/rt_test.c
myisam/rt_test.c
+60
-2
mysql-test/r/gis-rtree.result
mysql-test/r/gis-rtree.result
+5
-5
sql/spatial.cc
sql/spatial.cc
+6
-1
No files found.
include/myisampack.h
View file @
b8cf9f6a
...
...
@@ -21,6 +21,10 @@
better compression
*/
/* these two are for uniformity */
#define mi_sint1korr(A) (int8)(*A)
#define mi_uint1korr(A) (uint8)(*A)
#define mi_sint2korr(A) (int16) (((int16) ((uchar) (A)[1])) +\
((int16) ((int16) (A)[0]) << 8))
#define mi_sint3korr(A) ((int32) ((((uchar) (A)[0]) & 128) ? \
...
...
@@ -75,6 +79,9 @@
(((uint32) ((uchar) (A)[0])) << 24))) <<\
32))
/* This one is for uniformity */
#define mi_int1store(T,A) *((uchar*)(T))= (uchar) (A)
#define mi_int2store(T,A) { uint def_temp= (uint) (A) ;\
*((uchar*) ((T)+1))= (uchar)(def_temp); \
*((uchar*) ((T)+0))= (uchar)(def_temp >> 8); }
...
...
myisam/rt_index.c
View file @
b8cf9f6a
...
...
@@ -24,6 +24,8 @@
#include "rt_mbr.h"
#define REINSERT_BUFFER_INC 10
#define PICK_BY_AREA
/*#define PICK_BY_PERIMETER*/
typedef
struct
st_page_level
{
...
...
@@ -438,6 +440,84 @@ int rtree_get_next(MI_INFO *info, uint keynr, uint key_length)
}
/*
Choose non-leaf better key for insertion
*/
#ifdef PICK_BY_PERIMETER
static
uchar
*
rtree_pick_key
(
MI_INFO
*
info
,
MI_KEYDEF
*
keyinfo
,
uchar
*
key
,
uint
key_length
,
uchar
*
page_buf
,
uint
nod_flag
)
{
double
increase
;
double
best_incr
=
DBL_MAX
;
double
perimeter
;
double
best_perimeter
;
uchar
*
best_key
;
uchar
*
k
=
rt_PAGE_FIRST_KEY
(
page_buf
,
nod_flag
);
uchar
*
last
=
rt_PAGE_END
(
page_buf
);
LINT_INIT
(
best_perimeter
);
LINT_INIT
(
best_key
);
for
(;
k
<
last
;
k
=
rt_PAGE_NEXT_KEY
(
k
,
key_length
,
nod_flag
))
{
if
((
increase
=
rtree_perimeter_increase
(
keyinfo
->
seg
,
k
,
key
,
key_length
,
&
perimeter
))
==
-
1
)
return
NULL
;
if
((
increase
<
best_incr
)
||
(
increase
==
best_incr
&&
perimeter
<
best_perimeter
))
{
best_key
=
k
;
best_perimeter
=
perimeter
;
best_incr
=
increase
;
}
}
return
best_key
;
}
#endif
/*PICK_BY_PERIMETER*/
#ifdef PICK_BY_AREA
static
uchar
*
rtree_pick_key
(
MI_INFO
*
info
,
MI_KEYDEF
*
keyinfo
,
uchar
*
key
,
uint
key_length
,
uchar
*
page_buf
,
uint
nod_flag
)
{
double
increase
;
double
best_incr
=
DBL_MAX
;
double
area
;
double
best_area
;
uchar
*
best_key
;
uchar
*
k
=
rt_PAGE_FIRST_KEY
(
page_buf
,
nod_flag
);
uchar
*
last
=
rt_PAGE_END
(
page_buf
);
LINT_INIT
(
best_area
);
LINT_INIT
(
best_key
);
for
(;
k
<
last
;
k
=
rt_PAGE_NEXT_KEY
(
k
,
key_length
,
nod_flag
))
{
if
((
increase
=
rtree_area_increase
(
keyinfo
->
seg
,
k
,
key
,
key_length
,
&
area
))
==
-
1
)
return
NULL
;
if
(
increase
<
best_incr
)
{
best_key
=
k
;
best_area
=
area
;
best_incr
=
increase
;
}
else
{
if
((
increase
==
best_incr
)
&&
(
area
<
best_area
))
{
best_key
=
k
;
best_area
=
area
;
best_incr
=
increase
;
}
}
}
return
best_key
;
}
#endif
/*PICK_BY_AREA*/
/*
Go down and insert key into tree
...
...
@@ -469,7 +549,7 @@ static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
if
((
ins_level
==
-
1
&&
nod_flag
)
||
/* key: go down to leaf */
(
ins_level
>
-
1
&&
ins_level
>
level
))
/* branch: go down to ins_level */
{
if
((
k
=
rtree_
choose
_key
(
info
,
keyinfo
,
key
,
key_length
,
page_buf
,
if
((
k
=
rtree_
pick
_key
(
info
,
keyinfo
,
key
,
key_length
,
page_buf
,
nod_flag
))
==
NULL
)
goto
err1
;
switch
((
res
=
rtree_insert_req
(
info
,
keyinfo
,
key
,
key_length
,
...
...
@@ -579,7 +659,7 @@ static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key,
mi_putint
(
new_root_buf
,
2
,
nod_flag
);
if
((
new_root
=
_mi_new
(
info
,
keyinfo
,
DFLT_INIT_HITS
))
==
HA_OFFSET_ERROR
)
HA_OFFSET_ERROR
)
goto
err1
;
new_key
=
new_root_buf
+
keyinfo
->
block_length
+
nod_flag
;
...
...
myisam/rt_index.h
View file @
b8cf9f6a
...
...
@@ -25,7 +25,7 @@
(nod_flag ? nod_flag : info->s->base.rec_reflength))
#define rt_PAGE_END(page) (page + mi_getint(page))
#define rt_PAGE_MIN_SIZE(block_length) ((uint)(block_length) /
2
)
#define rt_PAGE_MIN_SIZE(block_length) ((uint)(block_length) /
3
)
int
rtree_insert
(
MI_INFO
*
info
,
uint
keynr
,
uchar
*
key
,
uint
key_length
);
int
rtree_delete
(
MI_INFO
*
info
,
uint
keynr
,
uchar
*
key
,
uint
key_length
);
...
...
myisam/rt_key.c
View file @
b8cf9f6a
...
...
@@ -36,7 +36,8 @@ int rtree_add_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
uint
page_size
=
mi_getint
(
page_buf
);
uint
nod_flag
=
mi_test_if_nod
(
page_buf
);
if
(
page_size
+
key_length
+
nod_flag
<=
keyinfo
->
block_length
)
if
(
page_size
+
key_length
+
info
->
s
->
base
.
rec_reflength
<=
keyinfo
->
block_length
)
{
/* split won't be necessary */
if
(
nod_flag
)
...
...
@@ -96,47 +97,4 @@ int rtree_set_key_mbr(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
return
rtree_page_mbr
(
info
,
keyinfo
->
seg
,
info
->
buff
,
key
,
key_length
);
}
/*
Choose non-leaf better key for insertion
*/
uchar
*
rtree_choose_key
(
MI_INFO
*
info
,
MI_KEYDEF
*
keyinfo
,
uchar
*
key
,
uint
key_length
,
uchar
*
page_buf
,
uint
nod_flag
)
{
double
increase
;
double
best_incr
=
DBL_MAX
;
double
area
;
double
best_area
;
uchar
*
best_key
;
uchar
*
k
=
rt_PAGE_FIRST_KEY
(
page_buf
,
nod_flag
);
uchar
*
last
=
rt_PAGE_END
(
page_buf
);
LINT_INIT
(
best_area
);
LINT_INIT
(
best_key
);
for
(;
k
<
last
;
k
=
rt_PAGE_NEXT_KEY
(
k
,
key_length
,
nod_flag
))
{
if
((
increase
=
rtree_area_increase
(
keyinfo
->
seg
,
key
,
k
,
key_length
,
&
area
))
==
-
1
)
return
NULL
;
if
(
increase
<
best_incr
)
{
best_key
=
k
;
best_area
=
area
;
best_incr
=
increase
;
}
else
{
if
((
increase
==
best_incr
)
&&
(
area
<
best_area
))
{
best_key
=
k
;
best_area
=
area
;
best_incr
=
increase
;
}
}
}
return
best_key
;
}
#endif
/*HAVE_RTREE_KEYS*/
myisam/rt_key.h
View file @
b8cf9f6a
...
...
@@ -28,7 +28,6 @@ int rtree_delete_key(MI_INFO *info, uchar *page, uchar *key,
uint
key_length
,
uint
nod_flag
);
int
rtree_set_key_mbr
(
MI_INFO
*
info
,
MI_KEYDEF
*
keyinfo
,
uchar
*
key
,
uint
key_length
,
my_off_t
child_page
);
uchar
*
rtree_choose_key
(
MI_INFO
*
info
,
MI_KEYDEF
*
keyinfo
,
uchar
*
key
,
uint
key_length
,
uchar
*
page_buf
,
uint
nod_flag
);
#endif
/*HAVE_RTREE_KEYS*/
#endif
/* _rt_key_h */
myisam/rt_mbr.c
View file @
b8cf9f6a
This diff is collapsed.
Click to expand it.
myisam/rt_mbr.h
View file @
b8cf9f6a
...
...
@@ -30,6 +30,8 @@ double rtree_overlapping_area(HA_KEYSEG *keyseg, uchar *a, uchar *b,
uint
key_length
);
double
rtree_area_increase
(
HA_KEYSEG
*
keyseg
,
uchar
*
a
,
uchar
*
b
,
uint
key_length
,
double
*
ab_area
);
double
rtree_perimeter_increase
(
HA_KEYSEG
*
keyseg
,
uchar
*
a
,
uchar
*
b
,
uint
key_length
,
double
*
ab_perim
);
int
rtree_page_mbr
(
MI_INFO
*
info
,
HA_KEYSEG
*
keyseg
,
uchar
*
page_buf
,
uchar
*
c
,
uint
key_length
);
#endif
/*HAVE_RTREE_KEYS*/
...
...
myisam/rt_split.c
View file @
b8cf9f6a
...
...
@@ -267,12 +267,12 @@ int rtree_split_page(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *page, uchar *key,
n_dim
=
keyinfo
->
keysegs
/
2
;
if
(
!
my_multi_malloc
(
MYF
(
0
),
&
coord_buf
,
n_dim
*
2
*
sizeof
(
double
)
*
(
max_keys
+
1
+
4
),
&
task
,
sizeof
(
SplitStruct
)
*
(
max_keys
+
1
),
NullS
))
if
(
!
(
coord_buf
=
my_alloca
(
n_dim
*
2
*
sizeof
(
double
)
*
(
max_keys
+
1
+
4
)
+
sizeof
(
SplitStruct
)
*
(
max_keys
+
1
))))
return
-
1
;
task
=
(
SplitStruct
*
)(
coord_buf
+
n_dim
*
2
*
(
max_keys
+
1
+
4
));
next_coord
=
coord_buf
;
stop
=
task
+
max_keys
;
...
...
@@ -345,7 +345,7 @@ int rtree_split_page(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *page, uchar *key,
my_afree
((
byte
*
)
new_page
);
split_err:
my_
free
((
gptr
)
coord_buf
,
MYF
(
0
)
);
my_
afree
((
byte
*
)
coord_buf
);
return
err_code
;
}
...
...
myisam/rt_test.c
View file @
b8cf9f6a
...
...
@@ -34,6 +34,51 @@ static void create_record1(char *record,uint rownr);
static
void
print_record
(
char
*
record
,
my_off_t
offs
,
const
char
*
tail
);
static
int
run_test
(
const
char
*
filename
);
static
double
rt_data
[]
=
{
/*1*/
0
,
10
,
0
,
10
,
/*2*/
5
,
15
,
0
,
10
,
/*3*/
0
,
10
,
5
,
15
,
/*4*/
10
,
20
,
10
,
20
,
/*5*/
0
,
10
,
0
,
10
,
/*6*/
5
,
15
,
0
,
10
,
/*7*/
0
,
10
,
5
,
15
,
/*8*/
10
,
20
,
10
,
20
,
/*9*/
0
,
10
,
0
,
10
,
/*10*/
5
,
15
,
0
,
10
,
/*11*/
0
,
10
,
5
,
15
,
/*12*/
10
,
20
,
10
,
20
,
/*13*/
0
,
10
,
0
,
10
,
/*14*/
5
,
15
,
0
,
10
,
/*15*/
0
,
10
,
5
,
15
,
/*16*/
10
,
20
,
10
,
20
,
/*17*/
5
,
15
,
0
,
10
,
/*18*/
0
,
10
,
5
,
15
,
/*19*/
10
,
20
,
10
,
20
,
/*20*/
0
,
10
,
0
,
10
,
/*1*/
100
,
110
,
0
,
10
,
/*2*/
105
,
115
,
0
,
10
,
/*3*/
100
,
110
,
5
,
15
,
/*4*/
110
,
120
,
10
,
20
,
/*5*/
100
,
110
,
0
,
10
,
/*6*/
105
,
115
,
0
,
10
,
/*7*/
100
,
110
,
5
,
15
,
/*8*/
110
,
120
,
10
,
20
,
/*9*/
100
,
110
,
0
,
10
,
/*10*/
105
,
115
,
0
,
10
,
/*11*/
100
,
110
,
5
,
15
,
/*12*/
110
,
120
,
10
,
20
,
/*13*/
100
,
110
,
0
,
10
,
/*14*/
105
,
115
,
0
,
10
,
/*15*/
100
,
110
,
5
,
15
,
/*16*/
110
,
120
,
10
,
20
,
/*17*/
105
,
115
,
0
,
10
,
/*18*/
100
,
110
,
5
,
15
,
/*19*/
110
,
120
,
10
,
20
,
/*20*/
100
,
110
,
0
,
10
,
-
1
};
int
main
(
int
argc
__attribute__
((
unused
)),
char
*
argv
[]
__attribute__
((
unused
)))
{
...
...
@@ -58,7 +103,7 @@ static int run_test(const char *filename)
int
key_type
=
HA_KEYTYPE_DOUBLE
;
int
key_length
=
8
;
int
null_fields
=
0
;
int
nrecords
=
300
;
int
nrecords
=
sizeof
(
rt_data
)
/
(
sizeof
(
double
)
*
4
);
/* 3000;*/
int
rec_length
=
0
;
int
uniques
=
0
;
int
i
;
...
...
@@ -381,7 +426,7 @@ static void create_record1(char *record,uint rownr)
}
static
void
create_record
(
char
*
record
,
uint
rownr
)
static
void
create_record
0
(
char
*
record
,
uint
rownr
)
{
int
i
;
char
*
pos
;
...
...
@@ -402,6 +447,19 @@ static void create_record(char *record,uint rownr)
}
}
static
void
create_record
(
char
*
record
,
uint
rownr
)
{
int
i
;
char
*
pos
;
double
*
data
=
rt_data
+
rownr
*
4
;
record
[
0
]
=
0x01
;
/* DEL marker */
for
(
pos
=
record
+
1
,
i
=
0
;
i
<
ndims
*
2
;
i
++
)
{
float8store
(
pos
,
data
[
i
]);
pos
+=
8
;
}
}
#else
int
main
(
int
argc
__attribute__
((
unused
)),
char
*
argv
[]
__attribute__
((
unused
)))
{
...
...
mysql-test/r/gis-rtree.result
View file @
b8cf9f6a
...
...
@@ -167,12 +167,10 @@ count(*)
150
EXPLAIN SELECT fid, AsText(g) FROM t1 WHERE Within(g, GeomFromText('Polygon((140 140,160 140,160 160,140 160,140 140))'));
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range g g 32 NULL
4
Using where
1 SIMPLE t1 range g g 32 NULL
7
Using where
SELECT fid, AsText(g) FROM t1 WHERE Within(g, GeomFromText('Polygon((140 140,160 140,160 160,140 160,140 140))'));
fid AsText(g)
1 LINESTRING(150 150,150 150)
11 LINESTRING(140 140,160 160)
2 LINESTRING(149 149,151 151)
3 LINESTRING(148 148,152 152)
4 LINESTRING(147 147,153 153)
5 LINESTRING(146 146,154 154)
...
...
@@ -181,6 +179,8 @@ fid AsText(g)
8 LINESTRING(143 143,157 157)
9 LINESTRING(142 142,158 158)
10 LINESTRING(141 141,159 159)
11 LINESTRING(140 140,160 160)
2 LINESTRING(149 149,151 151)
DROP TABLE t1;
CREATE TABLE t2 (
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
...
...
@@ -305,10 +305,10 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT fid, AsText(g) FROM t2 WHERE Within(g,
GeomFromText('Polygon((40 40,60 40,60 60,40 60,40 40))'));
fid AsText(g)
46 LINESTRING(51 41,60 50)
56 LINESTRING(41 41,50 50)
45 LINESTRING(51 51,60 60)
55 LINESTRING(41 51,50 60)
56 LINESTRING(41 41,50 50)
46 LINESTRING(51 41,60 50)
DELETE FROM t2 WHERE Within(g, Envelope(GeometryFromWKB(LineString(Point(10 * 10 - 9, 10 * 10 - 9), Point(10 * 10, 10 * 10)))));
SELECT count(*) FROM t2;
count(*)
...
...
sql/spatial.cc
View file @
b8cf9f6a
...
...
@@ -398,7 +398,7 @@ bool Gis_line_string::init_from_wkt(Gis_read_stream *trs, String *wkb)
if
(
trs
->
skip_char
(
','
))
// Didn't find ','
break
;
}
if
(
n_points
<
2
)
if
(
n_points
<
1
)
{
trs
->
set_error_msg
(
"Too few points in LINESTRING"
);
return
1
;
...
...
@@ -487,6 +487,11 @@ int Gis_line_string::is_closed(int *closed) const
if
(
no_data
(
data
,
4
))
return
1
;
n_points
=
uint4korr
(
data
);
if
(
n_points
==
1
)
{
*
closed
=
1
;
return
0
;
}
data
+=
4
;
if
(
no_data
(
data
,
SIZEOF_STORED_DOUBLE
*
2
*
n_points
))
return
1
;
...
...
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