mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 12:01:42 +01:00
496741d576
Added my_uuid Added pre-support for PAGE_CHECKSUM Added syntax for CREATE ... PAGE_CHECKSUM=# TABLE_CHECKSUM=# Reserved place for page checksums on index, bitmap and block pages Added index number to header of index pages Added linked list for free directory entries (speeds up inserts with BLOCK format) Calculate checksums in original column order (fixes bug with checksum on rows with BLOCK format) Cleaned up all index handling to use 'info->s->keypage_header' (variable size) as the header for index pages (before this was '2') Added 0xffffffff to end of index and block data bases and 0xfffffffe at end of bitmap pages when page checksums are not enabled Added _ma_get_page_used() and _ma_get_used_and_node() to simplify index page header handling rec_per_key_part is now in double precision Reserved place in index file for my_guid and nulls_per_key_part Give error HA_ERR_NEW_FILE if trying to open a Maria file with new, not yet supported extensions Lots of renames to increase readability: randomize() -> my_rnd_init() st_maria_info -> st_maria_handler st_maria_info -> MARIA_HA st_maria_isaminfo -> st_maria_info rand_struct -> my_rand_struct rec_per_key_rows -> records_at_analyze client/mysqladmin.cc: rand_struct -> my_rrnd_struct include/maria.h: st_maria_info -> MARIA_HA st_maria_isaminfo -> st_maria_info Changed analyze statistics to be of double precission Changed offset to field to be 32bits instead of 64 (safe as a record without blobs can't be that big) include/my_base.h: Added HA_OPTION_PAGE_CHECKSUM & HA_CREATE_PAGE_CHECKSUM Fixed comments Added HA_ERR_NEW_FILE include/my_sys.h: Added prototypes and structures for my_uuid() and my_rnd() include/myisamchk.h: Changed some buffers to size_t Added possibility to have key statistics with double precission include/mysql_com.h: Move rand functions to mysys libmysql/Makefile.shared: Added my_rnd mysql-test/r/maria.result: Updated results mysql-test/t/maria.test: More tests for checksum mysys/Makefile.am: Added my_rnd.c and my_uuid.c server-tools/instance-manager/listener.cc: Fixed include order (my_global.h should always be first) server-tools/instance-manager/mysql_connection.cc: Fixed include order (my_global.h should always be first) Use my_rnd_init() server-tools/instance-manager/mysql_connection.h: rand_struct -> my_rand_struct sql/handler.h: Added flag for page checksums sql/item_func.cc: Use new my_rnd() interface sql/item_func.h: Use new my_rnd() interface sql/item_strfunc.cc: Use new my_rnd() interface sql/lex.h: Added PAGE_CHECKSUM and TABLE_CHECKSUM sql/mysql_priv.h: Use new my_rnd() interface sql/mysqld.cc: Use new my_rnd() interface sql/password.c: Move my_rnd() to mysys Use new my_rnd() interface sql/sql_class.cc: Use new my_rnd() interface sql/sql_class.h: Use new my_rnd() interface sql/sql_crypt.cc: Use new my_rnd() interface sql/sql_crypt.h: Use new my_rnd() interface sql/sql_show.cc: Simpler handling of ha_choice_values Added PAGE_CHECKSUM sql/sql_table.cc: Enable correct checksum handling (for now) if not running in compatible mode sql/sql_yacc.yy: Added table option PAGE_CHECKSUM Added future compatible table option TABLE_CHECKSUM (alias for CHECKSUM) Added 'choice' target to simplify code sql/table.cc: Store flag for PAGE_CHECKSUM sql/table.h: Added support for PAGE_CHECKSUM storage/maria/ha_maria.cc: Remove protection for incompatbile frm and MAI (Slow, not needed test) Rec_per_key is now in double Remember row type for table Give warning if one Maria uses another row type than requested Removed some old ASK_MONTY entries (added comments instead) Added handling of PAGE_CHECKSUM flags storage/maria/ma_bitmap.c: Added page checksums to bitmap pages Added special bitmap marker for bitmap pages (Used to find bugs when running without page checksums) storage/maria/ma_blockrec.c: Added a free-link list over directory entries. This makes insert of small rows faster as we don't have to scan the whole directory to find a not used entry. Moved SANITY_CHECKS to maria_def.h Simplify code by introducing dir_entry_pos() Added support for PAGE_CHECKSUM storage/maria/ma_blockrec.h: Added DIR_FREE_SIZE (linked list of free directory entries) Added PAGE_CHECKSUM Added 'dir_entry_pos()' storage/maria/ma_check.c: Check that index pages has correct index number Calculate rec_per_key with double precission Simplify code by using '_ma_get_used_and_node()' Check free directory list Remove wrong end \n from messages maria_data_on_page() -> _ma_get_page_used() maria_putint() -> _ma_store_page_used() rec_per_key_rows -> records_at_analyze storage/maria/ma_checksum.c: Calculate checksum in original column order storage/maria/ma_create.c: Store original column order in index file Reserve place for nulls_per_key_part (future) Added support for PAGE_CHECKSUM storage/maria/ma_dbug.c: Fixed wrong debug output of key of type 'ulong' storage/maria/ma_delete.c: maria_data_on_page() -> _ma_get_used_and_node() maria_data_on_page() -> _ma_get_page_used() maria_putint() -> _ma_store_page_used() Added page header (index key number) to all index pages Reserved page for checksum on index pages Use keypage_header storage/maria/ma_ft_update.c: maria_putint() -> _ma_store_page_used() Store key number at start of page storage/maria/ma_loghandler.h: st_maria_info -> MARIA_HA storage/maria/ma_open.c: rec_per_key is now in double precission Added 'nulls_per_key_part' Added 'extra_options' (flags for future) Added support for PAGE_CHECKSUM Give error HA_ERR_NEW_FILE when using unsupported maria extensions Added comments Add maria_uuid to index file Added functions to store and read column_nr map. Changed some functions to return my_bool instead of uint storage/maria/ma_page.c: Added checks that pages has correct key nr Store 0xffffffff in checksum position if page checksums are not enabled Moved key-page-delete link to take into account keypage header storage/maria/ma_preload.c: Remove old MyISAM dependent code When scanning pages, only add pages to page cache for the requested index storage/maria/ma_range.c: maria_data_on_page() -> _ma_get_used_and_node() Use keypage_header storage/maria/ma_rt_index.c: Fixed indentation storage/maria/ma_rt_index.h: Added support for dynamic index page header Reserved place for PAGE_CHECKSUM storage/maria/ma_rt_key.c: Fixed indentation maria_data_on_page() -> _ma_get_page_used() maria_putint() -> maria_store_page_used() storage/maria/ma_rt_mbr.c: Fixed indentation storage/maria/ma_rt_split.c: Fixed indentation maria_data_on_page () -> _ma_get_page_used() storage/maria/ma_rt_test.c: Fixed indentation storage/maria/ma_search.c: Remove support of using -1 as 'last used index' to _ma_check_index() maria_data_on_page() -> _ma_get_page_used() maria_data_on_page() -> _ma_get_used_and_node() Use keypage_header storage/maria/ma_sort.c: Changed some buffers to size_t Changed rec_per_key_part to double storage/maria/ma_static.c: Removed NEAR Added maria_uuid storage/maria/ma_test2.c: Moevd testflag == 2 to correct place Remove test of reading with index number -1 (not supported anymore) storage/maria/ma_test_recovery.expected: Updated results storage/maria/ma_test_recovery: Changed tmp table names so that one can run maria_chk on them storage/maria/ma_write.c: Fixed indentation Use keypage_header Store index number on index pages maria_putint() -> _ma_store_page_used() maria_data_on_page() -> ma_get_used_and_node() maria_data_on_page() -> _ma_get_page_used() Added PAGE_CHECKSUM Added Maria handler to some functions Removed some not needed casts storage/maria/maria_chk.c: Added error handling for HA_ERR_NEW_FILE Added information about page checksums rec_per_key_part changed to double maria_data_on_page() -> _ma_get_page_used() Use keypage_header storage/maria/maria_def.h: Added IDENTICAL_PAGES_AFTER_RECOVERY and SANITY_CHECKS Changed rec_per_key_part to double Added nulls_per_key_part rec_per_key_rows -> records_at_analyze st_maria_info -> MARIA_HA Reserve place for new statistics variables, uuid, checksums per page etc. Removed NEAR tags Changed some prototypes to use my_bool and size_t storage/maria/maria_pack.c: st_maria_info -> MARIA_HA Fixed indentation storage/myisam/mi_dbug.c: Fix wrong debug output for ULONG mysys/my_rnd.c: New BitKeeper file ``mysys/my_rnd.c'' mysys/my_uuid.c: New BitKeeper file ``mysys/my_uuid.c''
806 lines
21 KiB
C
806 lines
21 KiB
C
/* Copyright (C) 2006 MySQL AB & Ramil Kalimullin & MySQL Finland AB
|
|
& TCX DataKonsult AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#include "maria_def.h"
|
|
|
|
#ifdef HAVE_RTREE_KEYS
|
|
|
|
#include "ma_rt_index.h"
|
|
#include "ma_rt_mbr.h"
|
|
|
|
#define INTERSECT_CMP(amin, amax, bmin, bmax) ((amin > bmax) || (bmin > amax))
|
|
#define CONTAIN_CMP(amin, amax, bmin, bmax) ((bmin > amin) || (bmax < amax))
|
|
#define WITHIN_CMP(amin, amax, bmin, bmax) ((amin > bmin) || (amax < bmax))
|
|
#define DISJOINT_CMP(amin, amax, bmin, bmax) ((amin <= bmax) && (bmin <= amax))
|
|
#define EQUAL_CMP(amin, amax, bmin, bmax) ((amin != bmin) || (amax != bmax))
|
|
|
|
#define FCMP(A, B) ((int)(A) - (int)(B))
|
|
#define p_inc(A, B, X) {A += X; B += X;}
|
|
|
|
#define RT_CMP(nextflag) \
|
|
if (nextflag & MBR_INTERSECT) \
|
|
{ \
|
|
if (INTERSECT_CMP(amin, amax, bmin, bmax)) \
|
|
return 1; \
|
|
} \
|
|
else if (nextflag & MBR_CONTAIN) \
|
|
{ \
|
|
if (CONTAIN_CMP(amin, amax, bmin, bmax)) \
|
|
return 1; \
|
|
} \
|
|
else if (nextflag & MBR_WITHIN) \
|
|
{ \
|
|
if (WITHIN_CMP(amin, amax, bmin, bmax)) \
|
|
return 1; \
|
|
} \
|
|
else if (nextflag & MBR_EQUAL) \
|
|
{ \
|
|
if (EQUAL_CMP(amin, amax, bmin, bmax)) \
|
|
return 1; \
|
|
} \
|
|
else if (nextflag & MBR_DISJOINT) \
|
|
{ \
|
|
if (DISJOINT_CMP(amin, amax, bmin, bmax)) \
|
|
return 1; \
|
|
}\
|
|
else /* if unknown comparison operator */ \
|
|
{ \
|
|
DBUG_ASSERT(0); \
|
|
}
|
|
|
|
#define RT_CMP_KORR(type, korr_func, len, nextflag) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
amin= korr_func(a); \
|
|
bmin= korr_func(b); \
|
|
amax= korr_func(a+len); \
|
|
bmax= korr_func(b+len); \
|
|
RT_CMP(nextflag); \
|
|
}
|
|
|
|
#define RT_CMP_GET(type, get_func, len, nextflag) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
get_func(amin, a); \
|
|
get_func(bmin, b); \
|
|
get_func(amax, a+len); \
|
|
get_func(bmax, b+len); \
|
|
RT_CMP(nextflag); \
|
|
}
|
|
|
|
/*
|
|
Compares two keys a and b depending on nextflag
|
|
nextflag can contain these flags:
|
|
MBR_INTERSECT(a,b) a overlaps b
|
|
MBR_CONTAIN(a,b) a contains b
|
|
MBR_DISJOINT(a,b) a disjoint b
|
|
MBR_WITHIN(a,b) a within b
|
|
MBR_EQUAL(a,b) All coordinates of MBRs are equal
|
|
MBR_DATA(a,b) Data reference is the same
|
|
Returns 0 on success.
|
|
*/
|
|
|
|
int maria_rtree_key_cmp(HA_KEYSEG *keyseg, uchar *b, uchar *a, uint key_length,
|
|
uint nextflag)
|
|
{
|
|
for (; (int) key_length > 0; keyseg += 2 )
|
|
{
|
|
uint32 keyseg_length;
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_CMP_KORR(int8, mi_sint1korr, 1, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_CMP_KORR(uint8, mi_uint1korr, 1, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_CMP_KORR(int16, mi_sint2korr, 2, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_CMP_KORR(uint16, mi_uint2korr, 2, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_CMP_KORR(int32, mi_sint3korr, 3, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_CMP_KORR(uint32, mi_uint3korr, 3, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_CMP_KORR(int32, mi_sint4korr, 4, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_CMP_KORR(uint32, mi_uint4korr, 4, nextflag);
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_CMP_KORR(longlong, mi_sint8korr, 8, nextflag)
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_CMP_KORR(ulonglong, mi_uint8korr, 8, nextflag)
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
/* The following should be safe, even if we compare doubles */
|
|
RT_CMP_GET(float, mi_float4get, 4, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_CMP_GET(double, mi_float8get, 8, nextflag);
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
goto end;
|
|
default:
|
|
return 1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
b+= keyseg_length;
|
|
}
|
|
|
|
end:
|
|
if (nextflag & MBR_DATA)
|
|
{
|
|
uchar *end= a + keyseg->length;
|
|
do
|
|
{
|
|
if (*a++ != *b++)
|
|
return FCMP(a[-1], b[-1]);
|
|
} while (a != end);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#define RT_VOL_KORR(type, korr_func, len, cast) \
|
|
{ \
|
|
type amin, amax; \
|
|
amin= korr_func(a); \
|
|
amax= korr_func(a+len); \
|
|
res *= (cast(amax) - cast(amin)); \
|
|
}
|
|
|
|
#define RT_VOL_GET(type, get_func, len, cast) \
|
|
{ \
|
|
type amin, amax; \
|
|
get_func(amin, a); \
|
|
get_func(amax, a+len); \
|
|
res *= (cast(amax) - cast(amin)); \
|
|
}
|
|
|
|
/*
|
|
Calculates rectangle volume
|
|
*/
|
|
double maria_rtree_rect_volume(HA_KEYSEG *keyseg, uchar *a, uint key_length)
|
|
{
|
|
double res= 1;
|
|
for (; (int)key_length > 0; keyseg += 2)
|
|
{
|
|
uint32 keyseg_length;
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_VOL_KORR(int8, mi_sint1korr, 1, (double));
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_VOL_KORR(uint8, mi_uint1korr, 1, (double));
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_VOL_KORR(int16, mi_sint2korr, 2, (double));
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_VOL_KORR(uint16, mi_uint2korr, 2, (double));
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_VOL_KORR(int32, mi_sint3korr, 3, (double));
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_VOL_KORR(uint32, mi_uint3korr, 3, (double));
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_VOL_KORR(int32, mi_sint4korr, 4, (double));
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_VOL_KORR(uint32, mi_uint4korr, 4, (double));
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_VOL_KORR(longlong, mi_sint8korr, 8, (double));
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_VOL_KORR(longlong, mi_sint8korr, 8, ulonglong2double);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_VOL_GET(float, mi_float4get, 4, (double));
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_VOL_GET(double, mi_float8get, 8, (double));
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
key_length= 0;
|
|
break;
|
|
default:
|
|
return -1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
#define RT_D_MBR_KORR(type, korr_func, len, cast) \
|
|
{ \
|
|
type amin, amax; \
|
|
amin= korr_func(a); \
|
|
amax= korr_func(a+len); \
|
|
*res++= cast(amin); \
|
|
*res++= cast(amax); \
|
|
}
|
|
|
|
#define RT_D_MBR_GET(type, get_func, len, cast) \
|
|
{ \
|
|
type amin, amax; \
|
|
get_func(amin, a); \
|
|
get_func(amax, a+len); \
|
|
*res++= cast(amin); \
|
|
*res++= cast(amax); \
|
|
}
|
|
|
|
|
|
/*
|
|
Creates an MBR as an array of doubles.
|
|
*/
|
|
|
|
int maria_rtree_d_mbr(HA_KEYSEG *keyseg, uchar *a, uint key_length, double *res)
|
|
{
|
|
for (; (int)key_length > 0; keyseg += 2)
|
|
{
|
|
uint32 keyseg_length;
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_D_MBR_KORR(int8, mi_sint1korr, 1, (double));
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_D_MBR_KORR(uint8, mi_uint1korr, 1, (double));
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_D_MBR_KORR(int16, mi_sint2korr, 2, (double));
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_D_MBR_KORR(uint16, mi_uint2korr, 2, (double));
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_D_MBR_KORR(int32, mi_sint3korr, 3, (double));
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_D_MBR_KORR(uint32, mi_uint3korr, 3, (double));
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_D_MBR_KORR(int32, mi_sint4korr, 4, (double));
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_D_MBR_KORR(uint32, mi_uint4korr, 4, (double));
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_D_MBR_KORR(longlong, mi_sint8korr, 8, (double));
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_D_MBR_KORR(longlong, mi_sint8korr, 8, ulonglong2double);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_D_MBR_GET(float, mi_float4get, 4, (double));
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_D_MBR_GET(double, mi_float8get, 8, (double));
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
key_length= 0;
|
|
break;
|
|
default:
|
|
return 1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#define RT_COMB_KORR(type, korr_func, store_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
amin= korr_func(a); \
|
|
bmin= korr_func(b); \
|
|
amax= korr_func(a+len); \
|
|
bmax= korr_func(b+len); \
|
|
amin= min(amin, bmin); \
|
|
amax= max(amax, bmax); \
|
|
store_func(c, amin); \
|
|
store_func(c+len, amax); \
|
|
}
|
|
|
|
#define RT_COMB_GET(type, get_func, store_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
get_func(amin, a); \
|
|
get_func(bmin, b); \
|
|
get_func(amax, a+len); \
|
|
get_func(bmax, b+len); \
|
|
amin= min(amin, bmin); \
|
|
amax= max(amax, bmax); \
|
|
store_func(c, amin); \
|
|
store_func(c+len, amax); \
|
|
}
|
|
|
|
/*
|
|
Creates common minimal bounding rectungle
|
|
for two input rectagnles a and b
|
|
Result is written to c
|
|
*/
|
|
|
|
int maria_rtree_combine_rect(HA_KEYSEG *keyseg, uchar* a, uchar* b, uchar* c,
|
|
uint key_length)
|
|
{
|
|
for ( ; (int) key_length > 0 ; keyseg += 2)
|
|
{
|
|
uint32 keyseg_length;
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_COMB_KORR(int8, mi_sint1korr, mi_int1store, 1);
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_COMB_KORR(uint8, mi_uint1korr, mi_int1store, 1);
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_COMB_KORR(int16, mi_sint2korr, mi_int2store, 2);
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_COMB_KORR(uint16, mi_uint2korr, mi_int2store, 2);
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_COMB_KORR(int32, mi_sint3korr, mi_int3store, 3);
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_COMB_KORR(uint32, mi_uint3korr, mi_int3store, 3);
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_COMB_KORR(int32, mi_sint4korr, mi_int4store, 4);
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_COMB_KORR(uint32, mi_uint4korr, mi_int4store, 4);
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_COMB_KORR(longlong, mi_sint8korr, mi_int8store, 8);
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_COMB_KORR(ulonglong, mi_uint8korr, mi_int8store, 8);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_COMB_GET(float, mi_float4get, mi_float4store, 4);
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_COMB_GET(double, mi_float8get, mi_float8store, 8);
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
return 0;
|
|
default:
|
|
return 1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
b+= keyseg_length;
|
|
c+= keyseg_length;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
#define RT_OVL_AREA_KORR(type, korr_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
amin= korr_func(a); \
|
|
bmin= korr_func(b); \
|
|
amax= korr_func(a+len); \
|
|
bmax= korr_func(b+len); \
|
|
amin= max(amin, bmin); \
|
|
amax= min(amax, bmax); \
|
|
if (amin >= amax) \
|
|
return 0; \
|
|
res *= amax - amin; \
|
|
}
|
|
|
|
#define RT_OVL_AREA_GET(type, get_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
get_func(amin, a); \
|
|
get_func(bmin, b); \
|
|
get_func(amax, a+len); \
|
|
get_func(bmax, b+len); \
|
|
amin= max(amin, bmin); \
|
|
amax= min(amax, bmax); \
|
|
if (amin >= amax) \
|
|
return 0; \
|
|
res *= amax - amin; \
|
|
}
|
|
|
|
/*
|
|
Calculates overlapping area of two MBRs a & b
|
|
*/
|
|
double maria_rtree_overlapping_area(HA_KEYSEG *keyseg, uchar* a, uchar* b,
|
|
uint key_length)
|
|
{
|
|
double res= 1;
|
|
for (; (int) key_length > 0 ; keyseg += 2)
|
|
{
|
|
uint32 keyseg_length;
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_OVL_AREA_KORR(int8, mi_sint1korr, 1);
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_OVL_AREA_KORR(uint8, mi_uint1korr, 1);
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_OVL_AREA_KORR(int16, mi_sint2korr, 2);
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_OVL_AREA_KORR(uint16, mi_uint2korr, 2);
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_OVL_AREA_KORR(int32, mi_sint3korr, 3);
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_OVL_AREA_KORR(uint32, mi_uint3korr, 3);
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_OVL_AREA_KORR(int32, mi_sint4korr, 4);
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_OVL_AREA_KORR(uint32, mi_uint4korr, 4);
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_OVL_AREA_KORR(longlong, mi_sint8korr, 8);
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_OVL_AREA_KORR(longlong, mi_sint8korr, 8);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_OVL_AREA_GET(float, mi_float4get, 4);
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_OVL_AREA_GET(double, mi_float8get, 8);
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
return res;
|
|
default:
|
|
return -1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
b+= keyseg_length;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
#define RT_AREA_INC_KORR(type, korr_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
amin= korr_func(a); \
|
|
bmin= korr_func(b); \
|
|
amax= korr_func(a+len); \
|
|
bmax= korr_func(b+len); \
|
|
a_area *= (((double)amax) - ((double)amin)); \
|
|
loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
|
|
}
|
|
|
|
#define RT_AREA_INC_GET(type, get_func, len)\
|
|
{\
|
|
type amin, amax, bmin, bmax; \
|
|
get_func(amin, a); \
|
|
get_func(bmin, b); \
|
|
get_func(amax, a+len); \
|
|
get_func(bmax, b+len); \
|
|
a_area *= (((double)amax) - ((double)amin)); \
|
|
loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
|
|
}
|
|
|
|
/*
|
|
Calculates MBR_AREA(a+b) - MBR_AREA(a)
|
|
*/
|
|
|
|
double maria_rtree_area_increase(HA_KEYSEG *keyseg, uchar *a, uchar *b,
|
|
uint key_length, double *ab_area)
|
|
{
|
|
double a_area= 1.0;
|
|
double loc_ab_area= 1.0;
|
|
|
|
*ab_area= 1.0;
|
|
for (; (int)key_length > 0; keyseg += 2)
|
|
{
|
|
uint32 keyseg_length;
|
|
|
|
if (keyseg->null_bit) /* Handle NULL part */
|
|
return -1;
|
|
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_AREA_INC_KORR(int8, mi_sint1korr, 1);
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_AREA_INC_KORR(uint8, mi_uint1korr, 1);
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_AREA_INC_KORR(int16, mi_sint2korr, 2);
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_AREA_INC_KORR(uint16, mi_uint2korr, 2);
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_AREA_INC_KORR(int32, mi_sint3korr, 3);
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_AREA_INC_KORR(int32, mi_uint3korr, 3);
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_AREA_INC_KORR(int32, mi_sint4korr, 4);
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_AREA_INC_KORR(uint32, mi_uint4korr, 4);
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_AREA_INC_KORR(longlong, mi_sint8korr, 8);
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_AREA_INC_KORR(longlong, mi_sint8korr, 8);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_AREA_INC_GET(float, mi_float4get, 4);
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_AREA_INC_GET(double, mi_float8get, 8);
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
goto safe_end;
|
|
default:
|
|
return -1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
b+= keyseg_length;
|
|
}
|
|
safe_end:
|
|
*ab_area= loc_ab_area;
|
|
return loc_ab_area - a_area;
|
|
}
|
|
|
|
#define RT_PERIM_INC_KORR(type, korr_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
amin= korr_func(a); \
|
|
bmin= korr_func(b); \
|
|
amax= korr_func(a+len); \
|
|
bmax= korr_func(b+len); \
|
|
a_perim+= (((double)amax) - ((double)amin)); \
|
|
*ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
|
|
}
|
|
|
|
#define RT_PERIM_INC_GET(type, get_func, len)\
|
|
{\
|
|
type amin, amax, bmin, bmax; \
|
|
get_func(amin, a); \
|
|
get_func(bmin, b); \
|
|
get_func(amax, a+len); \
|
|
get_func(bmax, b+len); \
|
|
a_perim+= (((double)amax) - ((double)amin)); \
|
|
*ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
|
|
}
|
|
|
|
/*
|
|
Calculates MBR_PERIMETER(a+b) - MBR_PERIMETER(a)
|
|
*/
|
|
double maria_rtree_perimeter_increase(HA_KEYSEG *keyseg, uchar* a, uchar* b,
|
|
uint key_length, double *ab_perim)
|
|
{
|
|
double a_perim= 0.0;
|
|
|
|
*ab_perim= 0.0;
|
|
for (; (int)key_length > 0; keyseg += 2)
|
|
{
|
|
uint32 keyseg_length;
|
|
|
|
if (keyseg->null_bit) /* Handle NULL part */
|
|
return -1;
|
|
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_PERIM_INC_KORR(int8, mi_sint1korr, 1);
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_PERIM_INC_KORR(uint8, mi_uint1korr, 1);
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_PERIM_INC_KORR(int16, mi_sint2korr, 2);
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_PERIM_INC_KORR(uint16, mi_uint2korr, 2);
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_PERIM_INC_KORR(int32, mi_sint3korr, 3);
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_PERIM_INC_KORR(int32, mi_uint3korr, 3);
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_PERIM_INC_KORR(int32, mi_sint4korr, 4);
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_PERIM_INC_KORR(uint32, mi_uint4korr, 4);
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_PERIM_INC_KORR(longlong, mi_sint8korr, 8);
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_PERIM_INC_KORR(longlong, mi_sint8korr, 8);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_PERIM_INC_GET(float, mi_float4get, 4);
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_PERIM_INC_GET(double, mi_float8get, 8);
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
return *ab_perim - a_perim;
|
|
default:
|
|
return -1;
|
|
}
|
|
keyseg_length= keyseg->length * 2;
|
|
key_length-= keyseg_length;
|
|
a+= keyseg_length;
|
|
b+= keyseg_length;
|
|
}
|
|
return *ab_perim - a_perim;
|
|
}
|
|
|
|
|
|
#define RT_PAGE_MBR_KORR(type, korr_func, store_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
amin= korr_func(k + inc); \
|
|
amax= korr_func(k + inc + len); \
|
|
k= rt_PAGE_NEXT_KEY(k, k_len, nod_flag); \
|
|
for (; k < last; k= rt_PAGE_NEXT_KEY(k, k_len, nod_flag)) \
|
|
{ \
|
|
bmin= korr_func(k + inc); \
|
|
bmax= korr_func(k + inc + len); \
|
|
if (amin > bmin) \
|
|
amin= bmin; \
|
|
if (amax < bmax) \
|
|
amax= bmax; \
|
|
} \
|
|
store_func(c, amin); \
|
|
c += len; \
|
|
store_func(c, amax); \
|
|
c += len; \
|
|
inc += 2 * len; \
|
|
}
|
|
|
|
#define RT_PAGE_MBR_GET(type, get_func, store_func, len) \
|
|
{ \
|
|
type amin, amax, bmin, bmax; \
|
|
get_func(amin, k + inc); \
|
|
get_func(amax, k + inc + len); \
|
|
k= rt_PAGE_NEXT_KEY(k, k_len, nod_flag); \
|
|
for (; k < last; k= rt_PAGE_NEXT_KEY(k, k_len, nod_flag)) \
|
|
{ \
|
|
get_func(bmin, k + inc); \
|
|
get_func(bmax, k + inc + len); \
|
|
if (amin > bmin) \
|
|
amin= bmin; \
|
|
if (amax < bmax) \
|
|
amax= bmax; \
|
|
} \
|
|
store_func(c, amin); \
|
|
c += len; \
|
|
store_func(c, amax); \
|
|
c += len; \
|
|
inc += 2 * len; \
|
|
}
|
|
|
|
/*
|
|
Calculates key page total MBR= MBR(key1) + MBR(key2) + ...
|
|
*/
|
|
int maria_rtree_page_mbr(MARIA_HA *info, HA_KEYSEG *keyseg, uchar *page_buf,
|
|
uchar *c, uint key_length)
|
|
{
|
|
uint inc= 0;
|
|
uint k_len= key_length;
|
|
uint nod_flag= _ma_test_if_nod(info, page_buf);
|
|
uchar *k;
|
|
uchar *last= rt_PAGE_END(info, page_buf);
|
|
|
|
for (; (int)key_length > 0; keyseg += 2)
|
|
{
|
|
key_length -= keyseg->length * 2;
|
|
|
|
/* Handle NULL part */
|
|
if (keyseg->null_bit)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
k= rt_PAGE_FIRST_KEY(info, page_buf, nod_flag);
|
|
|
|
switch ((enum ha_base_keytype) keyseg->type) {
|
|
case HA_KEYTYPE_INT8:
|
|
RT_PAGE_MBR_KORR(int8, mi_sint1korr, mi_int1store, 1);
|
|
break;
|
|
case HA_KEYTYPE_BINARY:
|
|
RT_PAGE_MBR_KORR(uint8, mi_uint1korr, mi_int1store, 1);
|
|
break;
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
RT_PAGE_MBR_KORR(int16, mi_sint2korr, mi_int2store, 2);
|
|
break;
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
RT_PAGE_MBR_KORR(uint16, mi_uint2korr, mi_int2store, 2);
|
|
break;
|
|
case HA_KEYTYPE_INT24:
|
|
RT_PAGE_MBR_KORR(int32, mi_sint3korr, mi_int3store, 3);
|
|
break;
|
|
case HA_KEYTYPE_UINT24:
|
|
RT_PAGE_MBR_KORR(uint32, mi_uint3korr, mi_int3store, 3);
|
|
break;
|
|
case HA_KEYTYPE_LONG_INT:
|
|
RT_PAGE_MBR_KORR(int32, mi_sint4korr, mi_int4store, 4);
|
|
break;
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
RT_PAGE_MBR_KORR(uint32, mi_uint4korr, mi_int4store, 4);
|
|
break;
|
|
#ifdef HAVE_LONG_LONG
|
|
case HA_KEYTYPE_LONGLONG:
|
|
RT_PAGE_MBR_KORR(longlong, mi_sint8korr, mi_int8store, 8);
|
|
break;
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
RT_PAGE_MBR_KORR(ulonglong, mi_uint8korr, mi_int8store, 8);
|
|
break;
|
|
#endif
|
|
case HA_KEYTYPE_FLOAT:
|
|
RT_PAGE_MBR_GET(float, mi_float4get, mi_float4store, 4);
|
|
break;
|
|
case HA_KEYTYPE_DOUBLE:
|
|
RT_PAGE_MBR_GET(double, mi_float8get, mi_float8store, 8);
|
|
break;
|
|
case HA_KEYTYPE_END:
|
|
return 0;
|
|
default:
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#endif /*HAVE_RTREE_KEYS*/
|