Commit 7cf1d259 authored by hf@deer.(none)'s avatar hf@deer.(none)

wl 1562 (To improve RTree indexes)

some changes to make code nicer
parent f200b0fb
......@@ -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); }
......
......@@ -462,21 +462,13 @@ static uchar *rtree_pick_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
if ((increase = rtree_perimeter_increase(keyinfo->seg, k, key, key_length,
&perimeter)) == -1)
return NULL;
if (increase < best_incr)
if ((increase < best_incr)||
(increase == best_incr && perimeter < best_perimeter))
{
best_key = k;
best_perimeter= perimeter;
best_incr = increase;
}
else
{
if ((increase == best_incr) && (perimeter < best_perimeter))
{
best_key = k;
best_perimeter= perimeter;
best_incr = increase;
}
}
}
return best_key;
}
......
This diff is collapsed.
......@@ -31,6 +31,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)))
{
......@@ -55,7 +100,7 @@ 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;
......@@ -399,7 +444,7 @@ static void create_record1(char *record,uint rownr)
}
static void create_record(char *record,uint rownr)
static void create_record0(char *record,uint rownr)
{
int i;
char * pos;
......@@ -419,3 +464,16 @@ static void create_record(char *record,uint rownr)
pos+=sizeof(c);
}
}
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;
}
}
......@@ -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(*)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment