diff options
author | unknown <monty@mashka.mysql.fi> | 2003-01-09 22:42:31 +0200 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2003-01-09 22:42:31 +0200 |
commit | f7ff1cca148b8cb0742f3d23c0e05e797c673dc0 (patch) | |
tree | f816bf52a43930fec89dbe67f90d81dd28b28a78 /mysys/my_handler.c | |
parent | 9d812016c1287fe06a0c0715f0b2852c919cff82 (diff) | |
download | mariadb-git-f7ff1cca148b8cb0742f3d23c0e05e797c673dc0.tar.gz |
Post merge fix
Allow empty key list in USE|IGNORE|FORCE INDEX()
mysql-test/r/myisam.result:
New explain format
mysql-test/t/myisam.test:
test of index()
mysys/my_handler.c:
Updated ha_key_cmp() to be as latest _mi_key_cmp() in 4.0
sql/sql_lex.cc:
Post merge fix
sql/sql_lex.h:
Post merge fix
sql/sql_parse.cc:
Post merge fix
sql/sql_yacc.yy:
Post merge fix for FORCE INDEX ()
Allow empty key list in USE|IGNORE|FORCE INDEX()
Diffstat (limited to 'mysys/my_handler.c')
-rw-r--r-- | mysys/my_handler.c | 87 |
1 files changed, 51 insertions, 36 deletions
diff --git a/mysys/my_handler.c b/mysys/my_handler.c index 2d51ab13f69..2fd7f1fcdee 100644 --- a/mysys/my_handler.c +++ b/mysys/my_handler.c @@ -40,15 +40,33 @@ static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length, return (int) (a_length-b_length); } -#define FCMP(A,B) ((int) (A) - (int) (B)) /* Compare two keys - Returns <0, 0, >0 acording to which is bigger - Key_length specifies length of key to use. Number-keys can't be splited - If flag <> SEARCH_FIND compare also position + + SYNOPSIS + ha_key_cmp() + keyseg Key segments of key to compare + a First key to compare, in format from _mi_pack_key() + This is normally key specified by user + b Second key to compare. This is always from a row + key_length Length of key to compare. This can be shorter than + a to just compare sub keys + next_flag How keys should be compared + If bit SEARCH_FIND is not set the keys includes the row + position and this should also be compared + + NOTES + Number-keys can't be splited + + RETURN VALUES + <0 If a < b + 0 If a == b + >0 If a > b */ +#define FCMP(A,B) ((int) (A) - (int) (B)) + int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, register uchar *b, uint key_length, uint nextflag, uint *diff_pos) @@ -59,9 +77,10 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, uint32 u_1,u_2; float f_1,f_2; double d_1,d_2; + uint next_key_length; *diff_pos=0; - for ( ; (int) key_length >0 ; keyseg++) + for ( ; (int) key_length >0 ; key_length=next_key_length, keyseg++) { uchar *end; uint piks=! (keyseg->flag & HA_NO_SORT); @@ -81,10 +100,21 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, { if (nextflag == (SEARCH_FIND | SEARCH_UPDATE)) nextflag=SEARCH_SAME; /* Allow duplicate keys */ + else if (nextflag & SEARCH_NULL_ARE_NOT_EQUAL) + { + /* + This is only used from mi_check() to calculate cardinality. + It can't be used when searching for a key as this would cause + compare of (a,b) and (b,a) to return the same value. + */ + return -1; + } + next_key_length=key_length; continue; /* To next key part */ } } end= a+ min(keyseg->length,key_length); + next_key_length=key_length-keyseg->length; switch ((enum ha_base_keytype) keyseg->type) { case HA_KEYTYPE_TEXT: /* Ascii; Key is converted */ @@ -93,12 +123,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - key_length-= b_length + pack_length; + next_key_length=key_length-b_length-pack_length; if (piks && - (flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length, - (my_bool) ((nextflag & SEARCH_PREFIX) && - key_length <= 0)))) + (flag=mi_compare_text(keyseg->charset,a,a_length,b,b_length, + (my_bool) ((nextflag & SEARCH_PREFIX) && + next_key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -107,7 +137,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, else { uint length=(uint) (end-a), a_length=length, b_length=length; - key_length-= keyseg->length; if (!(nextflag & SEARCH_PREFIX)) { while (a_length && a[a_length-1] == ' ') @@ -116,9 +145,9 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, b_length--; } if (piks && - (flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length, - (my_bool) ((nextflag & SEARCH_PREFIX) && - key_length <= 0)))) + (flag= mi_compare_text(keyseg->charset, a, a_length, b, b_length, + (my_bool) ((nextflag & SEARCH_PREFIX) && + next_key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a=end; b+=length; @@ -130,12 +159,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - key_length-= b_length + pack_length; + next_key_length=key_length-b_length-pack_length; if (piks && (flag=compare_bin(a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - key_length <= 0)))) + next_key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -144,11 +173,10 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, else { uint length=keyseg->length; - key_length-= keyseg->length; if (piks && (flag=compare_bin(a,length,b,length, (my_bool) ((nextflag & SEARCH_PREFIX) && - key_length <= 0)))) + next_key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=length; b+=length; @@ -159,12 +187,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - key_length-= b_length + pack_length; + next_key_length=key_length-b_length-pack_length; if (piks && (flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - key_length <= 0)))) + next_key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -176,12 +204,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - key_length-= b_length + pack_length; + next_key_length=key_length-b_length-pack_length; if (piks && (flag=compare_bin(a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - key_length <= 0)))) + next_key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -196,7 +224,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b++; - key_length-= keyseg->length; break; } case HA_KEYTYPE_SHORT_INT: @@ -206,7 +233,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 2; /* sizeof(short int); */ - key_length-= keyseg->length; break; case HA_KEYTYPE_USHORT_INT: { @@ -217,7 +243,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+=2; /* sizeof(short int); */ - key_length-= keyseg->length; break; } case HA_KEYTYPE_LONG_INT: @@ -227,7 +252,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 4; /* sizeof(long int); */ - key_length-= keyseg->length; break; case HA_KEYTYPE_ULONG_INT: u_1= mi_sint4korr(a); @@ -236,7 +260,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 4; /* sizeof(long int); */ - key_length-= keyseg->length; break; case HA_KEYTYPE_INT24: l_1=mi_sint3korr(a); @@ -245,7 +268,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 3; - key_length-= keyseg->length; break; case HA_KEYTYPE_UINT24: l_1=mi_uint3korr(a); @@ -254,7 +276,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 3; - key_length-= keyseg->length; break; case HA_KEYTYPE_FLOAT: mi_float4get(f_1,a); @@ -263,7 +284,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 4; /* sizeof(float); */ - key_length-= keyseg->length; break; case HA_KEYTYPE_DOUBLE: mi_float8get(d_1,a); @@ -272,13 +292,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 8; /* sizeof(double); */ - key_length-= keyseg->length; break; case HA_KEYTYPE_NUM: /* Numeric key */ { int swap_flag= 0; int alength,blength; - + if (keyseg->flag & HA_REVERSE_SORT) { swap(uchar*,a,b); @@ -289,7 +308,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, { alength= *a++; blength= *b++; end=a+alength; - key_length-= blength + 1; + next_key_length=key_length-blength-1; } else { @@ -298,9 +317,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, /* remove pre space from keys */ for ( ; alength && *a == ' ' ; a++, alength--) ; for ( ; blength && *b == ' ' ; b++, blength--) ; - key_length-= keyseg->length; } - if (piks) { if (*a == '-') @@ -350,7 +367,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 8; - key_length-= keyseg->length; break; } case HA_KEYTYPE_ULONGLONG: @@ -362,7 +378,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 8; - key_length-= keyseg->length; break; } #endif |