mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
0d61bd9dce
A REPLACE in the MERGE engine is actually a REPLACE into one (FIRST or LAST) of the underlying MyISAM tables. So in effect the server works on the meta data of the MERGE table, while the real insert happens in the MyISAM table. The MERGE table has no index, while MyISAM has a unique index. When a REPLACE into a MERGE table ( and the REPLACE conflicts with a duplicate in a child table) is done, we try to access the duplicate key information for the MERGE table. This information actually does not exist, hence this results in a crash. The problem can be resolved by modifying the MERGE engine to provide us the duplicate key information directly, instead of just returning the MyISAM index number as the error key. Then the SQL layer (or "the server") does not try to access the key_info of the MERGE table, which does not exist. The current patch modifies the MERGE engine to provide the position for a record where a unique key violation occurs. include/myisammrg.h: Bug#45800 crash when replacing into a merge table and there is a duplicate Add a member to the st_mymerge_info structure that will store the duplicate key offset in the MERGE table. This offset will be the sum of the record offset of the MyISAM table within the MERGE table and the offset of the record within the MyISAM table. mysql-test/r/merge.result: Bug#45800 crash when replacing into a merge table and there is a duplicate Result file for the test case. mysql-test/t/merge.test: Bug#45800 crash when replacing into a merge table and there is a duplicate Added test case for both REPLACE and INSERT...ON DUPLICATE UPDATE. storage/myisammrg/ha_myisammrg.cc: Bug#45800 crash when replacing into a merge table and there is a duplicate The info method now will process the HA_STATUS_ERRKEY flag and will return the index and the offset of the duplicate key. storage/myisammrg/ha_myisammrg.h: Bug#45800 crash when replacing into a merge table and there is a duplicate Set the HA_DUPLICATE_POS flag to indicate that the duplicate key information is now available in the MERGE storage engine. storage/myisammrg/myrg_info.c: Bug#45800 crash when replacing into a merge table and there is a duplicate We modify the myrg_status function to return the position of the duplicate key. The duplicate key position in the MERGE table will be the MyISAM file_offset and the offset within the MyISAM table of the start position of the records.
123 lines
4.5 KiB
C
123 lines
4.5 KiB
C
/* Copyright (C) 2000 MySQL 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 */
|
|
|
|
/* This file should be included when using merge_isam_funktions */
|
|
|
|
#ifndef _myisammrg_h
|
|
#define _myisammrg_h
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifndef _my_base_h
|
|
#include <my_base.h>
|
|
#endif
|
|
#ifndef _myisam_h
|
|
#include <myisam.h>
|
|
#endif
|
|
|
|
#include <queues.h>
|
|
|
|
#define MYRG_NAME_EXT ".MRG"
|
|
|
|
/* In which table to INSERT rows */
|
|
#define MERGE_INSERT_DISABLED 0
|
|
#define MERGE_INSERT_TO_FIRST 1
|
|
#define MERGE_INSERT_TO_LAST 2
|
|
|
|
extern TYPELIB merge_insert_method;
|
|
|
|
/* Param to/from myrg_info */
|
|
|
|
typedef struct st_mymerge_info /* Struct from h_info */
|
|
{
|
|
ulonglong records; /* Records in database */
|
|
ulonglong deleted; /* Deleted records in database */
|
|
ulonglong recpos; /* Pos for last used record */
|
|
ulonglong data_file_length;
|
|
ulonglong dupp_key_pos; /* Offset of the Duplicate key in the merge table */
|
|
uint reclength; /* Recordlength */
|
|
int errkey; /* With key was dupplicated on err */
|
|
uint options; /* HA_OPTION_... used */
|
|
ulong *rec_per_key; /* for sql optimizing */
|
|
} MYMERGE_INFO;
|
|
|
|
typedef struct st_myrg_table_info
|
|
{
|
|
struct st_myisam_info *table;
|
|
ulonglong file_offset;
|
|
} MYRG_TABLE;
|
|
|
|
typedef struct st_myrg_info
|
|
{
|
|
MYRG_TABLE *open_tables,*current_table,*end_table,*last_used_table;
|
|
ulonglong records; /* records in tables */
|
|
ulonglong del; /* Removed records */
|
|
ulonglong data_file_length;
|
|
ulong cache_size;
|
|
uint merge_insert_method;
|
|
uint tables,options,reclength,keys;
|
|
my_bool cache_in_use;
|
|
/* If MERGE children attached to parent. See top comment in ha_myisammrg.cc */
|
|
my_bool children_attached;
|
|
LIST open_list;
|
|
QUEUE by_key;
|
|
ulong *rec_per_key_part; /* for sql optimizing */
|
|
pthread_mutex_t mutex;
|
|
} MYRG_INFO;
|
|
|
|
|
|
/* Prototypes for merge-functions */
|
|
|
|
extern int myrg_close(MYRG_INFO *file);
|
|
extern int myrg_delete(MYRG_INFO *file,const uchar *buff);
|
|
extern MYRG_INFO *myrg_open(const char *name,int mode,int wait_if_locked);
|
|
extern MYRG_INFO *myrg_parent_open(const char *parent_name,
|
|
int (*callback)(void*, const char*),
|
|
void *callback_param);
|
|
extern int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
|
|
MI_INFO *(*callback)(void*),
|
|
void *callback_param,
|
|
my_bool *need_compat_check);
|
|
extern int myrg_detach_children(MYRG_INFO *m_info);
|
|
extern int myrg_panic(enum ha_panic_function function);
|
|
extern int myrg_rfirst(MYRG_INFO *file,uchar *buf,int inx);
|
|
extern int myrg_rlast(MYRG_INFO *file,uchar *buf,int inx);
|
|
extern int myrg_rnext(MYRG_INFO *file,uchar *buf,int inx);
|
|
extern int myrg_rprev(MYRG_INFO *file,uchar *buf,int inx);
|
|
extern int myrg_rnext_same(MYRG_INFO *file,uchar *buf);
|
|
extern int myrg_rkey(MYRG_INFO *info,uchar *buf,int inx, const uchar *key,
|
|
key_part_map keypart_map, enum ha_rkey_function search_flag);
|
|
extern int myrg_rrnd(MYRG_INFO *file,uchar *buf,ulonglong pos);
|
|
extern int myrg_rsame(MYRG_INFO *file,uchar *record,int inx);
|
|
extern int myrg_update(MYRG_INFO *file,const uchar *old,uchar *new_rec);
|
|
extern int myrg_write(MYRG_INFO *info,uchar *rec);
|
|
extern int myrg_status(MYRG_INFO *file,MYMERGE_INFO *x,int flag);
|
|
extern int myrg_lock_database(MYRG_INFO *file,int lock_type);
|
|
extern int myrg_create(const char *name, const char **table_names,
|
|
uint insert_method, my_bool fix_names);
|
|
extern int myrg_extra(MYRG_INFO *file,enum ha_extra_function function,
|
|
void *extra_arg);
|
|
extern int myrg_reset(MYRG_INFO *info);
|
|
extern void myrg_extrafunc(MYRG_INFO *info,invalidator_by_filename inv);
|
|
extern ha_rows myrg_records_in_range(MYRG_INFO *info, int inx,
|
|
key_range *min_key, key_range *max_key);
|
|
extern ha_rows myrg_records(MYRG_INFO *info);
|
|
|
|
extern ulonglong myrg_position(MYRG_INFO *info);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|