From 69dd773b67a9892561f148964e51d3be606f7c77 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 13 Sep 2010 15:22:11 -0700 Subject: An implementation of index intersect via a modified Unique class. This code is planned to be used for mwl#21. --- include/my_tree.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/my_tree.h b/include/my_tree.h index ceeb849ad0c..ca207932c73 100644 --- a/include/my_tree.h +++ b/include/my_tree.h @@ -31,6 +31,7 @@ extern "C" { #define tree_set_pointer(element,ptr) *((uchar **) (element+1))=((uchar*) (ptr)) #define TREE_NO_DUPS 1 +#define TREE_ONLY_DUPS 2 typedef enum { left_root_right, right_root_left } TREE_WALK; typedef uint32 element_count; -- cgit v1.2.1 From 9d68ccdeb8692b05d9cc0479d8d3757edbc49368 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sun, 7 Nov 2010 14:25:29 +0200 Subject: Added option BACKUP_ALL to mysqld --myisam-recover to also get a backup of the index file before it's repaired. Removed wrong call to translog_buffer_unlock() that caused 'unlocking not locked mutex' failure in Aria log handler. extra/replace.c: Updated call to my_redel() include/maria.h: Updated prototype for maria_change_to_newfile include/my_sys.h: Updated prototypes Added my_create_backup_name include/myisam.h: Updated prototypes include/myisamchk.h: Added 'backup_time' to st_handler_check_param to be able to generate same name for backuped data and index file mysys/my_redel.c: Added time_t option to my_redel() to be able to generate same backup extensions for many files sql/handler.cc: Added start_time to st_ha_check_opt sql/handler.h: Added start_time to HA_CHECK_OPT sql/mysqld.cc: Added option BACKUP_ALL to --myisam-recover storage/maria/ha_maria.cc: Remember start time for repair storage/maria/ma_check.c: Use remembered start time for backup file names Removed some dead code storage/maria/ma_loghandler.c: Removed wrong call to translog_buffer_unlock() that caused 'unlocking not locked mutex' failure in log handler. storage/maria/maria_chk.c: Removed dead code (O_NEW_INDEX was never set) Report if table was 'crashed on repair' storage/maria/maria_pack.c: Updated parameters to my_redel() storage/myisam/ha_myisam.cc: Added recover option BACKUP_ALL to get a backup of the index file before it's repaired. Print information to log if we make a backup of data as part of repair. storage/myisam/ha_myisam.h: Added HA_RECOVER_FULL_BACKUP storage/myisam/mi_check.c: Use remembered start time for backup file names Added mi_make_backup_of_index() storage/myisam/myisamchk.c: Removed dead code (O_NEW_INDEX was never set) Report if table was 'crashed on repair' storage/myisam/myisampack.c: Updated call to my_redel() --- include/maria.h | 3 ++- include/my_sys.h | 8 +++++++- include/myisam.h | 5 ++++- include/myisamchk.h | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/maria.h b/include/maria.h index 106aa61ddbb..fb09116a24c 100644 --- a/include/maria.h +++ b/include/maria.h @@ -430,7 +430,8 @@ int maria_repair_by_sort(HA_CHECK *param, MARIA_HA *info, int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, const char *name, my_bool rep_quick); int maria_change_to_newfile(const char *filename, const char *old_ext, - const char *new_ext, myf myflags); + const char *new_ext, time_t backup_time, + myf myflags); void maria_lock_memory(HA_CHECK *param); int maria_update_state_info(HA_CHECK *param, MARIA_HA *info, uint update); void maria_update_key_parts(MARIA_KEYDEF *keyinfo, double *rec_per_key_part, diff --git a/include/my_sys.h b/include/my_sys.h index 2f8a44fedc0..6f5e0328fe9 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -135,6 +135,9 @@ extern int NEAR my_errno; /* Last error in mysys */ #define GETDATE_GMT 8 #define GETDATE_FIXEDLENGTH 16 +/* Extra length needed for filename if one calls my_create_backup_name */ +#define MY_BACKUP_NAME_EXTRA_LENGTH 17 + /* defines when allocating data */ #ifdef SAFEMALLOC #define my_malloc(SZ,FLAG) _mymalloc((SZ), __FILE__, __LINE__, FLAG ) @@ -685,7 +688,10 @@ extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags); extern int my_message_curses(uint my_err, const char *str,myf MyFlags); extern my_bool my_init(void); extern void my_end(int infoflag); -extern int my_redel(const char *from, const char *to, int MyFlags); +extern int my_redel(const char *from, const char *to, time_t backup_time_stamp, + myf MyFlags); +void my_create_backup_name(char *to, const char *from, + time_t backup_time_stamp); extern int my_copystat(const char *from, const char *to, int MyFlags); extern char * my_filename(File fd); diff --git a/include/myisam.h b/include/myisam.h index 8413b7936e3..bf31a96b792 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -295,6 +295,8 @@ extern int mi_is_changed(struct st_myisam_info *info); extern int mi_delete_all_rows(struct st_myisam_info *info); extern ulong _mi_calc_blob_length(uint length , const uchar *pos); extern uint mi_get_pointer_length(ulonglong file_length, uint def); +extern int mi_make_backup_of_index(struct st_myisam_info *info, + time_t backup_time, myf flags); #define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for mmap file */ /* this is used to pass to mysql_myisamchk_table */ @@ -390,7 +392,8 @@ int mi_repair_by_sort(HA_CHECK *param, register MI_INFO *info, int mi_repair_parallel(HA_CHECK *param, register MI_INFO *info, const char * name, int rep_quick); int change_to_newfile(const char * filename, const char * old_ext, - const char * new_ext, uint raid_chunks, + const char * new_ext, time_t backup_time, + uint raid_chunks, myf myflags); int lock_file(HA_CHECK *param, File file, my_off_t start, int lock_type, const char *filetype, const char *filename); diff --git a/include/myisamchk.h b/include/myisamchk.h index 057c06652a1..7d7100bdd71 100644 --- a/include/myisamchk.h +++ b/include/myisamchk.h @@ -74,7 +74,7 @@ #define TT_USEFRM 1 #define TT_FOR_UPGRADE 2 -#define O_NEW_INDEX 1 /* Bits set in out_flag */ +/* Bits set in out_flag */ #define O_NEW_DATA 2 #define O_DATA_LOST 4 @@ -141,6 +141,7 @@ typedef struct st_handler_check_param ulonglong use_buffers; /* Used as param to getopt() */ size_t read_buffer_length, write_buffer_length; size_t sort_buffer_length, sort_key_blocks; + time_t backup_time; /* To sign backup files */ ulong rec_per_key_part[HA_MAX_KEY_SEG * HA_MAX_POSSIBLE_KEY]; double new_rec_per_key_part[HA_MAX_KEY_SEG * HA_MAX_POSSIBLE_KEY]; uint out_flag, warning_printed, error_printed, verbose; -- cgit v1.2.1 From c87923dc2d3f6b5e96d51957937be8a5b343ab51 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 1 Dec 2010 21:37:03 +0100 Subject: Make maria 5.1 compilable on Visual Studio 2010 and remove Windows warnings - Remove all mentioning of /MAP /MAPINFO link options (does not work in VS2010). Remove map files from packaging. - Fix warning about ETIMEDOUT being redefined. - Fix warning about FSP_EXTENT_SIZE in xtradb (32/64 bit right shift mismatch) - Silence warnings coming from generated code (flex/bison) in xtradb/innodb_plugin. - Be nice to people without cygwin (me) and add win/configure-mariadb.bat with options suitable for quick compilation, e.g no embedded --- include/my_pthread.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_pthread.h b/include/my_pthread.h index cadde5df06a..9ada1d90712 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -127,8 +127,9 @@ struct tm *gmtime_r(const time_t *timep,struct tm *tmp); void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ - +#ifndef ETIMEDOUT #define ETIMEDOUT 145 /* Win32 doesn't have this */ +#endif #define getpid() GetCurrentThreadId() #define HAVE_LOCALTIME_R 1 #define _REENTRANT 1 -- cgit v1.2.1 From ffb0cd6146662705491e1461a7727c9627f9bd15 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 13 Dec 2010 15:05:57 +0200 Subject: When compiling with valgrind, change my_alloca() to use my_malloc() - This allows us to detect missing my_afree() calls and also find overruns (when running with valgrind) to alloca() areas. - Added missing my_afree() calls - Fixed wrong call to my_afree() include/my_sys.h: When compiling with valgrind, change my_alloca() to use my_malloc() mysql-test/suite/innodb/t/innodb_bug57255.test: Speed up taste case (patch from Stewart Smith) mysql-test/suite/innodb_plugin/t/innodb_bug57255.test: Speed up taste case (patch from Stewart Smith) sql/ha_partition.cc: Removed casts from my_afree() sql/opt_range.cc: Add missing my_afree() calls. storage/maria/ma_rt_split.c: Fixed wrong parameter to my_afree() --- include/my_sys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_sys.h b/include/my_sys.h index 309cb9c59b9..f5e38c5858e 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -197,7 +197,7 @@ extern void my_large_free(uchar * ptr, myf my_flags); #define my_large_free(A,B) my_free_lock((A),(B)) #endif /* HAVE_LARGE_PAGES */ -#ifdef HAVE_ALLOCA +#if defined(HAVE_ALLOCA) && !defined(HAVE_valgrind) #if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43) #pragma alloca #endif /* _AIX */ -- cgit v1.2.1 From 65af63b038cb2ccc0503d6f67f6b70a8e9e438a0 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sun, 19 Dec 2010 00:44:39 -0800 Subject: Addressed the feedback from the review of Monty on the cumulative patch for mwl#21. --- include/my_tree.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/my_tree.h b/include/my_tree.h index ca207932c73..3aeef20e0ad 100644 --- a/include/my_tree.h +++ b/include/my_tree.h @@ -30,6 +30,15 @@ extern "C" { #define tree_set_pointer(element,ptr) *((uchar **) (element+1))=((uchar*) (ptr)) +/* + A tree with its flag set to TREE_ONLY_DUPS behaves differently on inserting + an element that is not in the tree: + the element is not added at all, but instead tree_insert() returns a special + address TREE_ELEMENT_UNIQUE as an indication that the function has not failed + due to lack of memory. +*/ + +#define TREE_ELEMENT_UNIQUE ((TREE_ELEMENT *) 1) #define TREE_NO_DUPS 1 #define TREE_ONLY_DUPS 2 -- cgit v1.2.1 From e63b5546c597f65696868eaf69159107bc4a8e44 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 4 Jan 2011 00:55:41 +0200 Subject: Implementation of MWL#172: Add support for prepared statements to HANDLER READ It includes speed optimizations for HANDLER READ by caching as much as possible in HANDLER OPEN Other things: - Added mysqld option --disable-thr-alarm to be able to benchmark things without thr_alarm - Changed 'Locked' state to 'System lock' and 'Table lock' (these where used in the code but never shown to end user) - Better error message if mysql_install_db.sh fails - Moved handler function prototypes to sql_handler.h - Remove not anymore used 'thd->locked' member include/thr_alarm.h: Added my_disable_thr_alarm include/thr_lock.h: Add new member to THR_LOCK_DATA to remember original lock type state. This is needed as thr_unlock() resets type to TL_UNLOCK. mysql-test/include/check_no_concurrent_insert.inc: Locked -> Table lock mysql-test/include/handler.inc: Locked -> Table lock mysql-test/r/handler_innodb.result: Updated results for new tests mysql-test/r/handler_myisam.result: Updated results for new tests mysql-test/r/sp-threads.result: Locked -> Table lock mysql-test/suite/binlog/t/binlog_stm_row.test: Locked -> Table lock mysql-test/suite/funcs_1/datadict/processlist_val.inc: Locked -> Table lock mysql-test/suite/pbxt/t/lock_multi.test: Locked -> Table lock mysql-test/suite/sys_vars/r/concurrent_insert_func.result: Locked -> Table lock mysql-test/suite/sys_vars/t/concurrent_insert_func.test: Locked -> Table lock mysql-test/suite/sys_vars/t/delayed_insert_limit_func.test: Locked -> Table lock mysql-test/suite/sys_vars/t/query_cache_wlock_invalidate_func.test: Locked -> Table lock mysql-test/suite/sys_vars/t/sql_low_priority_updates_func.test: Locked -> Table lock mysql-test/t/insert_notembedded.test: Locked -> Table lock mysql-test/t/lock_multi.test: Locked -> Table lock mysql-test/t/merge-big.test: Locked -> Table lock mysql-test/t/multi_update.test: Locked -> Table lock mysql-test/t/query_cache_28249.test: Locked -> Table lock mysql-test/t/sp_notembedded.test: Locked -> Table lock mysql-test/t/sp_sync.test: Locked -> Table lock mysql-test/t/status.test: Locked -> Table lock mysql-test/t/trigger_notembedded.test: Locked -> Table lock mysys/thr_alarm.c: Added option to disable thr_alarm mysys/thr_lock.c: Detect loops scripts/mysql_install_db.sh: Give better error message if something goes wrong sql/Makefile.am: Added sql_handler.h sql/lock.cc: Split functions to allow one to cache value if store_lock() (for HANDLER functions). - Split mysql_lock_tables() into two functions, where first one allocates MYSQL_LOCK and other other one uses it. - Made get_lock_data() an external function. - Added argument to mysql_unlock_tables() to not free sql_lock. - Added argument to reset_lock_data() to reset lock structure to initial state (as after get_lock_data()) sql/mysql_priv.h: Moved handler function prototypes to sql_handler.h Added new lock functions. sql/mysqld.cc: Added --thread-alarm startup option sql/net_serv.cc: Don't call vio_blocking() if not needed sql/sql_base.cc: include sql_handler.h sql/sql_class.cc: include sql_handler.h Remove not anymore used 'thd->locked' member sql/sql_class.h: Remove not anymore used 'thd->locked' member sql/sql_db.cc: include sql_handler.h sql/sql_delete.cc: include sql_handler.h sql/sql_handler.cc: Rewrote all code to use SQL_HANDLER instead of TABLE_LIST (original interface) Rewrote mysql_ha_open() to cache all things from TABLE_LIST and items for field list, where etc. In mysql_ha_open() also cache MYSQL_LOCK structure from get_lock_data(). Split functions into smaller sub functions (needed to be able to implement mysql_ha_read_prepare()) Added mysql_ha_read_prepare() to allow one to prepare HANDLER READ. sql/sql_handler.h: Interface to sql_handler.cc sql/sql_parse.cc: include sql_handler.h sql/sql_prepare.cc: Added mysql_test_handler_read(), prepare for HANDLER READ sql/sql_rename.cc: include sql_handler.h sql/sql_show.cc: Removed usage of thd->locked sql/sql_table.cc: include sql_handler.h sql/sql_trigger.cc: include sql_handler.h --- include/thr_alarm.h | 1 + include/thr_lock.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/thr_alarm.h b/include/thr_alarm.h index 99812ed808c..806735b2d38 100644 --- a/include/thr_alarm.h +++ b/include/thr_alarm.h @@ -88,6 +88,7 @@ typedef struct st_alarm { extern uint thr_client_alarm; extern pthread_t alarm_thread; +extern my_bool my_disable_thr_alarm; #define thr_alarm_init(A) (*(A))=0 #define thr_alarm_in_use(A) (*(A)!= 0) diff --git a/include/thr_lock.h b/include/thr_lock.h index 08cc8bd5408..ec24bbabddd 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -123,8 +123,10 @@ typedef struct st_thr_lock_data { struct st_thr_lock *lock; pthread_cond_t *cond; void *status_param; /* Param to status functions */ - void *debug_print_param; enum thr_lock_type type; + + enum thr_lock_type org_type; /* Cache for MariaDB */ + void *debug_print_param; /* For error messages */ uint priority; } THR_LOCK_DATA; -- cgit v1.2.1 From 0d01dd200f97835dfb4e23676332f0ea28050c33 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 11 Jan 2011 18:51:59 +0200 Subject: Added HANDLER support for MEMORY tables Added key and file version numbers to MEMORY tables so that we can detect if someone has changed them between HANDLER calls. mysql-test/suite/handler/aria.result: Fixed result after test changes mysql-test/suite/handler/handler.inc: Changed test to use combined key to ensure rows are returned in a pre-determinated order. mysql-test/suite/handler/heap.result: New result mysql-test/suite/handler/heap.test: Added test for HANDLER + HEAP mysql-test/suite/handler/innodb.result: Fixed result after test changes mysql-test/suite/handler/myisam.result: Fixed result after test changes sql/sql_handler.cc: Fixed wrong parameter to ha_index_next_same() storage/heap/ha_heap.cc: Abort key scan if table has changed. Abort table scan if table has been recreated. storage/heap/ha_heap.h: Added support for HANDLER storage/heap/hp_clear.c: Increase version number so that we can notice changes if using HANDLER storage/heap/hp_delete.c: Increase key data version number on key changes. storage/heap/hp_rfirst.c: Remember version of key data Give error if using read-first on hash key. storage/heap/hp_rkey.c: Remember version of key data storage/heap/hp_rlast.c: Remember version of key data Give error if using read-last on hash key. storage/heap/hp_rnext.c: Fixed that we get next key from last search. storage/heap/hp_rprev.c: Fixed that we get previous key from last search. storage/heap/hp_scan.c: Remember version of key and file data storage/heap/hp_update.c: Increase key data version number on key changes. storage/heap/hp_write.c: Increase key data version number on key changes. --- include/heap.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/heap.h b/include/heap.h index 4a1c7d419ed..74bec8079f2 100644 --- a/include/heap.h +++ b/include/heap.h @@ -136,6 +136,8 @@ typedef struct st_heap_share ulong min_records,max_records; /* Params to open */ ulonglong data_length,index_length,max_table_size; uint key_stat_version; /* version to indicate insert/delete */ + uint key_version; /* Updated on key change */ + uint file_version; /* Update on clear */ uint records; /* records */ uint blength; /* records rounded up to 2^n */ uint deleted; /* Deleted records in database */ @@ -173,6 +175,8 @@ typedef struct st_heap_info enum ha_rkey_function last_find_flag; TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1]; TREE_ELEMENT **last_pos; + uint key_version; /* Version at last read */ + uint file_version; /* Version at scan */ uint lastkey_len; my_bool implicit_emptied; #ifdef THREAD -- cgit v1.2.1 From fba96f7ccdd6661caa90ed345c3df2fe35ffdebd Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 14 Jan 2011 11:37:23 +0100 Subject: Added to Aria better hash for packed numeric data for unique handling. This was needed as the old code caused us to have LOTS of duplicate hash values when used by optimizer. include/m_ctype.h: Made my_hash_sort_bin() exernal storage/maria/ma_unique.c: Better hash for packed numeric data for unique handling. This was needed as the old code caused us to have LOTS of duplicate hash values when used by optimizer. --- include/m_ctype.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/m_ctype.h b/include/m_ctype.h index c2551b5d309..aea560e0740 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -357,6 +357,9 @@ extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t, extern void my_hash_sort_simple(CHARSET_INFO *cs, const uchar *key, size_t len, ulong *nr1, ulong *nr2); +extern void my_hash_sort_bin(CHARSET_INFO *cs, + const uchar *key, size_t len, ulong *nr1, + ulong *nr2); extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length); -- cgit v1.2.1 From f5ea301acc593b51b13303899246a38efff92c1a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 14 Jan 2011 11:54:39 +0100 Subject: Added support for NO_RECORD record format (don't store any row data) for Aria. This makes the keys smaller (no row pointer) and gives us proper errors if we use the table wrongly. sql/sql_select.cc: Use NO_RECORD for tables that doesn't need row data. storage/maria/Makefile.am: Added ma_norec.c storage/maria/ma_check.c: Added support for NO_RECORD record format (don't store any row data) storage/maria/ma_norec.c: Added support for NO_RECORD record format storage/maria/ma_open.c: Added support for NO_RECORD record format storage/maria/ma_search.c: Added support for 0 size row pointers (used with NO_RECORD) storage/maria/ma_test1.c: Added testing of NO_RECORD record format. storage/maria/maria_chk.c: Added support for NO_RECORD storage/maria/maria_def.h: Added support for NO_RECORD storage/maria/unittest/ma_test_all-t: Added testing of NO_RECORD record format --- include/my_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_base.h b/include/my_base.h index 8e6436bde70..8f50120a970 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -519,7 +519,7 @@ enum en_fieldtype { }; enum data_file_type { - STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD + STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD, NO_RECORD }; /* For key ranges */ -- cgit v1.2.1 From 69fe020f01a7eefa9f737291f0da2be56f42a6a0 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 26 Jan 2011 15:17:46 +0200 Subject: Fixed bugs found by buildbot: - Use -Wno-uninitialized if -DFORCE_INIT_OF_VARS is not used, to avoid warnings about not initialized variables. - Fixed compiler warnings - Added a name for each thr_lock to get better error messages (This is needed to find out why 'archive.test' sometimes fails) BUILD/SETUP.sh: Use -Wno-uninitialized if -DFORCE_INIT_OF_VARS is not used, to avoid warnings about not initialized variables. BUILD/build_mccge.sh: Use -Wno-uninitialized if -DFORCE_INIT_OF_VARS is not used, to avoid warnings about not initialized variables. client/mysqltest.cc: Fixed bug in remove_files_wildcards (the orignal code never removed anything) extra/libevent/devpoll.c: Fixed compiler warning include/thr_lock.h: Added a name for each thr_lock to get better error messages. mysql-test/suite/maria/t/maria3.test: Speed up test. mysys/thr_lock.c: Added a name for each thr_lock to get better error messages. Added a second 'check_locks' to find if something goes wrong in 'wake_up_waiters'. sql/lock.cc: Added a name for each thr_lock to get better error messages. storage/xtradb/fil/fil0fil.c: Fixed compiler warning --- include/thr_lock.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/thr_lock.h b/include/thr_lock.h index 08cc8bd5408..111fd5f4cf2 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -123,7 +123,7 @@ typedef struct st_thr_lock_data { struct st_thr_lock *lock; pthread_cond_t *cond; void *status_param; /* Param to status functions */ - void *debug_print_param; + void *debug_print_param; /* Used by MariaDB for TABLE ref */ enum thr_lock_type type; uint priority; } THR_LOCK_DATA; @@ -149,6 +149,7 @@ typedef struct st_thr_lock { my_bool (*start_trans)(void*); /* When all locks are taken */ my_bool (*check_status)(void *); void (*fix_status)(void *, void *);/* For thr_merge_locks() */ + const char *name; /* Used for error reporting */ my_bool allow_multiple_concurrent_insert; } THR_LOCK; -- cgit v1.2.1 From 4e17ec5a298b118e7f86df8d470abf06d3d5dbad Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 26 Jan 2011 18:16:39 +0100 Subject: fixes for solaris 10 configure.in: * don't use assembler when building with native linker and --with-embedded. Embedded uses PIC and our assembler sources aren't PIC * workaround for OpenSolaris Bug 6611808 extra/libevent/devpoll.c: compiler warning extra/yassl/src/buffer.cpp: include config.h first to make sure that _FILE_OFFSET_BITS is defined before including system headers extra/yassl/taocrypt/benchmark/benchmark.cpp: include config.h first to make sure that _FILE_OFFSET_BITS is defined before including system headers extra/yassl/taocrypt/test/test.cpp: include config.h first to make sure that _FILE_OFFSET_BITS is defined before including system headers include/my_pthread.h: workaround for OpenSolaris Bug 6611808 --- include/my_pthread.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/my_pthread.h b/include/my_pthread.h index 9ada1d90712..f1b9320a075 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -223,7 +223,11 @@ extern int my_pthread_getprio(pthread_t thread_id); typedef void *(* pthread_handler)(void *); #define my_pthread_once_t pthread_once_t +#if defined(PTHREAD_ONCE_INITIALIZER) +#define MY_PTHREAD_ONCE_INIT PTHREAD_ONCE_INITIALIZER +#else #define MY_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT +#endif #define my_pthread_once(C,F) pthread_once(C,F) /* Test first for RTS or FSU threads */ -- cgit v1.2.1 From b19e99865ccf3e946ebe59bf09add8e0452904ac Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sat, 29 Jan 2011 18:51:12 +0100 Subject: MWL#55 : cherrypick MySQL 5.5 CMake/build improvements in order to be able to build MSI based installer --- include/CMakeLists.txt | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/Makefile.am | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 include/CMakeLists.txt (limited to 'include') diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 00000000000..9bafbd43793 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,66 @@ +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# +# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +SET(HEADERS_GEN_CONFIGURE +${CMAKE_CURRENT_BINARY_DIR}/mysql_version.h +#${CMAKE_CURRENT_BINARY_DIR}/my_config.h +${CMAKE_CURRENT_BINARY_DIR}/mysqld_ername.h +${CMAKE_CURRENT_BINARY_DIR}/mysqld_error.h +${CMAKE_CURRENT_BINARY_DIR}/sql_state.h +) +SET(HEADERS_ABI + mysql.h + mysql_com.h + mysql_time.h + my_list.h + my_alloc.h + typelib.h + mysql/plugin.h + mysql/plugin_auth.h + mysql/client_plugin.h +) + +SET(HEADERS + ${HEADERS_ABI} + config-win.h + my_dbug.h + m_string.h + my_sys.h + my_xml.h + mysql_embed.h + my_pthread.h + my_no_pthread.h + decimal.h + errmsg.h + my_global.h + my_net.h + my_getopt.h + sslopt-longopts.h + my_dir.h + sslopt-vars.h + sslopt-case.h + sql_common.h + keycache.h + m_ctype.h + my_attribute.h + my_compiler.h + ${HEADERS_GEN_CONFIGURE} +) + +INSTALL(FILES ${HEADERS} DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT Development) +INSTALL(DIRECTORY mysql/ DESTINATION ${INSTALL_INCLUDEDIR}/mysql COMPONENT Development FILES_MATCHING PATTERN "*.h" ) + + + diff --git a/include/Makefile.am b/include/Makefile.am index d423e500aae..d81eb5f505c 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -46,7 +46,7 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ wqueue.h waiting_threads.h -EXTRA_DIST = mysql.h.pp mysql/plugin_auth.h.pp mysql/client_plugin.h.pp +EXTRA_DIST = mysql.h.pp mysql/plugin_auth.h.pp mysql/client_plugin.h.pp CMakeLists.txt # Remove built files and the symlinked directories CLEANFILES = $(BUILT_SOURCES) readline openssl -- cgit v1.2.1 From 785695e7c3df67f361acdfd2086328ddb7229b73 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sun, 30 Jan 2011 12:41:44 +0200 Subject: Flush DBUG log in case of DBUG_ASSERT() Added strings_def.h into strings library to be able to have a DBUG_ASSERT() version without _db_flush() call (as strings.a should not depend on dbug.a) Remove include of m_string.h in all string files (as it's included by string_def.h). Fixed include order. Changed "m_ctype.h" -> include/my_dbug.h: Flush DBUG log in case of DBUG_ASSERT() strings/bchange.c: Include strings_def.h strings/bcmp.c: Include strings_def.h strings/bfill.c: Include strings_def.h strings/bmove.c: Include strings_def.h strings/bmove512.c: Include strings_def.h strings/bmove_upp.c: Include strings_def.h strings/conf_to_src.c: Include strings_def.h Fixed copyright strings/ctype-big5.c: Include strings_def.h strings/ctype-bin.c: Include strings_def.h strings/ctype-cp932.c: Include strings_def.h strings/ctype-czech.c: Include strings_def.h strings/ctype-euc_kr.c: Include strings_def.h strings/ctype-eucjpms.c: Include strings_def.h strings/ctype-extra.c: Include strings_def.h strings/ctype-gbk.c: Include strings_def.h strings/ctype-latin1.c: Include strings_def.h strings/ctype-mb.c: Include strings_def.h strings/ctype-simple.c: Include strings_def.h strings/ctype-sjis.c: Include strings_def.h strings/ctype-tis620.c: Include strings_def.h strings/ctype-uca.c: Include strings_def.h strings/ctype-ucs2.c: Include strings_def.h strings/ctype-ujis.c: Include strings_def.h strings/ctype-utf8.c: Include strings_def.h strings/ctype-win1250ch.c: Include strings_def.h strings/ctype.c: Include strings_def.h strings/decimal.c: Include strings_def.h strings/do_ctype.c: Include strings_def.h strings/int2str.c: Include strings_def.h strings/is_prefix.c: Include strings_def.h strings/llstr.c: Include strings_def.h strings/longlong2str.c: Include strings_def.h strings/longlong2str_asm.c: Include strings_def.h strings/my_strchr.c: Include strings_def.h strings/my_strtoll10.c: Include strings_def.h strings/my_vsnprintf.c: Include strings_def.h strings/r_strinstr.c: Include strings_def.h strings/str2int.c: Include strings_def.h strings/str_alloc.c: Include strings_def.h strings/str_test.c: Include strings_def.h Fixed compiler warnings strings/strappend.c: Include strings_def.h strings/strcend.c: Include strings_def.h strings/strcont.c: Include strings_def.h strings/strend.c: Include strings_def.h strings/strfill.c: Include strings_def.h strings/strinstr.c: Include strings_def.h strings/strmake.c: Include strings_def.h strings/strmov.c: Include strings_def.h strings/strmov_overlapp.c: Include strings_def.h strings/strnlen.c: Include strings_def.h strings/strnmov.c: Include strings_def.h strings/strstr.c: Include strings_def.h strings/strto.c: Include strings_def.h strings/strtod.c: Include strings_def.h strings/strtol.c: Include strings_def.h strings/strtoll.c: Include strings_def.h strings/strtoul.c: Include strings_def.h strings/strtoull.c: Include strings_def.h strings/strxmov.c: Include strings_def.h strings/strxnmov.c: Include strings_def.h strings/uctypedump.c: Include strings_def.h Fixed compiler warnings Removed double include of m_ctype.h strings/udiv.c: Include strings_def.h strings/xml.c: Include strings_def.h --- include/my_dbug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_dbug.h b/include/my_dbug.h index e1cd4e2b7dc..3c1eb820028 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -126,7 +126,7 @@ extern void _db_flush_(); #define DBUG_END() _db_end_ () #define DBUG_LOCK_FILE _db_lock_file_() #define DBUG_UNLOCK_FILE _db_unlock_file_() -#define DBUG_ASSERT(A) assert(A) +#define DBUG_ASSERT(A) do { _db_flush_(); assert(A); } while(0) #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len)) #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) #define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) -- cgit v1.2.1 From b12e3796dc70466eca5ef3f25d51234b32af5113 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 18 Feb 2011 17:43:59 +0200 Subject: 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 --- include/my_base.h | 3 ++- include/my_handler.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_base.h b/include/my_base.h index 8f50120a970..a5f18146859 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -445,7 +445,8 @@ enum ha_base_keytype { #define HA_ERR_WRONG_CRC 176 /* Wrong CRC on page */ #define HA_ERR_ROW_NOT_VISIBLE 177 #define HA_ERR_TOO_MANY_CONCURRENT_TRXS 178 /*Too many active concurrent transactions */ -#define HA_ERR_LAST 178 /* Copy of last error nr */ +#define HA_ERR_ABORTED_BY_USER 179 +#define HA_ERR_LAST 179 /* Copy of last error nr */ /* Number of different errors */ #define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1) diff --git a/include/my_handler.h b/include/my_handler.h index 275dd92fa18..5fc0565538d 100644 --- a/include/my_handler.h +++ b/include/my_handler.h @@ -135,6 +135,9 @@ extern void my_handler_error_unregister(void); 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 { -- cgit v1.2.1 From 7e0e4b00c971b81b5ffd18db4f1ea977233e98be Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Feb 2011 18:43:29 +0100 Subject: we don't support longlong less than 8 bytes --- include/my_global.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/my_global.h b/include/my_global.h index ec22a57329b..5b70ba47b74 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -830,10 +830,10 @@ typedef SOCKET_SIZE_TYPE size_socket; #define strtok_r(A,B,C) strtok((A),(B)) #endif -/* This is from the old m-machine.h file */ - -#if SIZEOF_LONG_LONG > 4 +#if SIZEOF_LONG_LONG >= 8 #define HAVE_LONG_LONG 1 +#else +#error WHAT? sizeof(long long) < 8 ??? #endif /* -- cgit v1.2.1 From a8a757c6bb32bbf291afdf33df861127489889ab Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 1 Mar 2011 13:24:36 +0100 Subject: wl#173 - temporal types with sub-second resolution and collateral changes. * introduce my_hrtime_t, my_timediff_t, and conversion macros * inroduce TIME_RESULT, but it can only be returned from Item::cmp_type(), never from Item::result_type() * pack_time/unpack_time function for "packed" representation of MYSQL_TIME in a longlong that can be compared * ADDTIME()/SUBTIME()/+- INTERVAL now work with TIME values * numbers aren't quoted in EXPLAIN EXTENDED * new column I_S.COLUMNS.DATETIME_PRECISION * date/time values are compares to anything as date/time, not as strings or numbers. * old timestamp(X) is no longer supported * MYSQL_TIME to string conversion functions take precision as an argument * unified the warnings from Field_timestamp/datetime/time/date/newdate store methods * Field_timestamp_hires, Field_datetime_hires, Field_time_hires * Field_temporal * Lazy_string class to pass a value (string, number, time) polymorphically down the stack * make_truncated_value_warning and Field::set_datetime_warning use Lazy_string as an argument, removed char*/int/double variants * removed Field::can_be_compared_as_longlong(). Use Field::cmp_type() == INT_RESULT instead * introduced Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong() * in many cases date/time types are treated like other types, not as special cases * greatly simplified Arg_comparator (regarding date/time/year code) * SEC_TO_TIME is real function, not integer. * microsecond precision in NOW, CURTIME, etc * Item_temporal. All items derived from it only provide get_date, but no val* methods * replication of NOW(6) * Protocol::store(time) now takes the precision as an argument * @@TIMESTAMP is a double client/mysqlbinlog.cc: remove unneded casts include/my_sys.h: introduce my_hrtime_t, my_timediff_t, and conversion macros include/my_time.h: pack_time/unpack_time, etc. convenience functions to work with MYSQL_TIME::second_part libmysql/libmysql.c: str_to_time() is gone. str_to_datetime() does it now. my_TIME_to_str() takes the precision as an argument mysql-test/include/ps_conv.inc: time is not equal to datetime anymore mysql-test/r/distinct.result: a test for an old MySQL bug mysql-test/r/explain.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/func_default.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/func_sapdb.result: when decimals=NOT_FIXED_DEC it means "not fixed" indeed mysql-test/r/func_test.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/func_time.result: ADDTIME()/SUBTIME()/+- INTERVAL now work with TIME values mysql-test/r/having.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/information_schema.result: new column I_S.COLUMNS.DATETIME_PRECISION mysql-test/r/join_outer.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/metadata.result: TIMESTAMP no longer has zerofill flag mysql-test/r/range.result: invalid datetime is not compared with as a string mysql-test/r/select.result: NO_ZERO_IN_DATE, etc only affect storage - according to the manual numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/subselect.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/sysdate_is_now.result: when decimals=NOT_FIXED_DEC it means "not fixed" indeed mysql-test/r/type_blob.result: TIMESTAMP(N) is not deprecated mysql-test/r/type_timestamp.result: old TIMESTAMP(X) semantics is not supported anymore mysql-test/r/union.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/r/varbinary.result: numbers aren't quoted in EXPLAIN EXTENDED mysql-test/t/distinct.test: test for an old MySQL bug mysql-test/t/func_time.test: +- INTERVAL now works with TIME values mysql-test/t/select.test: typo mysql-test/t/subselect.test: only one error per statement, please mysql-test/t/system_mysql_db_fix40123.test: old timestamp(X) is no longer supported mysql-test/t/system_mysql_db_fix50030.test: old timestamp(X) is no longer supported mysql-test/t/system_mysql_db_fix50117.test: old timestamp(X) is no longer supported mysql-test/t/type_blob.test: old timestamp(X) is no longer supported mysql-test/t/type_timestamp.test: old timestamp(X) is no longer supported mysys/my_getsystime.c: functions to get the time with microsecond precision mysys/my_init.c: move the my_getsystime.c initialization code to my_getsystime.c mysys/my_static.c: no need to make these variables extern mysys/my_static.h: no need to make these variables extern scripts/mysql_system_tables.sql: old timestamp(X) is no longer supported scripts/mysql_system_tables_fix.sql: old timestamp(X) is no longer supported scripts/mysqlhotcopy.sh: old timestamp(X) is no longer supported sql-common/my_time.c: * call str_to_time from str_to_datetime, as appropriate * date/time to string conversions take precision as an argument * number_to_time() * TIME_to_double() * pack_time() and unpack_time() sql/event_data_objects.cc: cast is not needed my_datetime_to_str() takes precision as an argument sql/event_db_repository.cc: avoid dangerous downcast (because the pointer is not always Field_timestamp, see events_1.test) sql/event_queue.cc: avoid silly double-work for cond_wait (having an endpoint of wait, subtract the current time to get the timeout, and use set_timespec() macro to fill in struct timespec, by adding the current time to the timeout) sql/field.cc: * remove virtual Field::get_time(), everyone should use only Field::get_date() * remove lots of #ifdef WORDS_BIGENDIAN * unified the warnings from Field_timestamp/datetime/time/date/newdate store methods * Field_timestamp_hires, Field_datetime_hires, Field_time_hires * Field_temporal * make_truncated_value_warning and Field::set_datetime_warning use Lazy_string as an argument, removed char*/int/double variants sql/field.h: * remove virtual Field::get_time(), everyone should use only Field::get_date() * remove lots of #ifdef WORDS_BIGENDIAN * unified the warnings from Field_timestamp/datetime/time/date/newdate store methods * Field_timestamp_hires, Field_datetime_hires, Field_time_hires * Field_temporal * make_truncated_value_warning and Field::set_datetime_warning use Lazy_string as an argument, removed char*/int/double variants * removed Field::can_be_compared_as_longlong(). Use Field::cmp_type() == INT_RESULT instead sql/filesort.cc: TIME_RESULT, cmp_time() sql/item.cc: * numbers aren't quoted in EXPLAIN EXTENDED * Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong() * virtual Item::get_time() is gone * Item_param::field_type() is set correctly * Item_datetime, for a datetime constant * time to anything is compared as a time * Item_cache::print() prints the value is available * bug fixed in Item_cache_int::val_str() sql/item.h: * Item::print_value(), to be used from Item_xxx::print() when needed * Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong() * virtual Item::get_time() is gone * Item_datetime, for a datetime constant * better default for cast_to_int_type() * Item_cache objects now *always* have the field_type() set sql/item_cmpfunc.cc: * get_year_value, get_time_value are gone. get_datetime_value does it all * get_value_a_func, get_value_b_func are gone * can_compare_as_dates() is gone too, TIME_RESULT is used instead * cmp_type() instead or result_type() when doing a comparison * compare_datetime and compate_e_datetime in the comparator_matrix, is_nulls_eq is gone * Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong() sql/item_cmpfunc.h: greatly simplified Arg_comparator sql/item_create.cc: * fix a bug in error messages in CAST sql/item_func.cc: Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong() mention all possibitiles in switch over Item_result values, or use default: sql/item_row.h: overwrite the default cmp_type() for Item_row, as no MYSQL_TYPE_xxx value corresponds to ROW_RESULT sql/item_timefunc.cc: rewrite make_datetime to support precision argument SEC_TO_TIME is real function, not integer. many functions that returned temporal values had duplicate code in val_* methods, some of them did not have get_date() which resulted in unnecessary date->str->date conversions. Now they all are derived from Item_temporal_func and *only* provide get_date, not val* methods. many fixes to set decimals (datetime precision) correctly. sql/item_timefunc.h: SEC_TO_TIME is real function, not integer. many functions that returned temporal values had duplicate code in val_* methods, some of them did not have get_date() which resulted in unnecessary date->str->date conversions. Now they all are derived from Item_temporal_func and *only* provide get_date, not val* methods. many fixes to set decimals (datetime precision) correctly. sql/log_event.cc: replication of NOW(6) sql/log_event.h: replication of NOW(6) sql/mysql_priv.h: Lazy_string class to pass a value (string, number, time) polymorphically down the stack. make_truncated_value_warning() that uses it. sql/mysqld.cc: datetime in Arg_comparator::comparator_matrix sql/opt_range.cc: cleanup: don't disable warnings before calling save_in_field_no_warnings() sql/protocol.cc: Protocol::store(time) now takes the precision as an argument sql/protocol.h: Protocol::store(time) now takes the precision as an argument sql/rpl_rli.cc: small cleanup sql/set_var.cc: SET TIMESTAMP=double sql/set_var.h: @@TIMESTAMP is a double sql/share/errmsg.txt: precision and scale are unsigned sql/slave.cc: replication of NOW(6) sql/sp_head.cc: cleanup sql/sql_class.cc: support for NOW(6) sql/sql_class.h: support for NOW(6) sql/sql_insert.cc: support for NOW(6) sql/sql_select.cc: use item->cmp_type(). move a comment where it belongs sql/sql_show.cc: new column I_S.COLUMNS.DATETIME_PRECISION sql/sql_yacc.yy: TIME(X), DATETIME(X), cast, NOW(X), CURTIME(X), etc sql/time.cc: fix date_add_interval() to support MYSQL_TIMESTAMP_TIME argument storage/myisam/ha_myisam.cc: TIMESTAMP no longer carries ZEROFIELD flag, still we keep MYI file compatible. strings/my_vsnprintf.c: warnings tests/mysql_client_test.c: old timestamp(X) does not work anymore datetime is no longer equal to time --- include/my_sys.h | 18 ++++++++++++++---- include/my_time.h | 33 ++++++++++++++++++++++++++------- include/mysql.h.pp | 2 +- include/mysql_com.h | 2 +- 4 files changed, 42 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/my_sys.h b/include/my_sys.h index 3a240cfc118..f86b7839baf 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -894,11 +894,21 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); void my_free_open_file_info(void); -extern time_t my_time(myf flags); +typedef struct {ulonglong val;} my_hrtime_t; +typedef struct {ulonglong val;} my_timediff_t; +void my_time_init(); +extern my_hrtime_t my_hrtime(); +void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp); extern ulonglong my_getsystime(void); -extern ulonglong my_micro_time(); -extern ulonglong my_micro_time_and_time(time_t *time_arg); -time_t my_time_possible_from_micro(ulonglong microtime); + +#define my_micro_time() (my_getsystime()/10) +#define hrtime_to_time(X) ((time_t)((X).val/1000000)) +#define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) +#define hrtime_to_double(X) ((X).val/1e6) +#define hrtime_sec_part(X) ((X).val%1000000) +#define my_time(X) hrtime_to_time(my_hrtime()) +#define my_micro_and_hrtime(X,Y) my_diff_and_hrtime(X,Y) + extern my_bool my_gethwaddr(uchar *to); extern int my_getncpus(); diff --git a/include/my_time.h b/include/my_time.h index 58995f1bf62..7d059a03710 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -55,6 +55,7 @@ typedef long my_time_t; /* Flags to str_to_datetime */ #define TIME_FUZZY_DATE 1 #define TIME_DATETIME_ONLY 2 +#define TIME_TIME_ONLY 4 /* Must be same as MODE_NO_ZERO_IN_DATE */ #define TIME_NO_ZERO_IN_DATE (65536L*2*2*2*2*2*2*2) /* Must be same as MODE_NO_ZERO_DATE */ @@ -68,8 +69,9 @@ typedef long my_time_t; #define TIME_MAX_HOUR 838 #define TIME_MAX_MINUTE 59 #define TIME_MAX_SECOND 59 +#define TIME_MAX_SECOND_PART 999999 #define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \ - TIME_MAX_SECOND) + TIME_MAX_SECOND + TIME_MAX_SECOND_PART/1e6) #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) @@ -80,14 +82,15 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, uint flags, int *was_cut); longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, uint flags, int *was_cut); +int number_to_time(double nr, MYSQL_TIME *ltime, int *was_cut); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); ulonglong TIME_to_ulonglong(const MYSQL_TIME *); +double TIME_to_double(const MYSQL_TIME *my_time); - -my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time, - int *warning); +longlong pack_time(MYSQL_TIME *my_time); +MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time); int check_time_range(struct st_mysql_time *, int *warning); @@ -136,11 +139,27 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); sent using binary protocol fit in this buffer. */ #define MAX_DATE_STRING_REP_LENGTH 30 +#define MAX_SEC_PART_VALUE 999999 +#define MAX_SEC_PART_DIGITS 6 +#define AUTO_SEC_PART_DIGITS 31 /* same as NOT_FIXED_DEC */ -int my_time_to_str(const MYSQL_TIME *l_time, char *to); +int my_time_to_str(const MYSQL_TIME *l_time, char *to, int digits); int my_date_to_str(const MYSQL_TIME *l_time, char *to); -int my_datetime_to_str(const MYSQL_TIME *l_time, char *to); -int my_TIME_to_str(const MYSQL_TIME *l_time, char *to); +int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, int digits); +int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, int digits); + +static inline longlong sec_part_shift(longlong second_part, int digits) +{ + return second_part / log_10_int[MAX_SEC_PART_DIGITS - digits]; +} +static inline longlong sec_part_unshift(longlong second_part, int digits) +{ + return second_part * log_10_int[MAX_SEC_PART_DIGITS - digits]; +} +static inline ulong sec_part_truncate(ulong second_part, int digits) +{ + return second_part - second_part % log_10_int[MAX_SEC_PART_DIGITS - digits]; +} /* Available interval types used in any statement. diff --git a/include/mysql.h.pp b/include/mysql.h.pp index ceb4b2d591c..408800f55f2 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -102,7 +102,7 @@ struct rand_struct { double max_value_dbl; }; enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, - DECIMAL_RESULT}; + DECIMAL_RESULT, TIME_RESULT}; typedef struct st_udf_args { unsigned int arg_count; diff --git a/include/mysql_com.h b/include/mysql_com.h index 7d3dd3d4f34..61a50ae558c 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -439,7 +439,7 @@ struct rand_struct { /* The following is for user defined functions */ enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, - DECIMAL_RESULT}; + DECIMAL_RESULT, TIME_RESULT}; typedef struct st_udf_args { -- cgit v1.2.1 From e6bd643c7573fcbf422635e7a7440260ed30c297 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Fri, 4 Mar 2011 12:06:03 +0300 Subject: MRR interface: change range_info's type from char* to range_id_t typedef. The goals are: - cleaner code - ability to change from using pointers to offsets at some point --- include/my_base.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_base.h b/include/my_base.h index a5f18146859..c17897670ba 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -543,11 +543,13 @@ typedef struct st_key_range enum ha_rkey_function flag; } key_range; +typedef void *range_id_t; + typedef struct st_key_multi_range { key_range start_key; key_range end_key; - char *ptr; /* Free to use by caller (ptr to row etc) */ + range_id_t ptr; /* Free to use by caller (ptr to row etc) */ uint range_flag; /* key range flags see above */ } KEY_MULTI_RANGE; -- cgit v1.2.1 From 1cda2654578b82da52c29a829d463955f8795cc9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 17 Mar 2011 14:13:03 +0100 Subject: * fix for ALTER TABLE ... MODIFY timestamp->timestamp. Use dedicated do_field_temporal() for Copy_field. * check_time_range() needs to know TIME's precision to use the correct max value. --- include/my_time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_time.h b/include/my_time.h index 7d059a03710..db1795eeb6e 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -92,7 +92,7 @@ double TIME_to_double(const MYSQL_TIME *my_time); longlong pack_time(MYSQL_TIME *my_time); MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time); -int check_time_range(struct st_mysql_time *, int *warning); +int check_time_range(struct st_mysql_time *my_time, uint dec, int *warning); long calc_daynr(uint year,uint month,uint day); uint calc_days_in_year(uint year); -- cgit v1.2.1 From 8250ceced6aab95347e00e2ff1c02730da0be4fe Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 24 Mar 2011 12:30:03 +0100 Subject: Fix compilation on Windows: - Fixes for type-conversion (time_t is not interchangeable with my_time_t on Windows as time_t s 64 bit while my_time_t is long) - BIGENDIAN-> ARCH_BIGENDIAN . BIGENDIAN constant is defined in winsock2.h (as 0) - added explicit cast for longlong->double conversion in sql/item.h (fixed many warnings) Also, HAVE_SNPRINTF is now defined and snprintf is defined to _snprintf in config-win.h --- include/config-win.h | 7 +++---- include/my_sys.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/config-win.h b/include/config-win.h index da9b1fc00c3..84bc4ece959 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -293,10 +293,9 @@ inline ulonglong double2ulonglong(double d) #define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */ #endif -#ifdef NOT_USED -#define HAVE_SNPRINTF /* Gave link error */ -#define _snprintf snprintf -#endif + +#define HAVE_SNPRINTF +#define snprintf _snprintf #ifdef _MSC_VER #define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */ diff --git a/include/my_sys.h b/include/my_sys.h index f86b7839baf..0d57566d6e4 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -902,7 +902,7 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp); extern ulonglong my_getsystime(void); #define my_micro_time() (my_getsystime()/10) -#define hrtime_to_time(X) ((time_t)((X).val/1000000)) +#define hrtime_to_time(X) ((my_time_t)((X).val/1000000)) #define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) #define hrtime_to_double(X) ((X).val/1e6) #define hrtime_sec_part(X) ((X).val%1000000) -- cgit v1.2.1 From e016a2f5f00774f8126974fa26c7550bf0e60c84 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 26 Mar 2011 11:59:34 +0100 Subject: lp:705210 Compiling with BUILD/compile-pentium64-debug fails --- include/my_sys.h | 4 ++-- include/my_time.h | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/my_sys.h b/include/my_sys.h index 0d57566d6e4..ff4083b9fda 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -902,10 +902,10 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp); extern ulonglong my_getsystime(void); #define my_micro_time() (my_getsystime()/10) -#define hrtime_to_time(X) ((my_time_t)((X).val/1000000)) +#define hrtime_to_time(X) ((X).val/1000000) #define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) #define hrtime_to_double(X) ((X).val/1e6) -#define hrtime_sec_part(X) ((X).val%1000000) +#define hrtime_sec_part(X) ((ulong)((X).val%1000000)) #define my_time(X) hrtime_to_time(my_hrtime()) #define my_micro_and_hrtime(X,Y) my_diff_and_hrtime(X,Y) diff --git a/include/my_time.h b/include/my_time.h index db1795eeb6e..5ec51685489 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -158,9 +158,12 @@ static inline longlong sec_part_unshift(longlong second_part, int digits) } static inline ulong sec_part_truncate(ulong second_part, int digits) { - return second_part - second_part % log_10_int[MAX_SEC_PART_DIGITS - digits]; + /* the cast here should be unnecessary! */ + return second_part - second_part % (ulong)log_10_int[MAX_SEC_PART_DIGITS - digits]; } +#define hrtime_to_my_time(X) ((my_time_t)hrtime_to_time(X)) + /* Available interval types used in any statement. -- cgit v1.2.1 From bc9f6021ff424ff7724183bd4ad95796a3b14053 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Mar 2011 14:29:23 +0200 Subject: MWL#116: After-review fixes. --- include/my_sys.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/my_sys.h b/include/my_sys.h index 2f8a44fedc0..7333c10df35 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -554,6 +554,8 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *); #define my_b_tell(info) ((info)->pos_in_file + \ (size_t) (*(info)->current_pos - (info)->request_pos)) +#define my_b_write_tell(info) ((info)->pos_in_file + \ + ((info)->write_pos - (info)->write_buffer)) #define my_b_get_buffer_start(info) (info)->request_pos #define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end - \ -- cgit v1.2.1 From 6da8ac5f71a6501cb0fb1304ff144ec41b4d9389 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 28 Apr 2011 18:02:26 +0300 Subject: Added option "AND DISABLE CHECKPOINT" to "FLUSH TABLES WITH READ LOCK" This makes it possible to do safe multi volume snapshots as long as one snapshots the volume with the transaction logs last. include/mysql_com.h: Added REFRESH_CHECKPOINT mysql-test/r/flush.result: Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls mysql-test/t/flush.test: Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls sql/handler.cc: Added code to call checkpoint_state for all handlertons that supports it sql/handler.h: Added new checkpoint_state() handlerton call to temporarly disable checkpoints. sql/lex.h: Added CHECKPOINT keyword sql/sql_yacc.yy: Added support for FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT storage/maria/ha_maria.cc: Added handlerton call to disable checkpoints. storage/maria/ma_checkpoint.c: Don't do checkpoint if checkpoints are disabled. storage/maria/ma_static.c: Added maria_checkpoint_disabled storage/maria/maria_def.h: Added maria_checkpoint_disabled storage/xtradb/handler/ha_innodb.cc: Added handlerton call to disable checkpoints. storage/xtradb/include/log0log.h: Added option to log_checkpoint() to allow one to ignore not critical checkpoints during the time checkpoints are disabled. storage/xtradb/log/log0log.c: Added code to allow one to disable checkpoints during a FLUSH TABLES ... DISABLE CHECKPOINT This was done by adding a new argument to log_checkpoint() which tells us when the checkpoint is called by srv_master_thread (which are safe to ignore) storage/xtradb/srv/srv0srv.c: Tell log_checkpoint() that checkpoints from srv_master_thread() are safe to ignore (will just delay recovery time a bit). --- include/mysql_com.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/mysql_com.h b/include/mysql_com.h index affd24a4636..c85014a662b 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -136,6 +136,7 @@ enum enum_server_command #define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */ #define REFRESH_DES_KEY_FILE 0x40000L #define REFRESH_USER_RESOURCES 0x80000L +#define REFRESH_CHECKPOINT 0x100000L /* Don't do checkpoints */ #define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ -- cgit v1.2.1 From 5ab92b1f850c62718907d166b47553440502043c Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sun, 8 May 2011 13:24:06 +0300 Subject: Adding support for Dynamic columns (WL#34): - COLUMN_CREATE(column_nr, value, [column_nr,value]...) - COLUMN_ADD(blob,column_nr, value, column_nr,value]...) - COLUMN_DELETE(blob, column_nr, column_nr...) - COLUMN_EXISTS(blob, column_nr) - COLUMN_LIST(blob, column_nr) - COLUMN_GET(string, column_nr AS type) Added cast(X as DOUBLE) and cast(x as INT) Better warning and error messages for wrong cast's Created some sub functions to simplify and reuse code. Added a lot of conversation functions with error/warnings for what went wrong. Fixed some issues when casting time to datetime. Added functions to dynamic strings and Strings to allow one to move a string buffer from dynamic strings to String (to save malloc+ copy) Added dynamic columns library to libmysqlclient include/Makefile.am: Added ma_dyncol.h include/decimal.h: Added 'const' to arguments for some functions. include/my_sys.h: Added dynstr_reassociate() include/my_time.h: Added TIME_SUBSECOND_RANGE Added double_to_datetime() Added flag argument to str_to_time() libmysql/CMakeLists.txt: Added mysys/ma_dyncol.c libmysql/Makefile.shared: Added ma_dyncol libmysql/libmysql.c: Added argument to str_to_time() mysql-test/r/bigint.result: Better error messages mysql-test/r/cast.result: Better warning and error messages A lot of new cast() tests mysql-test/r/func_math.result: Better warning messages mysql-test/r/func_str.result: Better warning messages mysql-test/r/func_time.result: Better warning messages mysql-test/r/sp-vars.result: Better warning messages mysql-test/r/strict.result: Better warning messages New test result mysql-test/r/type_newdecimal.result: Better warning messages mysql-test/r/warnings.result: Better warning messages mysql-test/suite/funcs_1/r/innodb_func_view.result: Updated results after better cast warnings mysql-test/suite/funcs_1/r/memory_func_view.result: Updated results after better cast warnings mysql-test/suite/funcs_1/r/myisam_func_view.result: Updated results after better cast warnings mysql-test/suite/optimizer_unfixed_bugs/t/bug43448.test: Added begin...commit to speed up test. mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc: Added begin...commit to speed up test. mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc: Added begin...commit to speed up test. mysql-test/suite/parts/r/part_supported_sql_func_innodb.result: Added begin...commit to speed up test. mysql-test/suite/parts/r/part_supported_sql_func_myisam.result: Added begin...commit to speed up test. mysql-test/suite/parts/r/rpl_partition.result: Added begin...commit to speed up test. mysql-test/suite/parts/t/part_supported_sql_func_innodb.test: Removed duplicated --big_test mysql-test/suite/parts/t/rpl_partition.test: Added begin...commit to speed up test. mysql-test/suite/pbxt/r/cast.result: Updated results after better cast warnings mysql-test/suite/pbxt/r/func_str.result: Updated results after better cast warnings mysql-test/suite/pbxt/r/type_newdecimal.result: Updated results after better cast warnings mysql-test/suite/rpl/r/rpl_innodb_bug28430.result: Added begin...commit to speed up test. mysql-test/suite/rpl/t/rpl_innodb_bug28430.test: Added begin...commit to speed up test. mysql-test/suite/vcol/r/vcol_supported_sql_funcs_innodb.result: More warnings mysql-test/suite/vcol/r/vcol_supported_sql_funcs_myisam.result: More warnings mysql-test/t/cast.test: A lot of new cast() tests mysql-test/t/strict.test: Added new test mysys/CMakeLists.txt: Added ma_dyncol.c mysys/Makefile.am: Added ma_dyncol.c mysys/string.c: Added dynstr_reassociate() to move a buffer from dynamic_strings to some other allocator sql-common/my_time.c: Added 'fuzzydate' flag to str_to_time() Added support for microseconds to my_time_to_str() and my_datetime_to_str() Reset second_parts in number_to_datetime() Added double_to_datetime() sql/field.cc: Added double_to_longlong() and truncate_double() to simplify and reuse code sql/field.h: New prototypes sql/item.cc: Changed Item::get_date(MYSQL_TIME *ltime,uint fuzzydate) to be aware of type of argument. (Needed to make it microsecond safe and get better warnings). Updated call to str_to_time_with_warn() sql/item.h: Added struct st_dyncall_create_def used by dynamic columns Added virtual bool dynamic_result() to tell if type of argument may change over calls. sql/item_cmpfunc.cc: Added Item_func_dyncol_exists() sql/item_cmpfunc.h: Added class Item_func_dyncol_exists sql/item_create.cc: Added get_length_and_scale() to simplify other functions Simplified and extended create_func_cast() Added support for cast(X as double(X,Y)) Added functions to create dynamic column functions. sql/item_create.h: Added prototypes sql/item_func.cc: Extended cast functions Item_func_signed() and Item_func_unsigned() to work with dynamic types Added Item_double_typecast() sql/item_func.h: Added class Item_double_typecast() sql/item_strfunc.cc: Added functions for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST() sql/item_strfunc.h: Added classes for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST() sql/item_timefunc.cc: Added flag argument to str_to_time_with_warn() Updated Item_char_typecast() to handle result type that may change between calls (for dynamic columns) Added Item_time_typecast::get_date() to ensure that we cast a datetime to time properly. sql/item_timefunc.h: Added get_date() to Item_time_typecast() to allow proper results for casting time to datetime sql/lex.h: Added new SQL function names sql/my_decimal.cc: Added 'const' to some arguments. Better error message in case of errors (we now print out the wrong value) Added my_decimal2int() sql/my_decimal.h: Moved some constants to my_decimal_limits.h Updated prototypes. Made my_decimal2int() a function as it's rather long (no reason to have it inline) Added decimal2my_decimal() function. sql/mysql_priv.h: Prototypes for new functions sql/share/errmsg.txt: New error messages for wrong casts and dynamic columns sql/sql_acl.cc: Fixed indentation sql/sql_base.cc: Added dynamic_column_error_message() sql/sql_string.h: Added reassociate() to move a buffer to be owned by String object. sql/sql_yacc.yy: Added syntax for COLUMN_ functions. sql/time.cc: Updated str_to_datetime_with_warn() flag argument to same type as other functions Added conversion flag to str_to_time_with_warn() (Similar to all datetime functions) Added conversion functions with warnings: double_to_datetime_with_warn() and decimal_to_datetime_with_warn() strings/decimal.c: Added 'const' to arguments for some functions. unittest/mysys/Makefile.am: Added test for dynamic columns code --- include/Makefile.am | 1 + include/decimal.h | 12 ++-- include/ma_dyncol.h | 141 ++++++++++++++++++++++++++++++++++++++++++++ include/my_decimal_limits.h | 31 ++++++++++ include/my_sys.h | 2 + include/my_time.h | 5 +- 6 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 include/ma_dyncol.h create mode 100644 include/my_decimal_limits.h (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 3fbe349b9a4..bbb44389fd4 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -30,6 +30,7 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ my_getopt.h sslopt-longopts.h my_dir.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ m_ctype.h my_attribute.h my_compiler.h \ + my_decimal_limits.h ma_dyncol.h \ $(HEADERS_GEN_CONFIGURE) \ $(HEADERS_GEN_MAKE) diff --git a/include/decimal.h b/include/decimal.h index 530ed9e1757..aad9db9a1b8 100644 --- a/include/decimal.h +++ b/include/decimal.h @@ -29,17 +29,17 @@ typedef struct st_decimal_t { int internal_str2dec(const char *from, decimal_t *to, char **end, my_bool fixed); -int decimal2string(decimal_t *from, char *to, int *to_len, +int decimal2string(const decimal_t *from, char *to, int *to_len, int fixed_precision, int fixed_decimals, char filler); -int decimal2ulonglong(decimal_t *from, ulonglong *to); +int decimal2ulonglong(const decimal_t *from, ulonglong *to); int ulonglong2decimal(ulonglong from, decimal_t *to); -int decimal2longlong(decimal_t *from, longlong *to); +int decimal2longlong(const decimal_t *from, longlong *to); int longlong2decimal(longlong from, decimal_t *to); -int decimal2double(decimal_t *from, double *to); +int decimal2double(const decimal_t *from, double *to); int double2decimal(double from, decimal_t *to); int decimal_actual_fraction(decimal_t *from); -int decimal2bin(decimal_t *from, uchar *to, int precision, int scale); +int decimal2bin(const decimal_t *from, uchar *to, int precision, int scale); int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale); int decimal_size(int precision, int scale); @@ -55,7 +55,7 @@ int decimal_mul(decimal_t *from1, decimal_t *from2, decimal_t *to); int decimal_div(decimal_t *from1, decimal_t *from2, decimal_t *to, int scale_incr); int decimal_mod(decimal_t *from1, decimal_t *from2, decimal_t *to); -int decimal_round(decimal_t *from, decimal_t *to, int new_scale, +int decimal_round(const decimal_t *from, decimal_t *to, int new_scale, decimal_round_mode mode); int decimal_is_zero(decimal_t *from); void max_decimal(int precision, int frac, decimal_t *to); diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h new file mode 100644 index 00000000000..23b77503a33 --- /dev/null +++ b/include/ma_dyncol.h @@ -0,0 +1,141 @@ +/* Copyright (c) 2011, Monty Program Ab + Copyright (c) 2011, Oleksandr Byelkin + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#ifndef ma_dyncol_h +#define ma_dyncol_h + +#include +#include +#include + +/* NO and OK is the same used just to show semantics */ +#define ER_DYNCOL_NO ER_DYNCOL_OK + +enum enum_dyncol_func_result +{ + ER_DYNCOL_OK= 0, + ER_DYNCOL_YES= 1, /* For functions returning 0/1 */ + ER_DYNCOL_FORMAT= -1, /* Wrong format of the encoded string */ + ER_DYNCOL_LIMIT= -2, /* Some limit reached */ + ER_DYNCOL_RESOURCE= -3, /* Out of resourses */ + ER_DYNCOL_DATA= -4, /* Incorrect input data */ + ER_DYNCOL_UNKNOWN_CHARSET= -5 /* Unknown character set */ +}; + +typedef DYNAMIC_STRING DYNAMIC_COLUMN; + +enum enum_dynamic_column_type +{ + DYN_COL_NULL= 0, + DYN_COL_INT, + DYN_COL_UINT, + DYN_COL_DOUBLE, + DYN_COL_STRING, + DYN_COL_DECIMAL, + DYN_COL_DATETIME, + DYN_COL_DATE, + DYN_COL_TIME +}; + +typedef enum enum_dynamic_column_type DYNAMIC_COLUMN_TYPE; + +struct st_dynamic_column_value +{ + DYNAMIC_COLUMN_TYPE type; + union + { + long long long_value; + unsigned long long ulong_value; + double double_value; + struct { + LEX_STRING string_value; + CHARSET_INFO *charset; + }; + struct { + decimal_digit_t decimal_buffer[DECIMAL_BUFF_LENGTH]; + decimal_t decimal_value; + }; + MYSQL_TIME time_value; + }; +}; + +typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE; + +enum enum_dyncol_func_result +dynamic_column_create(DYNAMIC_COLUMN *str, + uint column_nr, DYNAMIC_COLUMN_VALUE *value); + +enum enum_dyncol_func_result +dynamic_column_create_many(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values); + +enum enum_dyncol_func_result +dynamic_column_update(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *value); +enum enum_dyncol_func_result +dynamic_column_update_many(DYNAMIC_COLUMN *str, + uint add_column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values); + +enum enum_dyncol_func_result +dynamic_column_delete(DYNAMIC_COLUMN *org, uint column_nr); + +enum enum_dyncol_func_result +dynamic_column_exists(DYNAMIC_COLUMN *org, uint column_nr); + +/* List of not NULL columns */ +enum enum_dyncol_func_result +dynamic_column_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint); + +/* + if the column do not exists it is NULL +*/ +enum enum_dyncol_func_result +dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *store_it_here); + +#define dynamic_column_initialize(A) memset((A), 0, sizeof(*(A))) +#define dynamic_column_column_free(V) dynstr_free(V) + +/*************************************************************************** + Internal functions, don't use if you don't know what you are doing... +***************************************************************************/ + +#define dynamic_column_reassociate(V,P,L, A) dynstr_reassociate((V),(P),(L),(A)) + +#define dynamic_column_value_init(V) (V)->type= DYN_COL_NULL + +/* + Prepare value for using as decimal +*/ +void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value); + +#endif diff --git a/include/my_decimal_limits.h b/include/my_decimal_limits.h new file mode 100644 index 00000000000..d9dabe92373 --- /dev/null +++ b/include/my_decimal_limits.h @@ -0,0 +1,31 @@ +#ifndef my_decimal_limits_h +#define my_decimal_limits_h + +#define DECIMAL_LONGLONG_DIGITS 22 +#define DECIMAL_LONG_DIGITS 10 +#define DECIMAL_LONG3_DIGITS 8 + +/** maximum length of buffer in our big digits (uint32). */ +#define DECIMAL_BUFF_LENGTH 9 + +/* the number of digits that my_decimal can possibly contain */ +#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9) + + +/** + maximum guaranteed precision of number in decimal digits (number of our + digits * number of decimal digits in one our big digit - number of decimal + digits in one our big digit decreased by 1 (because we always put decimal + point on the border of our big digits)) +*/ +#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2) +#define DECIMAL_MAX_SCALE 30 +#define DECIMAL_NOT_SPECIFIED 31 + +/** + maximum length of string representation (number of maximum decimal + digits + 1 position for sign + 1 position for decimal point) +*/ +#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2) + +#endif diff --git a/include/my_sys.h b/include/my_sys.h index 65455990b04..f891ee7e065 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -863,6 +863,8 @@ extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str); extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n); extern void dynstr_free(DYNAMIC_STRING *str); +extern void dynstr_reassociate(DYNAMIC_STRING *str, char **res, size_t *length, + size_t *alloc_length); #ifdef HAVE_MLOCK extern void *my_malloc_lock(size_t length,myf flags); extern void my_free_lock(void *ptr,myf flags); diff --git a/include/my_time.h b/include/my_time.h index 58995f1bf62..5929a24be11 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -72,6 +72,7 @@ typedef long my_time_t; TIME_MAX_SECOND) #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) +#define TIME_SUBSECOND_RANGE 1000000 my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, ulong flags, int *was_cut); @@ -80,6 +81,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, uint flags, int *was_cut); longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, uint flags, int *was_cut); +my_bool double_to_datetime(double nr, MYSQL_TIME *time_res, + uint flags); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); @@ -87,7 +90,7 @@ ulonglong TIME_to_ulonglong(const MYSQL_TIME *); my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time, - int *warning); + ulong flag,int *warning); int check_time_range(struct st_mysql_time *, int *warning); -- cgit v1.2.1 From 052d1bfb1a215d927e31bbe521a7e29d5da8a384 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 11 May 2011 02:41:02 +0300 Subject: Fixed all reported bugs for dynamic columns. Bugs fixed: - Added automatic detection of unsigned arguments to COLUMN_CREATE() - If string length is not know for COLUMN_GET() use MAX_DYNAMIC_COLUMN_LENGTH instead of MAX_FIELD_BLOBLENGTH - null_value flag was not propery reset for COLUMN_LIST() and COLUMN_CREATE() which could lead to crashes later: - lp:778905 Assertion `value->year <= 9999' failed in dynamic_column_date_store - lp:778912 Assertion `field_pos < field_count' failed in Protocol_text::store in maria-5.3-mwl34 include/ma_dyncol.h: Added define for max dynamic column length. mysql-test/r/cast.result: Added test of cast big unsigned int to signed (this test case was missing) mysql-test/r/dyncol.result: Added tests from reported bugs Added testing of automatic store of signed/unsigned integers mysql-test/t/cast.test: Added test of cast big unsigned int to signed (this test case was missing) mysql-test/t/dyncol.test: Added tests from reported bugs Added testing of automatic store of signed/unsigned integers sql/item.cc: Added assert to catch cases where null_value is not set properly sql/item_strfunc.cc: Added automatic detection of unsigned arguments to COLUMN_CREATE() COLUMN_GET() returned wrong value for illegal strings which lead to assert later null_value flag was not propery reset for COLUMN_LIST() and COLUMN_CREATE() which could lead to crashes later. sql/item_strfunc.h: If string length is not know for COLUMN_GET() use MAX_DYNAMIC_COLUMN_LENGTH --- include/ma_dyncol.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h index 23b77503a33..687823a4e73 100644 --- a/include/ma_dyncol.h +++ b/include/ma_dyncol.h @@ -33,6 +33,12 @@ #include #include +/* + Max length for data in a dynamic colums. This comes from how the + how the offset are stored. +*/ +#define MAX_DYNAMIC_COLUMN_LENGTH 0X1FFFFFFFL + /* NO and OK is the same used just to show semantics */ #define ER_DYNCOL_NO ER_DYNCOL_OK -- cgit v1.2.1 From 5c70f813f3d12974bf67d6ff98c0ff4b9ca71d7d Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 18 May 2011 13:36:12 +0300 Subject: Added HA_ERR_DISK_FULL handler error Original code by Zardosht Kasheff sql/handler.cc: Added HA_ERR_DISK_FULL and ENOSPC (for handler that uses normal errno). This sets 'fatal_error' to ensure that the error is logged to err file (which hopefully is on another disk...) --- include/my_base.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/my_base.h b/include/my_base.h index c17897670ba..0029d01d75e 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -446,7 +446,8 @@ enum ha_base_keytype { #define HA_ERR_ROW_NOT_VISIBLE 177 #define HA_ERR_TOO_MANY_CONCURRENT_TRXS 178 /*Too many active concurrent transactions */ #define HA_ERR_ABORTED_BY_USER 179 -#define HA_ERR_LAST 179 /* Copy of last error nr */ +#define HA_ERR_DISK_FULL 180 +#define HA_ERR_LAST 180 /* Copy of last error nr */ /* Number of different errors */ #define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1) -- cgit v1.2.1 From 1177bea2f1cd0c9f887670b65c9a403a26f07d76 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 May 2011 16:27:19 +0300 Subject: Rewritten patch of percona - switching query cache on and off, removing comments. client/mysqltest.cc: Column names. mysql-test/r/grant_cache_no_prot.result: fix of text. mysql-test/r/grant_cache_ps_prot.result: Fix of test. mysql-test/r/query_cache.result: Switching on and off query cache. mysql-test/t/query_cache.test: Switching on and off query cache. mysys/charset.c: Fix of parser. sql/handler.cc: thd added to parameters. sql/log_event.cc: thd added to parameters. sql/log_event_old.cc: thd added to parameters. sql/mysql_priv.h: Fixed functions definitions. sql/mysqld.cc: Comments stripping. sql/set_var.cc: Switching on and off query cache. sql/set_var.h: Switching on and off query cache. sql/share/errmsg.txt: New errors. sql/sql_cache.cc: Switching query cache on and off, removing comments. sql/sql_cache.h: thd added to parameters. sql/sql_class.h: Comments stripping. sql/sql_db.cc: thd added to parameters. sql/sql_lex.cc: lex fixed. sql/sql_parse.cc: thd added to parameters. --- include/m_ctype.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/m_ctype.h b/include/m_ctype.h index fa7b1f6f00c..696a1a83c7f 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -148,7 +148,8 @@ enum my_lex_states MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR, MY_LEX_IDENT_OR_KEYWORD, MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN, MY_LEX_IDENT_OR_NCHAR, - MY_LEX_STRING_OR_DELIMITER + MY_LEX_STRING_OR_DELIMITER, MY_LEX_MINUS_OR_COMMENT, MY_LEX_PLACEHOLDER, + MY_LEX_COMMA }; struct charset_info_st; -- cgit v1.2.1 From 8ddcd0cda8e6e90a58e9ea64f0f3773ea0037f0b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 19 May 2011 19:01:46 +0200 Subject: post-review changes 1 include/my_time.h: remove duplicate defines. cast to ulonglong to avoid overflow sql/field.cc: perform sign extension when reading packed TIME values sql/item_cmpfunc.cc: when converting a string to a date for the purpose of comparing it with another date, we should ignore strict sql mode. sql/item_timefunc.cc: better error message sql/item_timefunc.h: limit decimals appropriately sql/share/errmsg.txt: don't refer to an object as a "column" in error messages that are used not only for columns. --- include/my_sys.h | 3 ++- include/my_time.h | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/my_sys.h b/include/my_sys.h index ff4083b9fda..96754d2e85d 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -894,6 +894,7 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); void my_free_open_file_info(void); +#define HRTIME_RESOLUTION 1000000 typedef struct {ulonglong val;} my_hrtime_t; typedef struct {ulonglong val;} my_timediff_t; void my_time_init(); @@ -904,7 +905,7 @@ extern ulonglong my_getsystime(void); #define my_micro_time() (my_getsystime()/10) #define hrtime_to_time(X) ((X).val/1000000) #define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) -#define hrtime_to_double(X) ((X).val/1e6) +#define hrtime_to_double(X) ((X).val/(double)HRTIME_RESOLUTION) #define hrtime_sec_part(X) ((ulong)((X).val%1000000)) #define my_time(X) hrtime_to_time(my_hrtime()) #define my_micro_and_hrtime(X,Y) my_diff_and_hrtime(X,Y) diff --git a/include/my_time.h b/include/my_time.h index 5ec51685489..9fcff24918b 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -70,8 +70,10 @@ typedef long my_time_t; #define TIME_MAX_MINUTE 59 #define TIME_MAX_SECOND 59 #define TIME_MAX_SECOND_PART 999999 +#define TIME_SECOND_PART_FACTOR (TIME_MAX_SECOND_PART+1) +#define TIME_SECOND_PART_DIGITS 6 #define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \ - TIME_MAX_SECOND + TIME_MAX_SECOND_PART/1e6) + TIME_MAX_SECOND + TIME_MAX_SECOND_PART/(double)TIME_SECOND_PART_FACTOR) #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) @@ -139,8 +141,6 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); sent using binary protocol fit in this buffer. */ #define MAX_DATE_STRING_REP_LENGTH 30 -#define MAX_SEC_PART_VALUE 999999 -#define MAX_SEC_PART_DIGITS 6 #define AUTO_SEC_PART_DIGITS 31 /* same as NOT_FIXED_DEC */ int my_time_to_str(const MYSQL_TIME *l_time, char *to, int digits); @@ -150,16 +150,16 @@ int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, int digits); static inline longlong sec_part_shift(longlong second_part, int digits) { - return second_part / log_10_int[MAX_SEC_PART_DIGITS - digits]; + return second_part / (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; } static inline longlong sec_part_unshift(longlong second_part, int digits) { - return second_part * log_10_int[MAX_SEC_PART_DIGITS - digits]; + return second_part * (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; } static inline ulong sec_part_truncate(ulong second_part, int digits) { /* the cast here should be unnecessary! */ - return second_part - second_part % (ulong)log_10_int[MAX_SEC_PART_DIGITS - digits]; + return second_part - second_part % (ulong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; } #define hrtime_to_my_time(X) ((my_time_t)hrtime_to_time(X)) -- cgit v1.2.1 From 03b33425e5a3de3fad070aa21e7fc7baf8104c81 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 19 May 2011 19:05:35 +0200 Subject: many changes to my_getsystime.c: * my_getsystime() is only an interval timer. Its value can beused for calculating time intervals. * renamed my_getsystime() to my_interval_timer(), to make the semantics clearer and let the compiler catch wrong usages of my_getsystime() (also future ones, that may come in merges). * increased its granularity from 100ns to 1ns, old value was for UUID, but as UUID can no longer use it directly there is no need to downgrade the OS provided value * fixed the UUID code to anchor the my_interval_timer() on the epoch, as required by the UUID standard. That is, this was only needed by UUID, and now I've moved it to UUID code from my_getsystime(). * fixed other wrong usages of my_getsystime() - e.g. in calculating times for pthread_cond_timedwait. It was buggy and could've caused long waits if OS clock would be changed. --- include/my_pthread.h | 12 ++++++------ include/my_sys.h | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/my_pthread.h b/include/my_pthread.h index a7e4ea25064..a2476d4265c 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -426,9 +426,9 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex); #ifndef set_timespec_nsec #define set_timespec_nsec(ABSTIME,NSEC) \ { \ - ulonglong now= my_getsystime() + (NSEC/100); \ - (ABSTIME).ts_sec= (now / ULL(10000000)); \ - (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \ + ulonglong now= my_hrtime().val*1000 + (NSEC); \ + (ABSTIME).ts_sec= now / 1000000000ULL; \ + (ABSTIME).ts_nsec= now % 1000000000ULL; \ } #endif /* !set_timespec_nsec */ #else @@ -444,9 +444,9 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex); #ifndef set_timespec_nsec #define set_timespec_nsec(ABSTIME,NSEC) \ {\ - ulonglong now= my_getsystime() + (NSEC/100); \ - (ABSTIME).tv_sec= (time_t) (now / ULL(10000000)); \ - (ABSTIME).tv_nsec= (long) (now % ULL(10000000) * 100 + ((NSEC) % 100)); \ + ulonglong now= my_hrtime().val*1000 + (NSEC); \ + (ABSTIME).tv_sec= (time_t) (now / 1000000000ULL); \ + (ABSTIME).tv_nsec= (long) (now % 1000000000ULL); \ } #endif /* !set_timespec_nsec */ #endif /* HAVE_TIMESPEC_TS_SEC */ diff --git a/include/my_sys.h b/include/my_sys.h index 96754d2e85d..48370ea7c38 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -894,21 +894,18 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); void my_free_open_file_info(void); -#define HRTIME_RESOLUTION 1000000 +#define HRTIME_RESOLUTION 1000000 /* microseconds */ typedef struct {ulonglong val;} my_hrtime_t; -typedef struct {ulonglong val;} my_timediff_t; void my_time_init(); extern my_hrtime_t my_hrtime(); -void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp); -extern ulonglong my_getsystime(void); +extern ulonglong my_interval_timer(void); -#define my_micro_time() (my_getsystime()/10) +#define microsecond_interval_timer() (my_interval_timer()/1000) #define hrtime_to_time(X) ((X).val/1000000) #define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) #define hrtime_to_double(X) ((X).val/(double)HRTIME_RESOLUTION) #define hrtime_sec_part(X) ((ulong)((X).val%1000000)) #define my_time(X) hrtime_to_time(my_hrtime()) -#define my_micro_and_hrtime(X,Y) my_diff_and_hrtime(X,Y) extern my_bool my_gethwaddr(uchar *to); extern int my_getncpus(); -- cgit v1.2.1 From f06cac336ba7a27493fc753d2bf37e87137a1cdc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 19 May 2011 19:16:17 +0200 Subject: post review changes 2 sql/event_parse_data.cc: don't use "not_used" variable sql/item_timefunc.cc: Item_temporal_func::fix_length_and_dec() and other changes sql/item_timefunc.h: introducing Item_timefunc::fix_length_and_dec() sql/share/errmsg.txt: don't say "column X" in the error message that used not only for columns --- include/my_time.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/my_time.h b/include/my_time.h index 9fcff24918b..8ebca27e88d 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -80,6 +80,8 @@ typedef long my_time_t; my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, ulong flags, int *was_cut); enum enum_mysql_timestamp_type +str_to_time(const char *str, uint length, MYSQL_TIME *l_time, int *warning); +enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, uint flags, int *was_cut); longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, -- cgit v1.2.1 From 8767540a43b28c977714e2f35aadcfd1bcefef5f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 19 May 2011 19:19:44 +0200 Subject: microseconds in log tables: TIMESTAMP -> TIMESTAMP(6) TIME -> TIME(6) in general_log and slow_log tables. include/my_sys.h: use constants --- include/my_sys.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/my_sys.h b/include/my_sys.h index 48370ea7c38..1b8da17006f 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -894,17 +894,17 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); void my_free_open_file_info(void); -#define HRTIME_RESOLUTION 1000000 /* microseconds */ +#define HRTIME_RESOLUTION 1000000ULL /* microseconds */ typedef struct {ulonglong val;} my_hrtime_t; void my_time_init(); extern my_hrtime_t my_hrtime(); extern ulonglong my_interval_timer(void); #define microsecond_interval_timer() (my_interval_timer()/1000) -#define hrtime_to_time(X) ((X).val/1000000) -#define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) +#define hrtime_to_time(X) ((X).val/HRTIME_RESOLUTION) +#define hrtime_from_time(X) ((ulonglong)((X)*HRTIME_RESOLUTION)) #define hrtime_to_double(X) ((X).val/(double)HRTIME_RESOLUTION) -#define hrtime_sec_part(X) ((ulong)((X).val%1000000)) +#define hrtime_sec_part(X) ((ulong)((X).val % HRTIME_RESOLUTION)) #define my_time(X) hrtime_to_time(my_hrtime()) extern my_bool my_gethwaddr(uchar *to); -- cgit v1.2.1 From b519f2b626ebd1f3243a21dc883cefa6a26460f9 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sat, 28 May 2011 16:57:58 +0200 Subject: Fix compile errors and warnings and test errors introduced by microseconds push. Also, change windows timespec definition to be Unix-ish - simplifies handling a lot. --- include/my_pthread.h | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'include') diff --git a/include/my_pthread.h b/include/my_pthread.h index e280146c34f..139e5d08437 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -75,37 +75,11 @@ typedef volatile LONG my_pthread_once_t; #define MY_PTHREAD_ONCE_INPROGRESS 1 #define MY_PTHREAD_ONCE_DONE 2 -/* - Struct and macros to be used in combination with the - windows implementation of pthread_cond_timedwait -*/ - -/* - Declare a union to make sure FILETIME is properly aligned - so it can be used directly as a 64 bit value. The value - stored is in 100ns units. - */ -union ft64 { - FILETIME ft; - __int64 i64; -}; - struct timespec { - union ft64 tv; - /* The max timeout value in millisecond for pthread_cond_timedwait */ - long max_timeout_msec; + time_t tv_sec; + long tv_nsec; }; -#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \ - (ABSTIME).tv.i64= (TIME)+(__int64)(NSEC)/100; \ - (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ -} while(0) - -#define set_timespec_nsec(ABSTIME,NSEC) do { \ - union ft64 tv; \ - GetSystemTimeAsFileTime(&tv.ft); \ - set_timespec_time_nsec((ABSTIME), tv.i64, (NSEC)); \ -} while(0) void win_pthread_init(void); int win_pthread_setspecific(void *A,void *B,uint length); -- cgit v1.2.1 From 4d128777dde904c5f0adab9b093e854c9c580d41 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 6 Jun 2011 20:28:15 +0200 Subject: revert a suggested "optimization" that introduced a bug compilation error in mysys/my_getsystime.c fixed some redundant code removed sec_to_time, time_to_sec, from_unixtime, unix_timestamp, @@timestamp now use decimal, not double for numbers with a fractional part. purge_master_logs_before_date() fixed many bugs in corner cases fixed mysys/my_getsystime.c: compilation failure fixed sql/sql_parse.cc: don't cut corners. it backfires. --- include/my_time.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/my_time.h b/include/my_time.h index 8ebca27e88d..79742d5e283 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -47,7 +47,7 @@ typedef long my_time_t; #define TIMESTAMP_MAX_YEAR 2038 #define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1) #define TIMESTAMP_MAX_VALUE INT_MAX32 -#define TIMESTAMP_MIN_VALUE 1 +#define TIMESTAMP_MIN_VALUE 0 /* two-digit years < this are 20..; >= this are 19.. */ #define YY_PART_YEAR 70 @@ -72,8 +72,7 @@ typedef long my_time_t; #define TIME_MAX_SECOND_PART 999999 #define TIME_SECOND_PART_FACTOR (TIME_MAX_SECOND_PART+1) #define TIME_SECOND_PART_DIGITS 6 -#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \ - TIME_MAX_SECOND + TIME_MAX_SECOND_PART/(double)TIME_SECOND_PART_FACTOR) +#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + TIME_MAX_SECOND) #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) @@ -84,9 +83,10 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, int *warning); enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, uint flags, int *was_cut); -longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, +longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, uint flags, int *was_cut); -int number_to_time(double nr, MYSQL_TIME *ltime, int *was_cut); +int number_to_time(my_bool neg, longlong nr, ulong sec_part, + MYSQL_TIME *ltime, int *was_cut); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); @@ -129,8 +129,7 @@ static inline my_bool validate_timestamp_range(const MYSQL_TIME *t) } my_time_t -my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, - my_bool *in_dst_time_gap); +my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, uint *error_code); void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); -- cgit v1.2.1 From f1a5c49c4e9cee40d884193dd7477aff0cbffc53 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 10 Jun 2011 15:42:55 +0200 Subject: various fixes for buildbot failures --- include/my_time.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/my_time.h b/include/my_time.h index 8e5742f7603..c71ac4ace17 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -99,6 +99,17 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ulong flags, int *was_cut); longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, uint flags, int *was_cut); + +static inline +longlong double_to_datetime(double nr, MYSQL_TIME *ltime, uint flags, int *cut) +{ + if (nr < 0 || nr > LONGLONG_MAX) + nr= (double)LONGLONG_MAX; + return number_to_datetime((longlong) floor(nr), + (ulong)((nr-floor(nr))*TIME_SECOND_PART_FACTOR), + ltime, flags, cut); +} + int number_to_time(my_bool neg, longlong nr, ulong sec_part, MYSQL_TIME *ltime, int *was_cut); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); -- cgit v1.2.1 From 4171483b539555f50336d4304d931ef743cf7011 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sun, 12 Jun 2011 15:52:07 +0200 Subject: Backport Fix for Bug#24509 - 2048 file descriptor limit on windows needs increasing. The patch replaces the use of the POSIX I/O interfaces in mysys on Windows with the Win32 API calls (CreateFile, WriteFile, etc). The Windows HANDLE for the open file is stored in the my_file_info struct, along with a flag for append mode (because the Windows API does not support opening files in append mode in all cases) The default max open files has been increased to 16384 and can be increased further by setting --max-open-files= during the server start. Noteworthy benefit of this patch is that it removes limits from the table_cache size - allowing for more simultaneus users --- include/config-win.h | 3 +-- include/my_dir.h | 4 ++++ include/my_global.h | 41 +++++++++++++++++++++++++++++++++++++---- include/my_sys.h | 23 ++++++++++++++++------- 4 files changed, 58 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/config-win.h b/include/config-win.h index 6d12bb0e33f..3fd2c6c3a43 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -66,7 +66,6 @@ #endif /* File and lock constants */ -#define O_SHARE 0x1000 /* Open file in sharing mode */ #ifdef __BORLANDC__ #define F_RDLCK LK_NBLCK /* read lock */ #define F_WRLCK LK_NBRLCK /* write lock */ @@ -374,7 +373,7 @@ inline ulonglong double2ulonglong(double d) #define FN_DEVCHAR ':' #define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */ #define FN_NO_CASE_SENCE /* Files are not case-sensitive */ -#define OS_FILE_LIMIT 2048 +#define OS_FILE_LIMIT UINT_MAX #define DO_NOT_REMOVE_THREAD_WRAPPERS #define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V)) diff --git a/include/my_dir.h b/include/my_dir.h index 06509a3af19..90d708ac811 100644 --- a/include/my_dir.h +++ b/include/my_dir.h @@ -69,7 +69,11 @@ typedef struct my_stat #else +#if(_MSC_VER) +#define MY_STAT struct _stati64 /* 64 bit file size */ +#else #define MY_STAT struct stat /* Orginal struct have what we need */ +#endif #endif /* USE_MY_STAT_STRUCT */ diff --git a/include/my_global.h b/include/my_global.h index 8b71410dbf0..60c53ac937c 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -784,7 +784,41 @@ typedef SOCKET_SIZE_TYPE size_socket; #define FN_DIRSEP "/" /* Valid directory separators */ #define FN_ROOTDIR "/" #endif -#define MY_NFILE 64 /* This is only used to save filenames */ + +/* + MY_FILE_MIN is Windows speciality and is used to quickly detect + the mismatch of CRT and mysys file IO usage on Windows at runtime. + CRT file descriptors can be in the range 0-2047, whereas descriptors returned + by my_open() will start with 2048. If a file descriptor with value less then + MY_FILE_MIN is passed to mysys IO function, chances are it stemms from + open()/fileno() and not my_open()/my_fileno. + + For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN + is logically 0. +*/ + +#ifdef _WIN32 +#define MY_FILE_MIN 2048 +#else +#define MY_FILE_MIN 0 +#endif + +/* + MY_NFILE is the default size of my_file_info array. + + It is larger on Windows, because it all file handles are stored in my_file_info + Default size is 16384 and this should be enough for most cases.If it is not + enough, --max-open-files with larger value can be used. + + For Posix , my_file_info array is only used to store filenames for + error reporting and its size is not a limitation for number of open files. +*/ +#ifdef _WIN32 +#define MY_NFILE (16384 + MY_FILE_MIN) +#else +#define MY_NFILE 64 +#endif + #ifndef OS_FILE_LIMIT #define OS_FILE_LIMIT UINT_MAX #endif @@ -821,9 +855,8 @@ typedef SOCKET_SIZE_TYPE size_socket; /* Some things that this system doesn't have */ #define NO_HASH /* Not needed anymore */ -#ifdef __WIN__ -#define NO_DIR_LIBRARY /* Not standar dir-library */ -#define USE_MY_STAT_STRUCT /* For my_lib */ +#ifdef _WIN32 +#define NO_DIR_LIBRARY /* Not standard dir-library */ #endif /* Some defines of functions for portability */ diff --git a/include/my_sys.h b/include/my_sys.h index d391492983d..3368236694d 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -342,11 +342,12 @@ enum file_type struct st_my_file_info { - char * name; - enum file_type type; -#if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_t mutex; + char *name; +#ifdef _WIN32 + HANDLE fhandle; /* win32 file handle */ + int oflag; /* open flags, e.g O_APPEND */ #endif + enum file_type type; }; extern struct st_my_file_info *my_file_info; @@ -650,12 +651,12 @@ extern void *my_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen); -#ifdef __WIN__ -extern int my_access(const char *path, int amode); -extern File my_sopen(const char *path, int oflag, int shflag, int pmode); +#ifdef _WIN32 +extern int my_access(const char *path, int amode); #else #define my_access access #endif + extern int check_if_legal_filename(const char *path); extern int check_if_legal_tablename(const char *path); @@ -666,6 +667,13 @@ extern int nt_share_delete(const char *name,myf MyFlags); #define my_delete_allow_opened(fname,flags) my_delete((fname),(flags)) #endif +#ifdef _WIN32 +/* Windows-only functions (CRT equivalents)*/ +extern File my_sopen(const char *path, int oflag, int shflag, int pmode); +extern HANDLE my_get_osfhandle(File fd); +extern void my_osmaperr(unsigned long last_error); +#endif + #ifndef TERMINATE extern void TERMINATE(FILE *file, uint flag); #endif @@ -675,6 +683,7 @@ extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags); extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags); extern FILE *my_freopen(const char *path, const char *mode, FILE *stream); extern int my_fclose(FILE *fd,myf MyFlags); +extern File my_fileno(FILE *fd); extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags); extern int my_chmod(const char *name, mode_t mode, myf my_flags); extern int my_sync(File fd, myf my_flags); -- cgit v1.2.1 From fe054adfcaecbd891da802517826a951bb4ca377 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sun, 12 Jun 2011 16:09:28 +0200 Subject: Backport fix for MySQL bug #56405 : use native windows condition variables and rwlocks in mysys, if Windows supports it. --- include/my_pthread.h | 78 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/my_pthread.h b/include/my_pthread.h index fffb883912a..aa9eb8fc807 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -48,19 +48,30 @@ typedef struct st_pthread_link { struct st_pthread_link *next; } pthread_link; -typedef struct { - uint32 waiting; - CRITICAL_SECTION lock_waiting; - - enum { - SIGNAL= 0, - BROADCAST= 1, - MAX_EVENTS= 2 - } EVENTS; - - HANDLE events[MAX_EVENTS]; - HANDLE broadcast_block_event; - +/** + Implementation of Windows condition variables. + We use native conditions on Vista and later, and fallback to own + implementation on earlier OS version. +*/ +typedef union +{ + /* Native condition (used on Vista and later) */ + CONDITION_VARIABLE native_cond; + + /* Own implementation (used on XP) */ + struct + { + uint32 waiting; + CRITICAL_SECTION lock_waiting; + enum + { + SIGNAL= 0, + BROADCAST= 1, + MAX_EVENTS= 2 + } EVENTS; + HANDLE events[MAX_EVENTS]; + HANDLE broadcast_block_event; + }; } pthread_cond_t; @@ -632,6 +643,45 @@ int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp); #endif #define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0) #else +#ifdef _WIN32 +/** + Implementation of Windows rwlock. + + We use native (slim) rwlocks on Win7 and later, and fallback to portable + implementation on earlier Windows. + + slim rwlock are also available on Vista/WS2008, but we do not use it + ("trylock" APIs are missing on Vista) +*/ +typedef union +{ + /* Native rwlock (is_srwlock == TRUE) */ + struct + { + SRWLOCK srwlock; /* native reader writer lock */ + BOOL have_exclusive_srwlock; /* used for unlock */ + }; + + /* + Portable implementation (is_srwlock == FALSE) + Fields are identical with Unix my_rw_lock_t fields. + */ + struct + { + pthread_mutex_t lock; /* lock for structure */ + pthread_cond_t readers; /* waiting readers */ + pthread_cond_t writers; /* waiting writers */ + int state; /* -1:writer,0:free,>0:readers */ + int waiters; /* number of waiting writers */ +#ifdef SAFE_MUTEX + pthread_t write_thread; +#endif + }; +} my_rw_lock_t; + + +#else /* _WIN32 */ + /* Use our own version of read/write locks */ typedef struct _my_rw_lock_t { pthread_mutex_t lock; /* lock for structure */ @@ -641,6 +691,8 @@ typedef struct _my_rw_lock_t { int waiters; /* number of waiting writers */ } my_rw_lock_t; +#endif /* _WIN32 */ + #define rw_lock_t my_rw_lock_t #define rw_rdlock(A) my_rw_rdlock((A)) #define rw_wrlock(A) my_rw_wrlock((A)) -- cgit v1.2.1 From 3c78bfe7f1a1530daea83f5dae091bd654ea6d37 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 1 Jul 2011 15:08:30 +0300 Subject: Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting --- include/Makefile.am | 1 + include/myisamchk.h | 5 ++ include/mysql.h | 3 +- include/mysql.h.pp | 3 +- include/mysql/plugin.h | 7 +-- include/mysql/plugin_auth.h.pp | 23 ++++++++- include/mysql/service_progress_report.h | 82 +++++++++++++++++++++++++++++++++ include/mysql/services.h | 1 + include/mysql_com.h | 2 + include/service_versions.h | 1 + include/sql_common.h | 6 +++ 11 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 include/mysql/service_progress_report.h (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 99a21d686a3..2607afb938e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -22,6 +22,7 @@ HEADERS_ABI = mysql.h mysql_com.h mysql_time.h \ my_list.h my_alloc.h typelib.h mysql/plugin.h pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ my_xml.h mysql_embed.h mysql/services.h \ + mysql/service_progress_report.h mysql/service_my_snprintf.h mysql/service_thd_alloc.h \ my_pthread.h my_no_pthread.h \ mysql/plugin_auth.h mysql/client_plugin.h \ diff --git a/include/myisamchk.h b/include/myisamchk.h index 7d7100bdd71..48e4a8d1b9c 100644 --- a/include/myisamchk.h +++ b/include/myisamchk.h @@ -155,6 +155,11 @@ typedef struct st_handler_check_param char temp_filename[FN_REFLEN]; IO_CACHE read_cache; enum_handler_stats_method stats_method; + /* For reporting progress */ + uint stage, max_stage; + uint progress_counter; /* How often to call _report_progress() */ + ulonglong progress, max_progress; + #ifdef THREAD pthread_mutex_t print_msg_mutex; my_bool need_print_msg_lock; diff --git a/include/mysql.h b/include/mysql.h index 19aab89283b..2e412468bbe 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -169,7 +169,8 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, + MYSQL_PROGRESS_CALLBACK }; /** diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 7b29c1f2ce9..2ad38bbf82e 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -258,7 +258,8 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, + MYSQL_PROGRESS_CALLBACK }; struct st_mysql_options_extention; struct st_mysql_options { diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index 77d141d5282..4437f5e94ef 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -1,4 +1,5 @@ /* Copyright (C) 2005 MySQL AB, 2009 Sun Microsystems, Inc. + Copyright (C) 2009-2011 Monty Program 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 @@ -60,7 +61,7 @@ typedef struct st_mysql_xid MYSQL_XID; /* MySQL plugin interface version */ #define MYSQL_PLUGIN_INTERFACE_VERSION 0x0101 /* MariaDB plugin interface version */ -#define MARIA_PLUGIN_INTERFACE_VERSION 0x0100 +#define MARIA_PLUGIN_INTERFACE_VERSION 0x0101 /* The allowable types of plugins @@ -747,10 +748,6 @@ char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length, /* Increments the row counter, see THD::row_count */ void thd_inc_row_count(MYSQL_THD thd); -#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__) -const char *set_thd_proc_info(MYSQL_THD, const char * info, const char *func, - const char *file, const unsigned int line); - /** Create a temporary file. diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index b0d5daf4c64..e4878d28f94 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -31,6 +31,27 @@ void *thd_memdup(void* thd, const void* str, unsigned int size); MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, const char *str, unsigned int size, int allocate_lex_string); +#include +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); struct st_mysql_xid { long formatID; long gtrid_length; @@ -166,8 +187,6 @@ int thd_tx_isolation(const void* thd); char *thd_security_context(void* thd, char *buffer, unsigned int length, unsigned int max_query_len); void thd_inc_row_count(void* thd); -const char *set_thd_proc_info(void*, const char * info, const char *func, - const char *file, const unsigned int line); int mysql_tmpfile(const char *prefix); int thd_killed(const void* thd); unsigned long thd_get_thread_id(const void* thd); diff --git a/include/mysql/service_progress_report.h b/include/mysql/service_progress_report.h new file mode 100644 index 00000000000..670b1c37630 --- /dev/null +++ b/include/mysql/service_progress_report.h @@ -0,0 +1,82 @@ +#ifndef MYSQL_SERVICE_PROGRESS_REPORT_INCLUDED +/* Copyright (C) 2011 Monty Program 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 */ + +/** + @file + This service allows plugins to report progress of long running operations + to the server. The progress report is visible in SHOW PROCESSLIST, + INFORMATION_SCHEMA.PROCESSLIST, and is sent to the client + if requested. + + The functions are documented at + http://kb.askmonty.org/en/progress-reporting#how-to-add-support-for-progress-reporting-to-a-storage-engine +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, \ + __func__, __FILE__, __LINE__) + +extern struct progress_report_service_st { + void (*thd_progress_init_func)(MYSQL_THD thd, unsigned int max_stage); + void (*thd_progress_report_func)(MYSQL_THD thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(MYSQL_THD thd); + void (*thd_progress_end_func)(MYSQL_THD thd); + const char *(*set_thd_proc_info_func)(MYSQL_THD, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define thd_progress_init(thd,max_stage) (progress_report_service->thd_progress_init_func((thd),(max_stage))) +#define thd_progress_report(thd, progress, max_progress) (progress_report_service->thd_progress_report_func((thd), (progress), (max_progress))) +#define thd_progress_next_stage(thd) (progress_report_service->thd_progress_next_stage_func(thd)) +#define thd_progress_end(thd) (progress_report_service->thd_progress_end_func(thd)) +#define set_thd_proc_info(thd,info,func,file,line) (progress_report_service->set_thd_proc_info_func((thd),(info),(func),(file),(line))) + +#else + +/** + Report progress for long running operations + + @param thd User thread connection handle + @param progress Where we are now + @param max_progress Progress will continue up to this +*/ +void thd_progress_init(MYSQL_THD thd, unsigned int max_stage); +void thd_progress_report(MYSQL_THD thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(MYSQL_THD thd); +void thd_progress_end(MYSQL_THD thd); +const char *set_thd_proc_info(MYSQL_THD, const char * info, const char *func, + const char *file, unsigned int line); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_PROGRESS_REPORT_INCLUDED +#endif + diff --git a/include/mysql/services.h b/include/mysql/services.h index 19003e66b96..b8cdfc3510d 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -20,6 +20,7 @@ extern "C" { #include #include +#include #ifdef __cplusplus } diff --git a/include/mysql_com.h b/include/mysql_com.h index 96d9afce5e6..119676df5ce 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -158,6 +158,7 @@ enum enum_server_command #define CLIENT_MULTI_RESULTS (1UL << 17) /* Enable/disable multi-results */ #define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */ +#define CLIENT_PROGRESS (1UL << 29) /* Client support progress indicator */ #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) #define CLIENT_REMEMBER_OPTIONS (1UL << 31) @@ -189,6 +190,7 @@ enum enum_server_command CLIENT_MULTI_RESULTS | \ CLIENT_SSL_VERIFY_SERVER_CERT | \ CLIENT_REMEMBER_OPTIONS | \ + CLIENT_PROGRESS | \ CLIENT_PLUGIN_AUTH) /* diff --git a/include/service_versions.h b/include/service_versions.h index 114957cdd86..6f06b609e61 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -21,4 +21,5 @@ #define VERSION_my_snprintf 0x0100 #define VERSION_thd_alloc 0x0100 +#define VERSION_progress_report 0x0100 diff --git a/include/sql_common.h b/include/sql_common.h index 6b66ae2fd81..20e06275653 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -29,6 +29,12 @@ extern const char *not_error_sqlstate; struct st_mysql_options_extention { char *plugin_dir; char *default_auth; + void (*report_progress)(const MYSQL *mysql, + unsigned int stage, + unsigned int max_stage, + double progress, + const char *proc_info, + uint proc_info_length); }; typedef struct st_mysql_methods -- cgit v1.2.1 From ec3c26a515ba5f52db28cfb06deba664fc61b7b5 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sat, 2 Jul 2011 17:37:59 +0300 Subject: Fixed compilation & test issues found by buildbot include/Makefile.am: Added missing \ mysql-test/mysql-test-run.pl: Suppress warning when ha_archive is not compiled mysql-test/r/variables-big.result: Updated results --- include/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 2607afb938e..afc2afff115 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -22,7 +22,7 @@ HEADERS_ABI = mysql.h mysql_com.h mysql_time.h \ my_list.h my_alloc.h typelib.h mysql/plugin.h pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ my_xml.h mysql_embed.h mysql/services.h \ - mysql/service_progress_report.h + mysql/service_progress_report.h \ mysql/service_my_snprintf.h mysql/service_thd_alloc.h \ my_pthread.h my_no_pthread.h \ mysql/plugin_auth.h mysql/client_plugin.h \ -- cgit v1.2.1 From 3b393c929b2825f3737c265b8aa39b9075e3a5e5 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sun, 10 Jul 2011 12:48:13 +0200 Subject: Fix LPBUG#808233 - undefined uint in typelib.h --- include/typelib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/typelib.h b/include/typelib.h index a5ac5cc7bbf..16c719e3419 100644 --- a/include/typelib.h +++ b/include/typelib.h @@ -29,7 +29,7 @@ typedef struct st_typelib { /* Different types saved here */ extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); extern int find_type_with_warning(const char *x, TYPELIB *typelib, const char *option); -extern uint find_type_or_exit(const char *x, TYPELIB *typelib, +extern unsigned int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option); extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); -- cgit v1.2.1 From 46465327e796e6c3d9a89dcfb9ba71561fafdb05 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sun, 10 Jul 2011 13:39:37 +0200 Subject: merge --- include/mysql.h.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/mysql.h.pp b/include/mysql.h.pp index f9f38b67f96..6e71f886eba 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -224,7 +224,7 @@ typedef struct st_typelib { extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); extern int find_type_with_warning(const char *x, TYPELIB *typelib, const char *option); -extern uint find_type_or_exit(const char *x, TYPELIB *typelib, +extern unsigned int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option); extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); -- cgit v1.2.1