mariadb/include/my_handler.h
Michael Widenius b12e3796dc Fix for lp:711565 "Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time"
- In Maria/MyISAM: Release/re-acquire locks to give queries that wait on them a chance to make progress
- In Maria/MyISAM: Change from numeric constants to ICP_RES values.
- In Maria: Do check index condition in maria_rprev() (was lost in the merge/backport?)
- In Maria/MyISAM/XtraDB: Check if the query was killed, and return immediately if it was.

Added new storage engine error: HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted

Authors: Sergey Petrunia & Monty

include/my_base.h:
  Added HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted
include/my_handler.h:
  Added comment
mysql-test/r/myisam_icp.result:
  Updated test
mysql-test/t/myisam_icp.test:
  Drop used tables at start of test
  Added test case that can help with manual testing of killing index condition pushdown query.
mysys/my_handler_errors.h:
  Text for new storage engine error
sql/handler.cc:
  If engine got HA_ERR_ABORTED_BY_USER, send kill message.
sql/multi_range_read.cc:
  Return error code
storage/maria/ha_maria.cc:
  Added ma_killed_in_mariadb() to detect kill.
  Ensure that file->external_ref points to TABLE object.
storage/maria/ma_extra.c:
  Dummy test-if-killed for standalone
storage/maria/ma_key.c:
  If ma_check_index_cond() fails, set my_errno and info->cur_row.lastpos
storage/maria/ma_rkey.c:
  Release/re-acquire locks to give queries that wait on them a chance to make progress
  Check if the query was killed, and return immediately if it was
storage/maria/ma_rnext.c:
  Check if the query was killed, and return immediately if it was
  Added missing fast_ma_writeinfo(info)
storage/maria/ma_rnext_same.c:
  Check if the query was killed, and return immediately if it was
  Added missing fast_ma_writeinfo(info)
storage/maria/ma_rprev.c:
  Check if the query was killed, and return immediately if it was
  Added missing fast_ma_writeinfo(info) and ma_check_index_cond()
storage/maria/ma_search.c:
  Give error message if we find a wrong key
storage/maria/ma_static.c:
  Added pointer to test-if-killed function
storage/maria/maria_def.h:
  New prototypes
storage/myisam/ha_myisam.cc:
  Added mi_killed_in_mariadb()
  Ensure that file->external_ref points to TABLE object.
storage/myisam/mi_extra.c:
  Dummy test-if-killed for standalone
storage/myisam/mi_key.c:
  If ma_check_index_cond() fails, set my_errno and info->lastpos
storage/myisam/mi_rkey.c:
  Ensure that info->lastpos= HA_OFFSET_ERROR in case of error
  Release/re-acquire locks to give queries that wait on them a chance to make progress
  Check if the query was killed, and return immediately if it was
  Reorder code to do less things in case of error.
  Added missing fast_mi_writeinfo()
storage/myisam/mi_rnext.c:
  Check if the query was killed, and return immediately if it was
  Simplify old ICP code
  Added missing fast_ma_writeinfo(info)
storage/myisam/mi_rnext_same.c:
  Check if the query was killed, and return immediately if it was
  Added missing fast_mi_writeinfo(info)
storage/myisam/mi_rprev.c:
  Check if the query was killed, and return immediately if it was
  Simplify error handling of ICP
  Added missing fast_mi_writeinfo(info)
storage/myisam/mi_search.c:
  Give error message if we find a wrong key
storage/myisam/mi_static.c:
  Added pointer to test-if-killed function
storage/myisam/myisamdef.h:
  New prototypes
storage/xtradb/handler/ha_innodb.cc:
  Added DB_SEARCH_ABORTED_BY_USER and ha_innobase::is_thd_killed()
  Check if the query was killed, and return immediately if it was
storage/xtradb/handler/ha_innodb.h:
  Added prototype
storage/xtradb/include/db0err.h:
  Added DB_SEARCH_ABORTED_BY_USER
storage/xtradb/include/row0mysql.h:
  Added possible ICP errors
storage/xtradb/row/row0sel.c:
  Use ICP errors instead of constants.
  Detect if killed and return B_SEARCH_ABORTED_BY_USER
2011-02-18 17:43:59 +02:00

155 lines
5.3 KiB
C

