22 #ifdef HAVE_RTREE_KEYS
26 #define MAX_REC_LENGTH 1024
28 #define KEYALG HA_KEY_ALG_RTREE
30 static int read_with_pos(
MI_INFO *
file,
int silent);
31 static void create_record(uchar *
record,uint rownr);
32 static void create_record1(uchar *
record,uint rownr);
33 static void print_record(uchar *
record,my_off_t offs,
const char * tail);
34 static int run_test(
const char *filename);
36 static double rt_data[]=
82 int main(
int argc __attribute__((unused)),
char *argv[] __attribute__((unused)))
85 exit(run_test(
"rt_test"));
89 static int run_test(
const char *filename)
102 int key_type=HA_KEYTYPE_DOUBLE;
105 int nrecords=
sizeof(rt_data)/(
sizeof(
double)*4);
111 uchar
record[MAX_REC_LENGTH];
112 uchar read_record[MAX_REC_LENGTH];
118 recinfo[0].type=FIELD_NORMAL;
124 for (i=1; i<=2*ndims ;i++){
125 recinfo[
i].type=FIELD_NORMAL;
126 recinfo[
i].length=key_length;
127 rec_length+=key_length;
132 keyinfo[0].seg=keyseg;
133 keyinfo[0].keysegs=2*ndims;
135 keyinfo[0].key_alg=KEYALG;
137 for (i=0; i<2*ndims; i++){
138 keyinfo[0].seg[
i].type= key_type;
139 keyinfo[0].seg[
i].flag=0;
140 keyinfo[0].seg[
i].start= (key_length*
i)+1;
141 keyinfo[0].seg[
i].length=key_length;
142 keyinfo[0].seg[
i].null_bit= null_fields ? 2 : 0;
143 keyinfo[0].seg[
i].null_pos=0;
144 keyinfo[0].seg[
i].language=default_charset_info->number;
148 printf(
"- Creating isam-file\n");
150 memset(&create_info, 0,
sizeof(create_info));
151 create_info.max_rows=10000000;
153 if (mi_create(filename,
156 1+2*ndims+opt_unique,
157 recinfo,uniques,&uniquedef,&create_info,create_flag))
161 printf(
"- Open isam-file\n");
163 if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
167 printf(
"- Writing key:s\n");
169 for (i=0; i<nrecords; i++ )
171 create_record(record,i);
172 error=mi_write(file,record);
173 print_record(record,mi_position(file),
"\n");
180 printf(
"mi_write: %d\n", error);
185 if ((error=read_with_pos(file,silent)))
189 printf(
"- Reading rows with key\n");
191 for (i=0 ; i < nrecords ; i++)
194 create_record(record,i);
196 memset(read_record, 0, MAX_REC_LENGTH);
197 error=mi_rkey(file,read_record,0,record+1,0,HA_READ_MBR_EQUAL);
199 if (error && error!=HA_ERR_KEY_NOT_FOUND)
201 printf(
" mi_rkey: %3d errno: %3d\n",error,my_errno);
204 if (error == HA_ERR_KEY_NOT_FOUND)
206 print_record(record,mi_position(file),
" NOT FOUND\n");
209 print_record(read_record,mi_position(file),
"\n");
213 printf(
"- Deleting rows\n");
214 for (i=0; i < nrecords/4; i++)
217 memset(read_record, 0, MAX_REC_LENGTH);
218 error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR);
221 printf(
"pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno);
224 print_record(read_record,mi_position(file),
"\n");
226 error=mi_delete(file,read_record);
229 printf(
"pos: %2d mi_delete: %3d errno: %3d\n",i,error,my_errno);
235 printf(
"- Updating rows with position\n");
236 for (i=0; i < (nrecords - nrecords/4) ; i++)
239 memset(read_record, 0, MAX_REC_LENGTH);
240 error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR);
243 if (error==HA_ERR_RECORD_DELETED)
245 printf(
"pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno);
248 print_record(read_record,mi_position(file),
"");
249 create_record(record,i+nrecords*upd);
251 print_record(record,mi_position(file),
"\n");
252 error=mi_update(file,read_record,record);
255 printf(
"pos: %2d mi_update: %3d errno: %3d\n",i,error,my_errno);
260 if ((error=read_with_pos(file,silent)))
264 printf(
"- Test mi_rkey then a sequence of mi_rnext_same\n");
266 create_record(record, nrecords*4/5);
267 print_record(record,0,
" search for\n");
269 if ((error=mi_rkey(file,read_record,0,record+1,0,HA_READ_MBR_INTERSECT)))
271 printf(
"mi_rkey: %3d errno: %3d\n",error,my_errno);
274 print_record(read_record,mi_position(file),
" mi_rkey\n");
279 if ((error=mi_rnext_same(file,read_record)))
281 if (error==HA_ERR_END_OF_FILE)
283 printf(
"mi_next: %3d errno: %3d\n",error,my_errno);
286 print_record(read_record,mi_position(file),
" mi_rnext_same\n");
289 printf(
" %d rows\n",row_count);
292 printf(
"- Test mi_rfirst then a sequence of mi_rnext\n");
294 error=mi_rfirst(file,read_record,0);
297 printf(
"mi_rfirst: %3d errno: %3d\n",error,my_errno);
301 print_record(read_record,mi_position(file),
" mi_frirst\n");
303 for (i=0;i<nrecords;i++)
305 if ((error=mi_rnext(file,read_record,0)))
307 if (error==HA_ERR_END_OF_FILE)
309 printf(
"mi_next: %3d errno: %3d\n",error,my_errno);
312 print_record(read_record,mi_position(file),
" mi_rnext\n");
315 printf(
" %d rows\n",row_count);
318 printf(
"- Test mi_records_in_range()\n");
320 create_record1(record, nrecords*4/5);
321 print_record(record,0,
"\n");
325 range.flag= HA_READ_MBR_INTERSECT;
326 hrows= mi_records_in_range(file, 0, &range, (
key_range*) 0);
327 printf(
" %ld rows\n", (
long) hrows);
329 if (mi_close(file))
goto err;
330 my_end(MY_CHECK_ERROR);
335 printf(
"got error: %3d when using myisam-database\n",my_errno);
341 static int read_with_pos (
MI_INFO * file,
int silent)
345 uchar read_record[MAX_REC_LENGTH];
348 printf(
"- Reading rows with position\n");
352 memset(read_record, 0, MAX_REC_LENGTH);
353 error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR);
356 if (error==HA_ERR_END_OF_FILE)
358 if (error==HA_ERR_RECORD_DELETED)
360 printf(
"pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno);
363 print_record(read_record,mi_position(file),
"\n");
369 static void print_record(uchar * record,
370 my_off_t offs __attribute__((unused)),
377 printf(
" rec=(%d)",(
unsigned char)record[0]);
378 for ( pos=record+1, i=0; i<2*ndims; i++)
380 memcpy(&c,pos,
sizeof(c));
385 printf(
"pos=%ld",(
long int)offs);
391 static void create_record1(uchar *record,uint rownr)
397 memset(record, 0, MAX_REC_LENGTH);
400 for (pos=record+1, i=0; i<2*ndims; i++)
402 memcpy(pos,&c,
sizeof(c));
409 static void create_record(uchar *record,uint rownr)
413 double *data= rt_data+rownr*4;
415 for (pos=record+1, i=0; i<ndims*2; i++)
417 float8store(pos,data[i]);
423 int main(
int argc __attribute__((unused)),
char *argv[] __attribute__((unused)))
429 #include "mi_extrafunc.h"