/* Copyright (C) 2002-2006 MySQL AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; version 2
of the License.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
#ifndef _my_handler_h
#define _my_handler_h
#include "myisampack.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
There is a hard limit for the maximum number of keys as there are only
8 bits in the index file header for the number of keys in a table.
This means that 0..255 keys can exist for a table. The idea of
HA_MAX_POSSIBLE_KEY is to ensure that one can use myisamchk & tools on
a MyISAM table for which one has more keys than MyISAM is normally
compiled for. If you don't have this, you will get a core dump when
running myisamchk compiled for 128 keys on a table with 255 keys.
*/
#define HA_MAX_POSSIBLE_KEY 255 /* For myisamchk */
/*
The following defines can be increased if necessary.
But beware the dependency of HA_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH.
*/
#define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */
#define HA_MAX_KEY_SEG 32 /* Max segments for key */
#define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24+ 6+6)
#define HA_MAX_KEY_BUFF (HA_MAX_KEY_LENGTH+HA_MAX_KEY_SEG*6+8+8)
#define HA_MAX_MSG_BUF 1024 /* used in CHECK TABLE, REPAIR TABLE */
typedef struct st_HA_KEYSEG /* Key-portion */
{
CHARSET_INFO *charset;
uint32 start; /* Start of key in record */
uint32 null_pos; /* position to NULL indicator */
uint16 bit_pos; /* Position to bit part */
uint16 flag;
uint16 length; /* Keylength */
uint8 type; /* Type of key (for sort) */
uint8 language;
uint8 null_bit; /* bitmask to test for NULL */
uint8 bit_start,bit_end; /* if bit field */
uint8 bit_length; /* Length of bit part */
} HA_KEYSEG;
#define get_key_length(length,key) \
{ if (*(const uchar*) (key) != 255) \
length= (uint) *(const uchar*) ((key)++); \
else \
{ length= mi_uint2korr((key)+1); (key)+=3; } \
}
#define get_key_length_rdonly(length,key) \
{ if (*(const uchar*) (key) != 255) \
length= ((uint) *(const uchar*) ((key))); \
else \
{ length= mi_uint2korr((key)+1); } \
}
#define get_key_pack_length(length,length_pack,key) \
{ if (*(const uchar*) (key) != 255) \
{ length= (uint) *(const uchar*) ((key)++); length_pack= 1; }\
else \
{ length=mi_uint2korr((key)+1); (key)+= 3; length_pack= 3; } \
}
#define store_key_length_inc(key,length) \
{ if ((length) < 255) \
{ *(key)++= (length); } \
else \
{ *(key)=255; mi_int2store((key)+1,(length)); (key)+=3; } \
}
#define size_to_store_key_length(length) ((length) < 255 ? 1 : 3)
#define get_rec_bits(bit_ptr, bit_ofs, bit_len) \
(((((uint16) (bit_ptr)[1] << 8) | (uint16) (bit_ptr)[0]) >> (bit_ofs)) & \
((1 << (bit_len)) - 1))
#define set_rec_bits(bits, bit_ptr, bit_ofs, bit_len) \
{ \
(bit_ptr)[0]= ((bit_ptr)[0] & ~(((1 << (bit_len)) - 1) << (bit_ofs))) | \
((bits) << (bit_ofs)); \
if ((bit_ofs) + (bit_len) > 8) \
(bit_ptr)[1]= ((bit_ptr)[1] & ~((1 << ((bit_len) - 8 + (bit_ofs))) - 1)) | \
((bits) >> (8 - (bit_ofs))); \
}
#define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \
set_rec_bits(0, bit_ptr, bit_ofs, bit_len)
extern int ha_compare_text(CHARSET_INFO *, const uchar *, uint,
const uchar *, uint , my_bool, my_bool);
extern int ha_key_cmp(register HA_KEYSEG *keyseg, register const uchar *a,
register const uchar *b, uint key_length,
uint32 nextflag, uint *diff_pos);
extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a);
extern void my_handler_error_register(void);
extern void my_handler_error_unregister(void);
/*
Inside an in-memory data record, memory pointers to pieces of the
record (like BLOBs) are stored in their native byte order and in
this amount of bytes.
*/
#define portable_sizeof_char_ptr 8
/**
Return values of index_cond_func_xxx functions.
0=ICP_NO_MATCH - index tuple doesn't satisfy the pushed index condition (the
engine should discard the tuple and go to the next one)
1=ICP_MATCH - index tuple satisfies the pushed index condition (the engine
should fetch and return the record)
2=ICP_OUT_OF_RANGE - index tuple is out range that we're scanning, e.g. this
if we're scanning "t.key BETWEEN 10 AND 20" and got a
"t.key=21" tuple (the engine should stop scanning and return
HA_ERR_END_OF_FILE right away).
-1= ICP_ERROR - Reserved for internal errors in engines. Should not be
returned by index_cond_func_xxx
*/
typedef enum icp_result {
ICP_ERROR=-1,
ICP_NO_MATCH=0,
ICP_MATCH=1,
ICP_OUT_OF_RANGE=2
} ICP_RESULT;
#ifdef __cplusplus
}
#endif
#endif /* _my_handler_h */