mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c BitKeeper/etc/ignore: added libmysqld/ha_ndbcluster_cond.cc --- added debian/defs.mk debian/control client/completion_hash.cc: Remove not needed casts client/my_readline.h: Remove some old types client/mysql.cc: Simplify types client/mysql_upgrade.c: Remove some old types Update call to dirname_part client/mysqladmin.cc: Remove some old types client/mysqlbinlog.cc: Remove some old types Change some buffers to be uchar to avoid casts client/mysqlcheck.c: Remove some old types client/mysqldump.c: Remove some old types Remove some not needed casts Change some string lengths to size_t client/mysqlimport.c: Remove some old types client/mysqlshow.c: Remove some old types client/mysqlslap.c: Remove some old types Remove some not needed casts client/mysqltest.c: Removed some old types Removed some not needed casts Updated hash-get-key function arguments Updated parameters to dirname_part() client/readline.cc: Removed some old types Removed some not needed casts Changed some string lengths to use size_t client/sql_string.cc: Removed some old types dbug/dbug.c: Removed some old types Changed some string lengths to use size_t Changed some prototypes to avoid casts extra/comp_err.c: Removed some old types extra/innochecksum.c: Removed some old types extra/my_print_defaults.c: Removed some old types extra/mysql_waitpid.c: Removed some old types extra/perror.c: Removed some old types extra/replace.c: Removed some old types Updated parameters to dirname_part() extra/resolve_stack_dump.c: Removed some old types extra/resolveip.c: Removed some old types include/config-win.h: Removed some old types include/decimal.h: Changed binary strings to be uchar* instead of char* include/ft_global.h: Removed some old types include/hash.h: Removed some old types include/heap.h: Removed some old types Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable include/keycache.h: Removed some old types include/m_ctype.h: Removed some old types Changed some string lengths to use size_t Changed character length functions to return uint unsigned char -> uchar include/m_string.h: Removed some old types Changed some string lengths to use size_t include/my_alloc.h: Changed some string lengths to use size_t include/my_base.h: Removed some old types include/my_dbug.h: Removed some old types Changed some string lengths to use size_t Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage include/my_getopt.h: Removed some old types include/my_global.h: Removed old types: my_size_t -> size_t byte -> uchar gptr -> uchar * include/my_list.h: Removed some old types include/my_nosys.h: Removed some old types include/my_pthread.h: Removed some old types include/my_sys.h: Removed some old types Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read() Changed some string lengths to use size_t my_malloc() / my_free() now uses void * Updated parameters to dirname_part() & my_uncompress() include/my_tree.h: Removed some old types include/my_trie.h: Removed some old types include/my_user.h: Changed some string lengths to use size_t include/my_vle.h: Removed some old types include/my_xml.h: Removed some old types Changed some string lengths to use size_t include/myisam.h: Removed some old types include/myisammrg.h: Removed some old types include/mysql.h: Removed some old types Changed byte streams to use uchar* instead of char* include/mysql_com.h: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts include/queues.h: Removed some old types include/sql_common.h: Removed some old types include/sslopt-longopts.h: Removed some old types include/violite.h: Removed some old types Changed some string lengths to use size_t libmysql/client_settings.h: Removed some old types libmysql/libmysql.c: Removed some old types libmysql/manager.c: Removed some old types libmysqld/emb_qcache.cc: Removed some old types libmysqld/emb_qcache.h: Removed some old types libmysqld/lib_sql.cc: Removed some old types Removed some not needed casts Changed some buffers to be uchar* to avoid casts true -> TRUE, false -> FALSE mysys/array.c: Removed some old types mysys/charset.c: Changed some string lengths to use size_t mysys/checksum.c: Include zlib to get definition for crc32 Removed some old types mysys/default.c: Removed some old types Changed some string lengths to use size_t mysys/default_modify.c: Changed some string lengths to use size_t Removed some not needed casts mysys/hash.c: Removed some old types Changed some string lengths to use size_t Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function. hash_element now takes 'ulong' as the index type (cleanup) mysys/list.c: Removed some old types mysys/mf_cache.c: Changed some string lengths to use size_t mysys/mf_dirname.c: Removed some old types Changed some string lengths to use size_t Added argument to dirname_part() to avoid calculation of length for 'to' mysys/mf_fn_ext.c: Removed some old types Updated parameters to dirname_part() mysys/mf_format.c: Removed some old types Changed some string lengths to use size_t mysys/mf_getdate.c: Removed some old types mysys/mf_iocache.c: Removed some old types Changed some string lengths to use size_t Changed calculation of 'max_length' to be done the same way in all functions mysys/mf_iocache2.c: Removed some old types Changed some string lengths to use size_t Clean up comments Removed not needed indentation mysys/mf_keycache.c: Removed some old types mysys/mf_keycaches.c: Removed some old types mysys/mf_loadpath.c: Removed some old types mysys/mf_pack.c: Removed some old types Changed some string lengths to use size_t Removed some not needed casts Removed very old VMS code Updated parameters to dirname_part() Use result of dirnam_part() to remove call to strcat() mysys/mf_path.c: Removed some old types mysys/mf_radix.c: Removed some old types mysys/mf_same.c: Removed some old types mysys/mf_sort.c: Removed some old types mysys/mf_soundex.c: Removed some old types mysys/mf_strip.c: Removed some old types mysys/mf_tempdir.c: Removed some old types mysys/mf_unixpath.c: Removed some old types mysys/mf_wfile.c: Removed some old types mysys/mulalloc.c: Removed some old types mysys/my_alloc.c: Removed some old types Changed some string lengths to use size_t Use void* as type for allocated memory area Removed some not needed casts Changed argument 'Size' to 'length' according coding guidelines mysys/my_chsize.c: Changed some buffers to be uchar* to avoid casts mysys/my_compress.c: More comments Removed some old types Changed string lengths to use size_t Changed arguments to my_uncompress() to make them easier to understand Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) Changed type of 'pack_data' argument to packfrm() to avoid casts. mysys/my_conio.c: Changed some string lengths to use size_t mysys/my_create.c: Removed some old types mysys/my_div.c: Removed some old types mysys/my_error.c: Removed some old types mysys/my_fopen.c: Removed some old types mysys/my_fstream.c: Removed some old types Changed some string lengths to use size_t writen -> written mysys/my_getopt.c: Removed some old types mysys/my_getwd.c: Removed some old types More comments mysys/my_init.c: Removed some old types mysys/my_largepage.c: Removed some old types Changed some string lengths to use size_t mysys/my_lib.c: Removed some old types mysys/my_lockmem.c: Removed some old types mysys/my_malloc.c: Removed some old types Changed malloc(), free() and related functions to use void * Changed all functions to use size_t mysys/my_memmem.c: Indentation cleanup mysys/my_once.c: Removed some old types Changed malloc(), free() and related functions to use void * mysys/my_open.c: Removed some old types mysys/my_pread.c: Removed some old types Changed all functions to use size_t Added comment for how my_pread() / my_pwrite() are supposed to work. Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. (If we ever would really need this, it should be enabled only with a flag argument) mysys/my_quick.c: Removed some old types Changed all functions to use size_t mysys/my_read.c: Removed some old types Changed all functions to use size_t mysys/my_realloc.c: Removed some old types Use void* as type for allocated memory area Changed all functions to use size_t mysys/my_static.c: Removed some old types mysys/my_static.h: Removed some old types mysys/my_vle.c: Removed some old types mysys/my_wincond.c: Removed some old types mysys/my_windac.c: Removed some old types mysys/my_write.c: Removed some old types Changed all functions to use size_t mysys/ptr_cmp.c: Removed some old types Changed all functions to use size_t mysys/queues.c: Removed some old types mysys/safemalloc.c: Removed some old types Changed malloc(), free() and related functions to use void * Changed all functions to use size_t mysys/string.c: Removed some old types Changed all functions to use size_t mysys/testhash.c: Removed some old types mysys/thr_alarm.c: Removed some old types mysys/thr_lock.c: Removed some old types mysys/tree.c: Removed some old types mysys/trie.c: Removed some old types mysys/typelib.c: Removed some old types plugin/daemon_example/daemon_example.cc: Removed some old types regex/reginit.c: Removed some old types server-tools/instance-manager/buffer.cc: Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/buffer.h: Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/commands.cc: Removed some old types Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/instance_map.cc: Removed some old types Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/instance_options.cc: Changed buffer to be of type uchar* Replaced alloc_root + strcpy() with strdup_root() server-tools/instance-manager/mysql_connection.cc: Changed buffer to be of type uchar* server-tools/instance-manager/options.cc: Removed some old types server-tools/instance-manager/parse.cc: Changed some string lengths to use size_t server-tools/instance-manager/parse.h: Removed some old types Changed some string lengths to use size_t server-tools/instance-manager/protocol.cc: Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t server-tools/instance-manager/protocol.h: Changed some string lengths to use size_t server-tools/instance-manager/user_map.cc: Removed some old types Changed some string lengths to use size_t sql/derror.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/discover.cc: Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts sql/event_data_objects.cc: Removed some old types Added missing casts for alloc() and sprintf() sql/event_db_repository.cc: Changed some buffers to be uchar* to avoid casts Added missing casts for sprintf() sql/event_queue.cc: Removed some old types sql/field.cc: Removed some old types Changed memory buffers to be uchar* Changed some string lengths to use size_t Removed a lot of casts Safety fix in Field_blob::val_decimal() to not access zero pointer sql/field.h: Removed some old types Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes). Changed some string lengths to use size_t Removed some not needed casts Changed val_xxx(xxx, new_ptr) to take const pointers sql/field_conv.cc: Removed some old types Added casts required because memory area pointers are now uchar* sql/filesort.cc: Initalize variable that was used unitialized in error conditions sql/gen_lex_hash.cc: Removed some old types Changed memory buffers to be uchar* Changed some string lengths to use size_t Removed a lot of casts Safety fix in Field_blob::val_decimal() to not access zero pointer sql/gstream.h: Added required cast sql/ha_ndbcluster.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts Added required casts Removed some not needed casts sql/ha_ndbcluster.h: Removed some old types sql/ha_ndbcluster_binlog.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake() Changed some string lengths to use size_t Added missing casts for alloc() and sprintf() sql/ha_ndbcluster_binlog.h: Removed some old types sql/ha_ndbcluster_cond.cc: Removed some old types Removed some not needed casts sql/ha_ndbcluster_cond.h: Removed some old types sql/ha_partition.cc: Removed some old types Changed prototype for change_partition() to avoid casts sql/ha_partition.h: Removed some old types sql/handler.cc: Removed some old types Changed some string lengths to use size_t sql/handler.h: Removed some old types Changed some string lengths to use size_t Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts sql/hash_filo.h: Removed some old types Changed all functions to use size_t sql/hostname.cc: Removed some old types sql/item.cc: Removed some old types Changed some string lengths to use size_t Use strmake() instead of memdup() to create a null terminated string. Updated calls to new Field() sql/item.h: Removed some old types Changed malloc(), free() and related functions to use void * Changed some buffers to be uchar* to avoid casts sql/item_cmpfunc.cc: Removed some old types Changed some buffers to be uchar* to avoid casts sql/item_cmpfunc.h: Removed some old types sql/item_create.cc: Removed some old types sql/item_func.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added test for failing alloc() in init_result_field() Remove old confusing comment Fixed compiler warning sql/item_func.h: Removed some old types sql/item_row.cc: Removed some old types sql/item_row.h: Removed some old types sql/item_strfunc.cc: Include zlib (needed becasue we call crc32) Removed some old types sql/item_strfunc.h: Removed some old types Changed some types to match new function prototypes sql/item_subselect.cc: Removed some old types sql/item_subselect.h: Removed some old types sql/item_sum.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/item_sum.h: Removed some old types sql/item_timefunc.cc: Removed some old types Changed some string lengths to use size_t sql/item_timefunc.h: Removed some old types sql/item_xmlfunc.cc: Changed some string lengths to use size_t sql/item_xmlfunc.h: Removed some old types sql/key.cc: Removed some old types Removed some not needed casts sql/lock.cc: Removed some old types Added some cast to my_multi_malloc() arguments for safety sql/log.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Changed usage of pwrite() to not assume it holds the cursor position for the file Made usage of my_read() safer sql/log_event.cc: Removed some old types Added checking of return value of malloc() in pack_info() Changed some buffers to be uchar* to avoid casts Removed some 'const' to avoid casts Added missing casts for alloc() and sprintf() Added required casts Removed some not needed casts Added some cast to my_multi_malloc() arguments for safety sql/log_event.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/log_event_old.cc: Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/log_event_old.h: Changed some buffers to be uchar* to avoid casts sql/mf_iocache.cc: Removed some old types sql/my_decimal.cc: Changed memory area to use uchar* sql/my_decimal.h: Changed memory area to use uchar* sql/mysql_priv.h: Removed some old types Changed malloc(), free() and related functions to use void * Changed some string lengths to use size_t Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow Changed some buffers to be uchar* to avoid casts sql/mysqld.cc: Removed some old types sql/net_serv.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Ensure that vio_read()/vio_write() return values are stored in a size_t variable Removed some not needed casts sql/opt_range.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/opt_range.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/opt_sum.cc: Removed some old types Removed some not needed casts sql/parse_file.cc: Removed some old types Changed some string lengths to use size_t Changed alloc_root + memcpy + set end 0 -> strmake_root() sql/parse_file.h: Removed some old types sql/partition_info.cc: Removed some old types Added missing casts for alloc() Changed some buffers to be uchar* to avoid casts sql/partition_info.h: Changed some buffers to be uchar* to avoid casts sql/protocol.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/protocol.h: Removed some old types Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/records.cc: Removed some old types sql/repl_failsafe.cc: Removed some old types Changed some string lengths to use size_t Added required casts sql/rpl_filter.cc: Removed some old types Updated hash-get-key function arguments Changed some string lengths to use size_t sql/rpl_filter.h: Changed some string lengths to use size_t sql/rpl_injector.h: Removed some old types sql/rpl_record.cc: Removed some old types Removed some not needed casts Changed some buffers to be uchar* to avoid casts sql/rpl_record.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/rpl_record_old.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/rpl_record_old.h: Removed some old types Changed some buffers to be uchar* to avoid cast sql/rpl_rli.cc: Removed some old types sql/rpl_tblmap.cc: Removed some old types sql/rpl_tblmap.h: Removed some old types sql/rpl_utility.cc: Removed some old types sql/rpl_utility.h: Removed some old types Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length sql/set_var.cc: Removed some old types Updated parameters to dirname_part() sql/set_var.h: Removed some old types sql/slave.cc: Removed some old types Changed some string lengths to use size_t sql/slave.h: Removed some old types sql/sp.cc: Removed some old types Added missing casts for printf() sql/sp.h: Removed some old types Updated hash-get-key function arguments sql/sp_cache.cc: Removed some old types Added missing casts for printf() Updated hash-get-key function arguments sql/sp_head.cc: Removed some old types Added missing casts for alloc() and printf() Added required casts Updated hash-get-key function arguments sql/sp_head.h: Removed some old types sql/sp_pcontext.cc: Removed some old types sql/sp_pcontext.h: Removed some old types sql/sql_acl.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added required casts sql/sql_analyse.cc: Changed some buffers to be uchar* to avoid casts sql/sql_analyse.h: Changed some buffers to be uchar* to avoid casts sql/sql_array.h: Removed some old types sql/sql_base.cc: Removed some old types Updated hash-get-key function arguments sql/sql_binlog.cc: Removed some old types Added missing casts for printf() sql/sql_cache.cc: Removed some old types Updated hash-get-key function arguments Removed some not needed casts Changed some string lengths to use size_t sql/sql_cache.h: Removed some old types Removed reference to not existing function cache_key() Updated hash-get-key function arguments sql/sql_class.cc: Removed some old types Updated hash-get-key function arguments Added missing casts for alloc() Updated hash-get-key function arguments Moved THD::max_row_length() to table.cc (as it's not depending on THD) Removed some not needed casts sql/sql_class.h: Removed some old types Changed malloc(), free() and related functions to use void * Removed some not needed casts Changed some string lengths to use size_t Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD sql/sql_connect.cc: Removed some old types Added required casts sql/sql_db.cc: Removed some old types Removed some not needed casts Added some cast to my_multi_malloc() arguments for safety Added missing casts for alloc() sql/sql_delete.cc: Removed some old types sql/sql_handler.cc: Removed some old types Updated hash-get-key function arguments Added some cast to my_multi_malloc() arguments for safety sql/sql_help.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_insert.cc: Removed some old types Added missing casts for alloc() and printf() sql/sql_lex.cc: Removed some old types sql/sql_lex.h: Removed some old types Removed some not needed casts sql/sql_list.h: Removed some old types Removed some not needed casts sql/sql_load.cc: Removed some old types Removed compiler warning sql/sql_manager.cc: Removed some old types sql/sql_map.cc: Removed some old types sql/sql_map.h: Removed some old types sql/sql_olap.cc: Removed some old types sql/sql_parse.cc: Removed some old types Trivial move of code lines to make things more readable Changed some string lengths to use size_t Added missing casts for alloc() sql/sql_partition.cc: Removed some old types Removed compiler warnings about not used functions Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_partition.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/sql_plugin.cc: Removed some old types Added missing casts for alloc() Updated hash-get-key function arguments sql/sql_prepare.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Added missing casts for alloc() and printf() sql-common/client.c: Removed some old types Changed some memory areas to use uchar* sql-common/my_user.c: Changed some string lengths to use size_t sql-common/pack.c: Changed some buffers to be uchar* to avoid casts sql/sql_repl.cc: Added required casts Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/sql_select.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some old types sql/sql_select.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/sql_servers.cc: Removed some old types Updated hash-get-key function arguments sql/sql_show.cc: Removed some old types Added missing casts for alloc() Removed some not needed casts sql/sql_string.cc: Removed some old types Added required casts sql/sql_table.cc: Removed some old types Removed compiler warning about not used variable Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_test.cc: Removed some old types sql/sql_trigger.cc: Removed some old types Added missing casts for alloc() sql/sql_udf.cc: Removed some old types Updated hash-get-key function arguments sql/sql_union.cc: Removed some old types sql/sql_update.cc: Removed some old types Removed some not needed casts sql/sql_view.cc: Removed some old types sql/sql_yacc.yy: Removed some old types Changed some string lengths to use size_t Added missing casts for alloc() sql/stacktrace.c: Removed some old types sql/stacktrace.h: Removed some old types sql/structs.h: Removed some old types sql/table.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts Removed setting of LEX_STRING() arguments in declaration Added required casts More function comments Moved max_row_length() here from sql_class.cc/sql_class.h sql/table.h: Removed some old types Changed some string lengths to use size_t sql/thr_malloc.cc: Use void* as type for allocated memory area Changed all functions to use size_t sql/tzfile.h: Changed some buffers to be uchar* to avoid casts sql/tztime.cc: Changed some buffers to be uchar* to avoid casts Updated hash-get-key function arguments Added missing casts for alloc() Removed some not needed casts sql/uniques.cc: Removed some old types Removed some not needed casts sql/unireg.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added missing casts for alloc() storage/archive/archive_reader.c: Removed some old types storage/archive/azio.c: Removed some old types Removed some not needed casts storage/archive/ha_archive.cc: Removed some old types Changed type for 'frmblob' in archive_discover() to match handler Updated hash-get-key function arguments Removed some not needed casts storage/archive/ha_archive.h: Removed some old types storage/blackhole/ha_blackhole.cc: Removed some old types storage/blackhole/ha_blackhole.h: Removed some old types storage/csv/ha_tina.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts storage/csv/ha_tina.h: Removed some old types Removed some not needed casts storage/csv/transparent_file.cc: Removed some old types Changed type of 'bytes_read' to be able to detect read errors Fixed indentation storage/csv/transparent_file.h: Removed some old types storage/example/ha_example.cc: Removed some old types Updated hash-get-key function arguments storage/example/ha_example.h: Removed some old types storage/federated/ha_federated.cc: Removed some old types Updated hash-get-key function arguments Removed some not needed casts storage/federated/ha_federated.h: Removed some old types storage/heap/_check.c: Changed some buffers to be uchar* to avoid casts storage/heap/_rectest.c: Removed some old types storage/heap/ha_heap.cc: Removed some old types storage/heap/ha_heap.h: Removed some old types storage/heap/heapdef.h: Removed some old types storage/heap/hp_block.c: Removed some old types Changed some string lengths to use size_t storage/heap/hp_clear.c: Removed some old types storage/heap/hp_close.c: Removed some old types storage/heap/hp_create.c: Removed some old types storage/heap/hp_delete.c: Removed some old types storage/heap/hp_hash.c: Removed some old types storage/heap/hp_info.c: Removed some old types storage/heap/hp_open.c: Removed some old types storage/heap/hp_rfirst.c: Removed some old types storage/heap/hp_rkey.c: Removed some old types storage/heap/hp_rlast.c: Removed some old types storage/heap/hp_rnext.c: Removed some old types storage/heap/hp_rprev.c: Removed some old types storage/heap/hp_rrnd.c: Removed some old types storage/heap/hp_rsame.c: Removed some old types storage/heap/hp_scan.c: Removed some old types storage/heap/hp_test1.c: Removed some old types storage/heap/hp_test2.c: Removed some old types storage/heap/hp_update.c: Removed some old types storage/heap/hp_write.c: Removed some old types Changed some string lengths to use size_t storage/innobase/handler/ha_innodb.cc: Removed some old types Updated hash-get-key function arguments Added missing casts for alloc() and printf() Removed some not needed casts storage/innobase/handler/ha_innodb.h: Removed some old types storage/myisam/ft_boolean_search.c: Removed some old types storage/myisam/ft_nlq_search.c: Removed some old types storage/myisam/ft_parser.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/ft_static.c: Removed some old types storage/myisam/ft_stopwords.c: Removed some old types storage/myisam/ft_update.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/ftdefs.h: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/fulltext.h: Removed some old types storage/myisam/ha_myisam.cc: Removed some old types storage/myisam/ha_myisam.h: Removed some old types storage/myisam/mi_cache.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/mi_check.c: Removed some old types storage/myisam/mi_checksum.c: Removed some old types storage/myisam/mi_close.c: Removed some old types storage/myisam/mi_create.c: Removed some old types storage/myisam/mi_delete.c: Removed some old types storage/myisam/mi_delete_all.c: Removed some old types storage/myisam/mi_dynrec.c: Removed some old types storage/myisam/mi_extra.c: Removed some old types storage/myisam/mi_key.c: Removed some old types storage/myisam/mi_locking.c: Removed some old types storage/myisam/mi_log.c: Removed some old types storage/myisam/mi_open.c: Removed some old types Removed some not needed casts Check argument of my_write()/my_pwrite() in functions returning int Added casting of string lengths to size_t storage/myisam/mi_packrec.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/mi_page.c: Removed some old types storage/myisam/mi_preload.c: Removed some old types storage/myisam/mi_range.c: Removed some old types storage/myisam/mi_rfirst.c: Removed some old types storage/myisam/mi_rkey.c: Removed some old types storage/myisam/mi_rlast.c: Removed some old types storage/myisam/mi_rnext.c: Removed some old types storage/myisam/mi_rnext_same.c: Removed some old types storage/myisam/mi_rprev.c: Removed some old types storage/myisam/mi_rrnd.c: Removed some old types storage/myisam/mi_rsame.c: Removed some old types storage/myisam/mi_rsamepos.c: Removed some old types storage/myisam/mi_scan.c: Removed some old types storage/myisam/mi_search.c: Removed some old types storage/myisam/mi_static.c: Removed some old types storage/myisam/mi_statrec.c: Removed some old types storage/myisam/mi_test1.c: Removed some old types storage/myisam/mi_test2.c: Removed some old types storage/myisam/mi_test3.c: Removed some old types storage/myisam/mi_unique.c: Removed some old types storage/myisam/mi_update.c: Removed some old types storage/myisam/mi_write.c: Removed some old types storage/myisam/myisam_ftdump.c: Removed some old types storage/myisam/myisamchk.c: Removed some old types storage/myisam/myisamdef.h: Removed some old types storage/myisam/myisamlog.c: Removed some old types Indentation fix storage/myisam/myisampack.c: Removed some old types storage/myisam/rt_index.c: Removed some old types storage/myisam/rt_split.c: Removed some old types storage/myisam/sort.c: Removed some old types storage/myisam/sp_defs.h: Removed some old types storage/myisam/sp_key.c: Removed some old types storage/myisammrg/ha_myisammrg.cc: Removed some old types storage/myisammrg/ha_myisammrg.h: Removed some old types storage/myisammrg/myrg_close.c: Removed some old types storage/myisammrg/myrg_def.h: Removed some old types storage/myisammrg/myrg_delete.c: Removed some old types storage/myisammrg/myrg_open.c: Removed some old types Updated parameters to dirname_part() storage/myisammrg/myrg_queue.c: Removed some old types storage/myisammrg/myrg_rfirst.c: Removed some old types storage/myisammrg/myrg_rkey.c: Removed some old types storage/myisammrg/myrg_rlast.c: Removed some old types storage/myisammrg/myrg_rnext.c: Removed some old types storage/myisammrg/myrg_rnext_same.c: Removed some old types storage/myisammrg/myrg_rprev.c: Removed some old types storage/myisammrg/myrg_rrnd.c: Removed some old types storage/myisammrg/myrg_rsame.c: Removed some old types storage/myisammrg/myrg_update.c: Removed some old types storage/myisammrg/myrg_write.c: Removed some old types storage/ndb/include/util/ndb_opts.h: Removed some old types storage/ndb/src/cw/cpcd/main.cpp: Removed some old types storage/ndb/src/kernel/vm/Configuration.cpp: Removed some old types storage/ndb/src/mgmclient/main.cpp: Removed some old types storage/ndb/src/mgmsrv/InitConfigFileParser.cpp: Removed some old types Removed old disabled code storage/ndb/src/mgmsrv/main.cpp: Removed some old types storage/ndb/src/ndbapi/NdbBlob.cpp: Removed some old types storage/ndb/src/ndbapi/NdbOperationDefine.cpp: Removed not used variable storage/ndb/src/ndbapi/NdbOperationInt.cpp: Added required casts storage/ndb/src/ndbapi/NdbScanOperation.cpp: Added required casts storage/ndb/tools/delete_all.cpp: Removed some old types storage/ndb/tools/desc.cpp: Removed some old types storage/ndb/tools/drop_index.cpp: Removed some old types storage/ndb/tools/drop_tab.cpp: Removed some old types storage/ndb/tools/listTables.cpp: Removed some old types storage/ndb/tools/ndb_config.cpp: Removed some old types storage/ndb/tools/restore/consumer_restore.cpp: Changed some buffers to be uchar* to avoid casts with new defintion of packfrm() storage/ndb/tools/restore/restore_main.cpp: Removed some old types storage/ndb/tools/select_all.cpp: Removed some old types storage/ndb/tools/select_count.cpp: Removed some old types storage/ndb/tools/waiter.cpp: Removed some old types strings/bchange.c: Changed function to use uchar * and size_t strings/bcmp.c: Changed function to use uchar * and size_t strings/bmove512.c: Changed function to use uchar * and size_t strings/bmove_upp.c: Changed function to use uchar * and size_t strings/ctype-big5.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-bin.c: Changed functions to use size_t strings/ctype-cp932.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-czech.c: Fixed indentation Changed functions to use size_t strings/ctype-euc_kr.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-eucjpms.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-gb2312.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-gbk.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-latin1.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-mb.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-simple.c: Changed functions to use size_t Simpler loops for caseup/casedown unsigned int -> uint unsigned char -> uchar strings/ctype-sjis.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-tis620.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-uca.c: Changed functions to use size_t unsigned char -> uchar strings/ctype-ucs2.c: Moved inclusion of stdarg.h to other includes usigned char -> uchar Changed functions to use size_t Changed character length functions to return uint strings/ctype-ujis.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-utf8.c: Changed functions to use size_t unsigned char -> uchar Indentation fixes strings/ctype-win1250ch.c: Indentation fixes Changed functions to use size_t strings/ctype.c: Changed functions to use size_t strings/decimal.c: Changed type for memory argument to uchar * strings/do_ctype.c: Indentation fixes strings/my_strtoll10.c: unsigned char -> uchar strings/my_vsnprintf.c: Changed functions to use size_t strings/r_strinstr.c: Removed some old types Changed functions to use size_t strings/str_test.c: Removed some old types strings/strappend.c: Changed functions to use size_t strings/strcont.c: Removed some old types strings/strfill.c: Removed some old types strings/strinstr.c: Changed functions to use size_t strings/strlen.c: Changed functions to use size_t strings/strmake.c: Changed functions to use size_t strings/strnlen.c: Changed functions to use size_t strings/strnmov.c: Changed functions to use size_t strings/strto.c: unsigned char -> uchar strings/strtod.c: Changed functions to use size_t strings/strxnmov.c: Changed functions to use size_t strings/xml.c: Changed functions to use size_t Indentation fixes tests/mysql_client_test.c: Removed some old types tests/thread_test.c: Removed some old types vio/test-ssl.c: Removed some old types vio/test-sslclient.c: Removed some old types vio/test-sslserver.c: Removed some old types vio/vio.c: Removed some old types vio/vio_priv.h: Removed some old types Changed vio_read()/vio_write() to work with size_t vio/viosocket.c: Changed vio_read()/vio_write() to work with size_t Indentation fixes vio/viossl.c: Changed vio_read()/vio_write() to work with size_t Indentation fixes vio/viosslfactories.c: Removed some old types vio/viotest-ssl.c: Removed some old types win/README: More explanations
2106 lines
60 KiB
C
2106 lines
60 KiB
C
/* Copyright (C) 2005 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
original idea: Brian Aker via playing with ab for too many years
|
|
coded by: Patrick Galbraith
|
|
*/
|
|
|
|
|
|
/*
|
|
MySQL Slap
|
|
|
|
A simple program designed to work as if multiple clients querying the database,
|
|
then reporting the timing of each stage.
|
|
|
|
MySQL slap runs three stages:
|
|
1) Create schema,table, and optionally any SP or data you want to beign
|
|
the test with. (single client)
|
|
2) Load test (many clients)
|
|
3) Cleanup (disconnection, drop table if specified, single client)
|
|
|
|
Examples:
|
|
|
|
Supply your own create and query SQL statements, with 50 clients
|
|
querying (200 selects for each):
|
|
|
|
mysqlslap --create="CREATE TABLE A (a int);INSERT INTO A (23)" \
|
|
--query="SELECT * FROM A" --concurrency=50 --iterations=200
|
|
|
|
Let the program build the query SQL statement with a table of two int
|
|
columns, three varchar columns, five clients querying (20 times each),
|
|
don't create the table or insert the data (using the previous test's
|
|
schema and data):
|
|
|
|
mysqlslap --concurrency=5 --iterations=20 \
|
|
--number-int-cols=2 --number-char-cols=3 \
|
|
--auto-generate-sql
|
|
|
|
Tell the program to load the create, insert and query SQL statements from
|
|
the specified files, where the create.sql file has multiple table creation
|
|
statements delimited by ';' and multiple insert statements delimited by ';'.
|
|
The --query file will have multiple queries delimited by ';', run all the
|
|
load statements, and then run all the queries in the query file
|
|
with five clients (five times each):
|
|
|
|
mysqlslap --concurrency=5 \
|
|
--iterations=5 --query=query.sql --create=create.sql \
|
|
--delimiter=";"
|
|
|
|
TODO:
|
|
Add language for better tests
|
|
String length for files and those put on the command line are not
|
|
setup to handle binary data.
|
|
More stats
|
|
Break up tests and run them on multiple hosts at once.
|
|
Allow output to be fed into a database directly.
|
|
|
|
*/
|
|
|
|
#define SHOW_VERSION "0.9"
|
|
|
|
#define HUGE_STRING_LENGTH 8196
|
|
#define RAND_STRING_SIZE 126
|
|
|
|
/* Types */
|
|
#define SELECT_TYPE 0
|
|
#define UPDATE_TYPE 1
|
|
#define INSERT_TYPE 2
|
|
#define UPDATE_TYPE_REQUIRES_PREFIX 3
|
|
#define CREATE_TABLE_TYPE 4
|
|
#define SELECT_TYPE_REQUIRES_PREFIX 5
|
|
|
|
#include "client_priv.h"
|
|
#include <mysqld_error.h>
|
|
#include <my_dir.h>
|
|
#include <signal.h>
|
|
#include <stdarg.h>
|
|
#include <sslopt-vars.h>
|
|
#include <sys/types.h>
|
|
#ifndef __WIN__
|
|
#include <sys/wait.h>
|
|
#endif
|
|
#include <ctype.h>
|
|
|
|
#ifdef __WIN__
|
|
#define srandom srand
|
|
#define random rand
|
|
#define snprintf _snprintf
|
|
#endif
|
|
|
|
#ifdef HAVE_SMEM
|
|
static char *shared_memory_base_name=0;
|
|
#endif
|
|
|
|
/* Global Thread counter */
|
|
uint thread_counter;
|
|
pthread_mutex_t counter_mutex;
|
|
pthread_cond_t count_threshhold;
|
|
uint master_wakeup;
|
|
pthread_mutex_t sleeper_mutex;
|
|
pthread_cond_t sleep_threshhold;
|
|
|
|
static char **defaults_argv;
|
|
|
|
char **primary_keys;
|
|
unsigned long long primary_keys_number_of;
|
|
|
|
static char *host= NULL, *opt_password= NULL, *user= NULL,
|
|
*user_supplied_query= NULL,
|
|
*user_supplied_pre_statements= NULL,
|
|
*user_supplied_post_statements= NULL,
|
|
*default_engine= NULL,
|
|
*opt_mysql_unix_port= NULL;
|
|
|
|
const char *delimiter= "\n";
|
|
|
|
const char *create_schema_string= "mysqlslap";
|
|
|
|
static my_bool opt_preserve;
|
|
|
|
static my_bool opt_only_print= FALSE;
|
|
|
|
static my_bool opt_compress= FALSE, tty_password= FALSE,
|
|
opt_silent= FALSE,
|
|
auto_generate_sql_autoincrement= FALSE,
|
|
auto_generate_sql_guid_primary= FALSE,
|
|
auto_generate_sql= FALSE;
|
|
const char *auto_generate_sql_type= "mixed";
|
|
|
|
static unsigned long connect_flags= CLIENT_MULTI_RESULTS;
|
|
|
|
static int verbose, delimiter_length;
|
|
const char *num_int_cols_opt;
|
|
const char *num_char_cols_opt;
|
|
/* Yes, we do set defaults here */
|
|
static unsigned int num_int_cols= 1;
|
|
static unsigned int num_char_cols= 1;
|
|
static unsigned int num_int_cols_index= 0;
|
|
static unsigned int num_char_cols_index= 0;
|
|
|
|
static unsigned int iterations;
|
|
static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
|
|
static ulonglong actual_queries= 0;
|
|
static ulonglong auto_actual_queries;
|
|
static ulonglong auto_generate_sql_unique_write_number;
|
|
static ulonglong auto_generate_sql_unique_query_number;
|
|
static unsigned int auto_generate_sql_secondary_indexes;
|
|
static ulonglong num_of_query;
|
|
static ulonglong auto_generate_sql_number;
|
|
const char *concurrency_str= NULL;
|
|
static char *create_string;
|
|
uint *concurrency;
|
|
|
|
const char *default_dbug_option="d:t:o,/tmp/mysqlslap.trace";
|
|
const char *opt_csv_str;
|
|
File csv_file;
|
|
|
|
static uint opt_protocol= 0;
|
|
|
|
static int get_options(int *argc,char ***argv);
|
|
static uint opt_mysql_port= 0;
|
|
|
|
static const char *load_default_groups[]= { "mysqlslap","client",0 };
|
|
|
|
typedef struct statement statement;
|
|
|
|
struct statement {
|
|
char *string;
|
|
size_t length;
|
|
unsigned char type;
|
|
char *option;
|
|
size_t option_length;
|
|
statement *next;
|
|
};
|
|
|
|
typedef struct option_string option_string;
|
|
|
|
struct option_string {
|
|
char *string;
|
|
size_t length;
|
|
char *option;
|
|
size_t option_length;
|
|
option_string *next;
|
|
};
|
|
|
|
typedef struct stats stats;
|
|
|
|
struct stats {
|
|
long int timing;
|
|
uint users;
|
|
unsigned long long rows;
|
|
};
|
|
|
|
typedef struct thread_context thread_context;
|
|
|
|
struct thread_context {
|
|
statement *stmt;
|
|
ulonglong limit;
|
|
};
|
|
|
|
typedef struct conclusions conclusions;
|
|
|
|
struct conclusions {
|
|
char *engine;
|
|
long int avg_timing;
|
|
long int max_timing;
|
|
long int min_timing;
|
|
uint users;
|
|
unsigned long long avg_rows;
|
|
/* The following are not used yet */
|
|
unsigned long long max_rows;
|
|
unsigned long long min_rows;
|
|
};
|
|
|
|
static option_string *engine_options= NULL;
|
|
static statement *pre_statements= NULL;
|
|
static statement *post_statements= NULL;
|
|
static statement *create_statements= NULL,
|
|
*query_statements= NULL;
|
|
|
|
/* Prototypes */
|
|
void print_conclusions(conclusions *con);
|
|
void print_conclusions_csv(conclusions *con);
|
|
void generate_stats(conclusions *con, option_string *eng, stats *sptr);
|
|
uint parse_comma(const char *string, uint **range);
|
|
uint parse_delimiter(const char *script, statement **stmt, char delm);
|
|
uint parse_option(const char *origin, option_string **stmt, char delm);
|
|
static int drop_schema(MYSQL *mysql, const char *db);
|
|
uint get_random_string(char *buf);
|
|
static statement *build_table_string(void);
|
|
static statement *build_insert_string(void);
|
|
static statement *build_update_string(void);
|
|
static statement * build_select_string(my_bool key);
|
|
static int generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt);
|
|
static int drop_primary_key_list(void);
|
|
static int create_schema(MYSQL *mysql, const char *db, statement *stmt,
|
|
option_string *engine_stmt);
|
|
static int run_scheduler(stats *sptr, statement *stmts, uint concur,
|
|
ulonglong limit);
|
|
pthread_handler_t run_task(void *p);
|
|
void statement_cleanup(statement *stmt);
|
|
void option_cleanup(option_string *stmt);
|
|
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr);
|
|
static int run_statements(MYSQL *mysql, statement *stmt);
|
|
|
|
static const char ALPHANUMERICS[]=
|
|
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
|
|
|
|
|
|
static long int timedif(struct timeval a, struct timeval b)
|
|
{
|
|
register int us, s;
|
|
|
|
us = a.tv_usec - b.tv_usec;
|
|
us /= 1000;
|
|
s = a.tv_sec - b.tv_sec;
|
|
s *= 1000;
|
|
return s + us;
|
|
}
|
|
|
|
#ifdef __WIN__
|
|
static int gettimeofday(struct timeval *tp, void *tzp)
|
|
{
|
|
unsigned int ticks;
|
|
ticks= GetTickCount();
|
|
tp->tv_usec= ticks*1000;
|
|
tp->tv_sec= ticks/1000;
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
MYSQL mysql;
|
|
option_string *eptr;
|
|
|
|
MY_INIT(argv[0]);
|
|
|
|
load_defaults("my",load_default_groups,&argc,&argv);
|
|
defaults_argv=argv;
|
|
if (get_options(&argc,&argv))
|
|
{
|
|
free_defaults(defaults_argv);
|
|
my_end(0);
|
|
exit(1);
|
|
}
|
|
|
|
/* Seed the random number generator if we will be using it. */
|
|
if (auto_generate_sql)
|
|
srandom((uint)time(NULL));
|
|
|
|
/* globals? Yes, so we only have to run strlen once */
|
|
delimiter_length= strlen(delimiter);
|
|
|
|
if (argc > 2)
|
|
{
|
|
fprintf(stderr,"%s: Too many arguments\n",my_progname);
|
|
free_defaults(defaults_argv);
|
|
my_end(0);
|
|
exit(1);
|
|
}
|
|
mysql_init(&mysql);
|
|
if (opt_compress)
|
|
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
|
|
#ifdef HAVE_OPENSSL
|
|
if (opt_use_ssl)
|
|
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
|
|
opt_ssl_capath, opt_ssl_cipher);
|
|
#endif
|
|
if (opt_protocol)
|
|
mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
|
|
#ifdef HAVE_SMEM
|
|
if (shared_memory_base_name)
|
|
mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
|
|
#endif
|
|
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
|
|
|
|
if (!opt_only_print)
|
|
{
|
|
if (!(mysql_real_connect(&mysql, host, user, opt_password,
|
|
NULL, opt_mysql_port,
|
|
opt_mysql_unix_port, connect_flags)))
|
|
{
|
|
fprintf(stderr,"%s: Error when connecting to server: %s\n",
|
|
my_progname,mysql_error(&mysql));
|
|
free_defaults(defaults_argv);
|
|
my_end(0);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
VOID(pthread_mutex_init(&counter_mutex, NULL));
|
|
VOID(pthread_cond_init(&count_threshhold, NULL));
|
|
VOID(pthread_mutex_init(&sleeper_mutex, NULL));
|
|
VOID(pthread_cond_init(&sleep_threshhold, NULL));
|
|
|
|
/* Main iterations loop */
|
|
eptr= engine_options;
|
|
do
|
|
{
|
|
/* For the final stage we run whatever queries we were asked to run */
|
|
uint *current;
|
|
|
|
if (verbose >= 2)
|
|
printf("Starting Concurrency Test\n");
|
|
|
|
if (*concurrency)
|
|
{
|
|
for (current= concurrency; current && *current; current++)
|
|
concurrency_loop(&mysql, *current, eptr);
|
|
}
|
|
else
|
|
{
|
|
uint infinite= 1;
|
|
do {
|
|
concurrency_loop(&mysql, infinite, eptr);
|
|
}
|
|
while (infinite++);
|
|
}
|
|
|
|
if (!opt_preserve)
|
|
drop_schema(&mysql, create_schema_string);
|
|
|
|
} while (eptr ? (eptr= eptr->next) : 0);
|
|
|
|
VOID(pthread_mutex_destroy(&counter_mutex));
|
|
VOID(pthread_cond_destroy(&count_threshhold));
|
|
VOID(pthread_mutex_destroy(&sleeper_mutex));
|
|
VOID(pthread_cond_destroy(&sleep_threshhold));
|
|
|
|
if (!opt_only_print)
|
|
mysql_close(&mysql); /* Close & free connection */
|
|
|
|
/* now free all the strings we created */
|
|
if (opt_password)
|
|
my_free(opt_password, MYF(0));
|
|
|
|
my_free(concurrency, MYF(0));
|
|
|
|
statement_cleanup(create_statements);
|
|
statement_cleanup(query_statements);
|
|
statement_cleanup(pre_statements);
|
|
statement_cleanup(post_statements);
|
|
option_cleanup(engine_options);
|
|
|
|
#ifdef HAVE_SMEM
|
|
if (shared_memory_base_name)
|
|
my_free(shared_memory_base_name, MYF(MY_ALLOW_ZERO_PTR));
|
|
#endif
|
|
free_defaults(defaults_argv);
|
|
my_end(0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr)
|
|
{
|
|
unsigned int x;
|
|
stats *head_sptr;
|
|
stats *sptr;
|
|
conclusions conclusion;
|
|
unsigned long long client_limit;
|
|
|
|
head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
|
|
bzero(&conclusion, sizeof(conclusions));
|
|
|
|
if (auto_actual_queries)
|
|
client_limit= auto_actual_queries;
|
|
else if (num_of_query)
|
|
client_limit= num_of_query / current;
|
|
else
|
|
client_limit= actual_queries;
|
|
|
|
for (x= 0, sptr= head_sptr; x < iterations; x++, sptr++)
|
|
{
|
|
/*
|
|
We might not want to load any data, such as when we are calling
|
|
a stored_procedure that doesn't use data, or we know we already have
|
|
data in the table.
|
|
*/
|
|
if (!opt_preserve)
|
|
drop_schema(mysql, create_schema_string);
|
|
|
|
/* First we create */
|
|
if (create_statements)
|
|
create_schema(mysql, create_schema_string, create_statements, eptr);
|
|
|
|
/*
|
|
If we generated GUID we need to build a list of them from creation that
|
|
we can later use.
|
|
*/
|
|
if (verbose >= 2)
|
|
printf("Generating primary key list\n");
|
|
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
|
|
generate_primary_key_list(mysql, eptr);
|
|
|
|
if (pre_statements)
|
|
run_statements(mysql, pre_statements);
|
|
|
|
run_scheduler(sptr, query_statements, current, client_limit);
|
|
|
|
if (post_statements)
|
|
run_statements(mysql, post_statements);
|
|
|
|
/* We are finished with this run */
|
|
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
|
|
drop_primary_key_list();
|
|
}
|
|
|
|
if (verbose >= 2)
|
|
printf("Generating stats\n");
|
|
|
|
generate_stats(&conclusion, eptr, head_sptr);
|
|
|
|
if (!opt_silent)
|
|
print_conclusions(&conclusion);
|
|
if (opt_csv_str)
|
|
print_conclusions_csv(&conclusion);
|
|
|
|
my_free(head_sptr, MYF(0));
|
|
|
|
}
|
|
|
|
|
|
static struct my_option my_long_options[] =
|
|
{
|
|
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql", 'a',
|
|
"Generate SQL where not supplied by file or command line.",
|
|
(uchar**) &auto_generate_sql, (uchar**) &auto_generate_sql,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-add-autoincrement", OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
|
|
"Add autoincrement to auto-generated tables.",
|
|
(uchar**) &auto_generate_sql_autoincrement,
|
|
(uchar**) &auto_generate_sql_autoincrement,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-execute-number", OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
|
|
"Set this number to generate a set number of queries to run.\n",
|
|
(uchar**) &auto_actual_queries, (uchar**) &auto_actual_queries,
|
|
0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
|
|
"Add GUID based primary keys to auto-generated tables.",
|
|
(uchar**) &auto_generate_sql_guid_primary,
|
|
(uchar**) &auto_generate_sql_guid_primary,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
|
|
"Load types are mixed, update, write, key, or read. Default is mixed\n",
|
|
(uchar**) &auto_generate_sql_type, (uchar**) &auto_generate_sql_type,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-secondary-indexes",
|
|
OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
|
|
"Number of secondary indexes to add auto-generated tables.",
|
|
(uchar**) &auto_generate_sql_secondary_indexes,
|
|
(uchar**) &auto_generate_sql_secondary_indexes, 0,
|
|
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-unique-query-number",
|
|
OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
|
|
"Number of unique queries auto tests",
|
|
(uchar**) &auto_generate_sql_unique_query_number,
|
|
(uchar**) &auto_generate_sql_unique_query_number,
|
|
0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-unique-write-number",
|
|
OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
|
|
"Number of unique queries for auto-generate-sql-write-number",
|
|
(uchar**) &auto_generate_sql_unique_write_number,
|
|
(uchar**) &auto_generate_sql_unique_write_number,
|
|
0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
|
|
{"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
|
|
"Number of rows to insert to used in read and write loads (default is 100).\n",
|
|
(uchar**) &auto_generate_sql_number, (uchar**) &auto_generate_sql_number,
|
|
0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
|
|
{"compress", 'C', "Use compression in server/client protocol.",
|
|
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
|
|
0, 0, 0},
|
|
{"concurrency", 'c', "Number of clients to simulate for query to run.",
|
|
(uchar**) &concurrency_str, (uchar**) &concurrency_str, 0, GET_STR,
|
|
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"create", OPT_SLAP_CREATE_STRING, "File or string to use create tables.",
|
|
(uchar**) &create_string, (uchar**) &create_string, 0, GET_STR, REQUIRED_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
|
|
(uchar**) &create_schema_string, (uchar**) &create_schema_string, 0, GET_STR,
|
|
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"csv", OPT_SLAP_CSV,
|
|
"Generate CSV output to named file or to stdout if no file is named.",
|
|
(uchar**) &opt_csv_str, (uchar**) &opt_csv_str, 0, GET_STR,
|
|
OPT_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
|
|
(uchar**) &default_dbug_option, (uchar**) &default_dbug_option, 0, GET_STR,
|
|
OPT_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"delimiter", 'F',
|
|
"Delimiter to use in SQL statements supplied in file or command line.",
|
|
(uchar**) &delimiter, (uchar**) &delimiter, 0, GET_STR, REQUIRED_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"engine", 'e', "Storage engine to use for creating the table.",
|
|
(uchar**) &default_engine, (uchar**) &default_engine, 0,
|
|
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"host", 'h', "Connect to host.", (uchar**) &host, (uchar**) &host, 0, GET_STR,
|
|
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"iterations", 'i', "Number of times too run the tests.", (uchar**) &iterations,
|
|
(uchar**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
|
|
{"number-char-cols", 'x',
|
|
"Number of VARCHAR columns to create table with if specifying --auto-generate-sql ",
|
|
(uchar**) &num_char_cols_opt, (uchar**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"number-int-cols", 'y',
|
|
"Number of INT columns to create table with if specifying --auto-generate-sql.",
|
|
(uchar**) &num_int_cols_opt, (uchar**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY,
|
|
"Limit each client to this number of queries (this is not exact).",
|
|
(uchar**) &num_of_query, (uchar**) &num_of_query, 0,
|
|
GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"only-print", OPT_MYSQL_ONLY_PRINT,
|
|
"This causes mysqlslap to not connect to the databases, but instead print "
|
|
"out what it would have done instead.",
|
|
(uchar**) &opt_only_print, (uchar**) &opt_only_print, 0, GET_BOOL, NO_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"password", 'p',
|
|
"Password to use when connecting to server. If password is not given it's "
|
|
"asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
|
#ifdef __WIN__
|
|
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
|
|
NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
#endif
|
|
{"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
|
|
(uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
|
|
0},
|
|
{"post-query", OPT_SLAP_POST_QUERY,
|
|
"Query to run or file containing query to run after executing.",
|
|
(uchar**) &user_supplied_post_statements,
|
|
(uchar**) &user_supplied_post_statements,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"pre-query", OPT_SLAP_PRE_QUERY,
|
|
"Query to run or file containing query to run before executing.",
|
|
(uchar**) &user_supplied_pre_statements,
|
|
(uchar**) &user_supplied_pre_statements,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"preserve-schema", OPT_MYSQL_PRESERVE_SCHEMA,
|
|
"Preserve the schema from the mysqlslap run, this happens unless "
|
|
"--auto-generate-sql or --create are used.",
|
|
(uchar**) &opt_preserve, (uchar**) &opt_preserve, 0, GET_BOOL,
|
|
NO_ARG, TRUE, 0, 0, 0, 0, 0},
|
|
{"protocol", OPT_MYSQL_PROTOCOL,
|
|
"The protocol of connection (tcp,socket,pipe,memory).",
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"query", 'q', "Query to run or file containing query to run.",
|
|
(uchar**) &user_supplied_query, (uchar**) &user_supplied_query,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
#ifdef HAVE_SMEM
|
|
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
|
|
"Base name of shared memory.", (uchar**) &shared_memory_base_name,
|
|
(uchar**) &shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
#endif
|
|
{"silent", 's', "Run program in silent mode - no output.",
|
|
(uchar**) &opt_silent, (uchar**) &opt_silent, 0, GET_BOOL, NO_ARG,
|
|
0, 0, 0, 0, 0, 0},
|
|
{"socket", 'S', "Socket file to use for connection.",
|
|
(uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
|
|
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
#include <sslopt-longopts.h>
|
|
#ifndef DONT_ALLOW_USER_CHANGE
|
|
{"user", 'u', "User for login if not current user.", (uchar**) &user,
|
|
(uchar**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
#endif
|
|
{"verbose", 'v',
|
|
"More verbose output; You can use this multiple times to get even more "
|
|
"verbose output.", (uchar**) &verbose, (uchar**) &verbose, 0,
|
|
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
|
|
NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
|
|
};
|
|
|
|
|
|
#include <help_start.h>
|
|
|
|
static void print_version(void)
|
|
{
|
|
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,SHOW_VERSION,
|
|
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
|
|
}
|
|
|
|
|
|
static void usage(void)
|
|
{
|
|
print_version();
|
|
puts("Copyright (C) 2005 MySQL AB");
|
|
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
|
|
\nand you are welcome to modify and redistribute it under the GPL \
|
|
license\n");
|
|
puts("Run a query multiple times against the server\n");
|
|
printf("Usage: %s [OPTIONS]\n",my_progname);
|
|
print_defaults("my",load_default_groups);
|
|
my_print_help(my_long_options);
|
|
}
|
|
|
|
#include <help_end.h>
|
|
|
|
static my_bool
|
|
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
|
char *argument)
|
|
{
|
|
DBUG_ENTER("get_one_option");
|
|
switch(optid) {
|
|
#ifdef __NETWARE__
|
|
case OPT_AUTO_CLOSE:
|
|
setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
|
|
break;
|
|
#endif
|
|
case 'v':
|
|
verbose++;
|
|
break;
|
|
case 'p':
|
|
if (argument)
|
|
{
|
|
char *start= argument;
|
|
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
|
|
opt_password= my_strdup(argument,MYF(MY_FAE));
|
|
while (*argument) *argument++= 'x'; /* Destroy argument */
|
|
if (*start)
|
|
start[1]= 0; /* Cut length of argument */
|
|
tty_password= 0;
|
|
}
|
|
else
|
|
tty_password= 1;
|
|
break;
|
|
case 'W':
|
|
#ifdef __WIN__
|
|
opt_protocol= MYSQL_PROTOCOL_PIPE;
|
|
#endif
|
|
break;
|
|
case OPT_MYSQL_PROTOCOL:
|
|
opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
|
|
opt->name);
|
|
break;
|
|
case '#':
|
|
DBUG_PUSH(argument ? argument : default_dbug_option);
|
|
break;
|
|
#include <sslopt-case.h>
|
|
case 'V':
|
|
print_version();
|
|
exit(0);
|
|
break;
|
|
case '?':
|
|
case 'I': /* Info */
|
|
usage();
|
|
exit(0);
|
|
}
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
uint
|
|
get_random_string(char *buf)
|
|
{
|
|
char *buf_ptr= buf;
|
|
int x;
|
|
DBUG_ENTER("get_random_string");
|
|
for (x= RAND_STRING_SIZE; x > 0; x--)
|
|
*buf_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
|
|
DBUG_RETURN(buf_ptr - buf);
|
|
}
|
|
|
|
|
|
/*
|
|
build_table_string
|
|
|
|
This function builds a create table query if the user opts to not supply
|
|
a file or string containing a create table statement
|
|
*/
|
|
static statement *
|
|
build_table_string(void)
|
|
{
|
|
char buf[HUGE_STRING_LENGTH];
|
|
unsigned int col_count;
|
|
statement *ptr;
|
|
DYNAMIC_STRING table_string;
|
|
DBUG_ENTER("build_table_string");
|
|
|
|
DBUG_PRINT("info", ("num int cols %u num char cols %u",
|
|
num_int_cols, num_char_cols));
|
|
|
|
init_dynamic_string(&table_string, "", 1024, 1024);
|
|
|
|
dynstr_append(&table_string, "CREATE TABLE `t1` (");
|
|
|
|
if (auto_generate_sql_autoincrement)
|
|
{
|
|
dynstr_append(&table_string, "id serial");
|
|
|
|
if (num_int_cols || num_char_cols)
|
|
dynstr_append(&table_string, ",");
|
|
}
|
|
|
|
if (auto_generate_sql_guid_primary)
|
|
{
|
|
dynstr_append(&table_string, "id varchar(32) primary key");
|
|
|
|
if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
|
|
dynstr_append(&table_string, ",");
|
|
}
|
|
|
|
if (auto_generate_sql_secondary_indexes)
|
|
{
|
|
unsigned int count;
|
|
|
|
for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
|
|
{
|
|
if (count) /* Except for the first pass we add a comma */
|
|
dynstr_append(&table_string, ",");
|
|
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
|
|
> HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in create table\n");
|
|
exit(1);
|
|
}
|
|
dynstr_append(&table_string, buf);
|
|
}
|
|
|
|
if (num_int_cols || num_char_cols)
|
|
dynstr_append(&table_string, ",");
|
|
}
|
|
|
|
if (num_int_cols)
|
|
for (col_count= 1; col_count <= num_int_cols; col_count++)
|
|
{
|
|
if (num_int_cols_index)
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32), INDEX(intcol%d)",
|
|
col_count, col_count) > HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in create table\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32) ", col_count)
|
|
> HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in create table\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
dynstr_append(&table_string, buf);
|
|
|
|
if (col_count < num_int_cols || num_char_cols > 0)
|
|
dynstr_append(&table_string, ",");
|
|
}
|
|
|
|
if (num_char_cols)
|
|
for (col_count= 1; col_count <= num_char_cols; col_count++)
|
|
{
|
|
if (num_char_cols_index)
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH,
|
|
"charcol%d VARCHAR(128), INDEX(charcol%d) ",
|
|
col_count, col_count) > HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating table\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)",
|
|
col_count) > HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating table\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
dynstr_append(&table_string, buf);
|
|
|
|
if (col_count < num_char_cols)
|
|
dynstr_append(&table_string, ",");
|
|
}
|
|
|
|
dynstr_append(&table_string, ")");
|
|
ptr= (statement *)my_malloc(sizeof(statement),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->string = (char *)my_malloc(table_string.length+1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->length= table_string.length+1;
|
|
ptr->type= CREATE_TABLE_TYPE;
|
|
strmov(ptr->string, table_string.str);
|
|
dynstr_free(&table_string);
|
|
DBUG_RETURN(ptr);
|
|
}
|
|
|
|
/*
|
|
build_update_string()
|
|
|
|
This function builds insert statements when the user opts to not supply
|
|
an insert file or string containing insert data
|
|
*/
|
|
static statement *
|
|
build_update_string(void)
|
|
{
|
|
char buf[HUGE_STRING_LENGTH];
|
|
unsigned int col_count;
|
|
statement *ptr;
|
|
DYNAMIC_STRING update_string;
|
|
DBUG_ENTER("build_update_string");
|
|
|
|
init_dynamic_string(&update_string, "", 1024, 1024);
|
|
|
|
dynstr_append(&update_string, "UPDATE t1 SET ");
|
|
|
|
if (num_int_cols)
|
|
for (col_count= 1; col_count <= num_int_cols; col_count++)
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count,
|
|
random()) > HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating update\n");
|
|
exit(1);
|
|
}
|
|
dynstr_append(&update_string, buf);
|
|
|
|
if (col_count < num_int_cols || num_char_cols > 0)
|
|
dynstr_append_mem(&update_string, ",", 1);
|
|
}
|
|
|
|
if (num_char_cols)
|
|
for (col_count= 1; col_count <= num_char_cols; col_count++)
|
|
{
|
|
char rand_buffer[RAND_STRING_SIZE];
|
|
int buf_len= get_random_string(rand_buffer);
|
|
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count,
|
|
buf_len, rand_buffer)
|
|
> HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating update\n");
|
|
exit(1);
|
|
}
|
|
dynstr_append(&update_string, buf);
|
|
|
|
if (col_count < num_char_cols)
|
|
dynstr_append_mem(&update_string, ",", 1);
|
|
}
|
|
|
|
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
|
|
dynstr_append(&update_string, " WHERE id = ");
|
|
|
|
|
|
ptr= (statement *)my_malloc(sizeof(statement),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
|
|
ptr->string= (char *)my_malloc(update_string.length + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->length= update_string.length+1;
|
|
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
|
|
ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
|
|
else
|
|
ptr->type= UPDATE_TYPE;
|
|
strmov(ptr->string, update_string.str);
|
|
dynstr_free(&update_string);
|
|
DBUG_RETURN(ptr);
|
|
}
|
|
|
|
|
|
/*
|
|
build_insert_string()
|
|
|
|
This function builds insert statements when the user opts to not supply
|
|
an insert file or string containing insert data
|
|
*/
|
|
static statement *
|
|
build_insert_string(void)
|
|
{
|
|
char buf[HUGE_STRING_LENGTH];
|
|
unsigned int col_count;
|
|
statement *ptr;
|
|
DYNAMIC_STRING insert_string;
|
|
DBUG_ENTER("build_insert_string");
|
|
|
|
init_dynamic_string(&insert_string, "", 1024, 1024);
|
|
|
|
dynstr_append(&insert_string, "INSERT INTO t1 VALUES (");
|
|
|
|
if (auto_generate_sql_autoincrement)
|
|
{
|
|
dynstr_append(&insert_string, "NULL");
|
|
|
|
if (num_int_cols || num_char_cols)
|
|
dynstr_append(&insert_string, ",");
|
|
}
|
|
|
|
if (auto_generate_sql_guid_primary)
|
|
{
|
|
dynstr_append(&insert_string, "uuid()");
|
|
|
|
if (num_int_cols || num_char_cols)
|
|
dynstr_append(&insert_string, ",");
|
|
}
|
|
|
|
if (auto_generate_sql_secondary_indexes)
|
|
{
|
|
unsigned int count;
|
|
|
|
for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
|
|
{
|
|
if (count) /* Except for the first pass we add a comma */
|
|
dynstr_append(&insert_string, ",");
|
|
|
|
dynstr_append(&insert_string, "uuid()");
|
|
}
|
|
|
|
if (num_int_cols || num_char_cols)
|
|
dynstr_append(&insert_string, ",");
|
|
}
|
|
|
|
if (num_int_cols)
|
|
for (col_count= 1; col_count <= num_int_cols; col_count++)
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "%ld", random()) > HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating insert\n");
|
|
exit(1);
|
|
}
|
|
dynstr_append(&insert_string, buf);
|
|
|
|
if (col_count < num_int_cols || num_char_cols > 0)
|
|
dynstr_append_mem(&insert_string, ",", 1);
|
|
}
|
|
|
|
if (num_char_cols)
|
|
for (col_count= 1; col_count <= num_char_cols; col_count++)
|
|
{
|
|
int buf_len= get_random_string(buf);
|
|
dynstr_append_mem(&insert_string, "'", 1);
|
|
dynstr_append_mem(&insert_string, buf, buf_len);
|
|
dynstr_append_mem(&insert_string, "'", 1);
|
|
|
|
if (col_count < num_char_cols)
|
|
dynstr_append_mem(&insert_string, ",", 1);
|
|
}
|
|
|
|
dynstr_append_mem(&insert_string, ")", 1);
|
|
|
|
ptr= (statement *)my_malloc(sizeof(statement),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->string= (char *)my_malloc(insert_string.length + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->length= insert_string.length+1;
|
|
ptr->type= INSERT_TYPE;
|
|
strmov(ptr->string, insert_string.str);
|
|
dynstr_free(&insert_string);
|
|
DBUG_RETURN(ptr);
|
|
}
|
|
|
|
|
|
/*
|
|
build_select_string()
|
|
|
|
This function builds a query if the user opts to not supply a query
|
|
statement or file containing a query statement
|
|
*/
|
|
static statement *
|
|
build_select_string(my_bool key)
|
|
{
|
|
char buf[HUGE_STRING_LENGTH];
|
|
unsigned int col_count;
|
|
statement *ptr;
|
|
static DYNAMIC_STRING query_string;
|
|
DBUG_ENTER("build_select_string");
|
|
|
|
init_dynamic_string(&query_string, "", 1024, 1024);
|
|
|
|
dynstr_append_mem(&query_string, "SELECT ", 7);
|
|
for (col_count= 1; col_count <= num_int_cols; col_count++)
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count)
|
|
> HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating select\n");
|
|
exit(1);
|
|
}
|
|
dynstr_append(&query_string, buf);
|
|
|
|
if (col_count < num_int_cols || num_char_cols > 0)
|
|
dynstr_append_mem(&query_string, ",", 1);
|
|
|
|
}
|
|
for (col_count= 1; col_count <= num_char_cols; col_count++)
|
|
{
|
|
if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d", col_count)
|
|
> HUGE_STRING_LENGTH)
|
|
{
|
|
fprintf(stderr, "Memory Allocation error in creating select\n");
|
|
exit(1);
|
|
}
|
|
dynstr_append(&query_string, buf);
|
|
|
|
if (col_count < num_char_cols)
|
|
dynstr_append_mem(&query_string, ",", 1);
|
|
|
|
}
|
|
dynstr_append(&query_string, " FROM t1");
|
|
|
|
if ((key) &&
|
|
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
|
|
dynstr_append(&query_string, " WHERE id = ");
|
|
|
|
ptr= (statement *)my_malloc(sizeof(statement),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->string= (char *)my_malloc(query_string.length + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
ptr->length= query_string.length+1;
|
|
if ((key) &&
|
|
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
|
|
ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
|
|
else
|
|
ptr->type= SELECT_TYPE;
|
|
strmov(ptr->string, query_string.str);
|
|
dynstr_free(&query_string);
|
|
DBUG_RETURN(ptr);
|
|
}
|
|
|
|
static int
|
|
get_options(int *argc,char ***argv)
|
|
{
|
|
int ho_error;
|
|
char *tmp_string;
|
|
MY_STAT sbuf; /* Stat information for the data file */
|
|
|
|
DBUG_ENTER("get_options");
|
|
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
|
|
exit(ho_error);
|
|
|
|
if (!user)
|
|
user= (char *)"root";
|
|
|
|
if (create_string || auto_generate_sql)
|
|
{
|
|
if (verbose >= 1)
|
|
fprintf(stderr, "Turning off preserve-schema!\n");
|
|
opt_preserve= FALSE;
|
|
}
|
|
|
|
if (auto_generate_sql && (create_string || user_supplied_query))
|
|
{
|
|
fprintf(stderr,
|
|
"%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
|
|
if (auto_generate_sql && auto_generate_sql_guid_primary &&
|
|
auto_generate_sql_autoincrement)
|
|
{
|
|
fprintf(stderr,
|
|
"%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
|
|
/*
|
|
We are testing to make sure that if someone specified a key search
|
|
that we actually added a key!
|
|
*/
|
|
if (auto_generate_sql && auto_generate_sql_type[0] == 'k')
|
|
if ( auto_generate_sql_autoincrement == FALSE &&
|
|
auto_generate_sql_guid_primary == FALSE)
|
|
{
|
|
fprintf(stderr,
|
|
"%s: Can't perform key test without a primary key!\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
|
|
if (auto_generate_sql && num_of_query && auto_actual_queries)
|
|
{
|
|
fprintf(stderr,
|
|
"%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
|
|
parse_comma(concurrency_str ? concurrency_str : "1", &concurrency);
|
|
|
|
if (opt_csv_str)
|
|
{
|
|
opt_silent= TRUE;
|
|
|
|
if (opt_csv_str[0] == '-')
|
|
{
|
|
csv_file= fileno(stdout);
|
|
}
|
|
else
|
|
{
|
|
if ((csv_file= my_open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND, MYF(0)))
|
|
== -1)
|
|
{
|
|
fprintf(stderr,"%s: Could not open csv file: %sn\n",
|
|
my_progname, opt_csv_str);
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (opt_only_print)
|
|
opt_silent= TRUE;
|
|
|
|
if (num_int_cols_opt)
|
|
{
|
|
option_string *str;
|
|
parse_option(num_int_cols_opt, &str, ',');
|
|
num_int_cols= atoi(str->string);
|
|
if (str->option)
|
|
num_int_cols_index= atoi(str->option);
|
|
option_cleanup(str);
|
|
}
|
|
|
|
if (num_char_cols_opt)
|
|
{
|
|
option_string *str;
|
|
parse_option(num_char_cols_opt, &str, ',');
|
|
num_char_cols= atoi(str->string);
|
|
if (str->option)
|
|
num_char_cols_index= atoi(str->option);
|
|
else
|
|
num_char_cols_index= 0;
|
|
option_cleanup(str);
|
|
}
|
|
|
|
|
|
if (auto_generate_sql)
|
|
{
|
|
unsigned long long x= 0;
|
|
statement *ptr_statement;
|
|
|
|
if (verbose >= 2)
|
|
printf("Building Create Statements for Auto\n");
|
|
|
|
create_statements= build_table_string();
|
|
/*
|
|
Pre-populate table
|
|
*/
|
|
for (ptr_statement= create_statements, x= 0;
|
|
x < auto_generate_sql_unique_write_number;
|
|
x++, ptr_statement= ptr_statement->next)
|
|
{
|
|
ptr_statement->next= build_insert_string();
|
|
}
|
|
|
|
if (verbose >= 2)
|
|
printf("Building Query Statements for Auto\n");
|
|
|
|
if (auto_generate_sql_type[0] == 'r')
|
|
{
|
|
if (verbose >= 2)
|
|
printf("Generating SELECT Statements for Auto\n");
|
|
|
|
query_statements= build_select_string(FALSE);
|
|
for (ptr_statement= query_statements, x= 0;
|
|
x < auto_generate_sql_unique_query_number;
|
|
x++, ptr_statement= ptr_statement->next)
|
|
{
|
|
ptr_statement->next= build_select_string(FALSE);
|
|
}
|
|
}
|
|
else if (auto_generate_sql_type[0] == 'k')
|
|
{
|
|
if (verbose >= 2)
|
|
printf("Generating SELECT for keys Statements for Auto\n");
|
|
|
|
query_statements= build_select_string(TRUE);
|
|
for (ptr_statement= query_statements, x= 0;
|
|
x < auto_generate_sql_unique_query_number;
|
|
x++, ptr_statement= ptr_statement->next)
|
|
{
|
|
ptr_statement->next= build_select_string(TRUE);
|
|
}
|
|
}
|
|
else if (auto_generate_sql_type[0] == 'w')
|
|
{
|
|
/*
|
|
We generate a number of strings in case the engine is
|
|
Archive (since strings which were identical one after another
|
|
would be too easily optimized).
|
|
*/
|
|
if (verbose >= 2)
|
|
printf("Generating INSERT Statements for Auto\n");
|
|
query_statements= build_insert_string();
|
|
for (ptr_statement= query_statements, x= 0;
|
|
x < auto_generate_sql_unique_query_number;
|
|
x++, ptr_statement= ptr_statement->next)
|
|
{
|
|
ptr_statement->next= build_insert_string();
|
|
}
|
|
}
|
|
else if (auto_generate_sql_type[0] == 'u')
|
|
{
|
|
query_statements= build_update_string();
|
|
for (ptr_statement= query_statements, x= 0;
|
|
x < auto_generate_sql_unique_query_number;
|
|
x++, ptr_statement= ptr_statement->next)
|
|
{
|
|
ptr_statement->next= build_update_string();
|
|
}
|
|
}
|
|
else /* Mixed mode is default */
|
|
{
|
|
int coin= 0;
|
|
|
|
query_statements= build_insert_string();
|
|
/*
|
|
This logic should be extended to do a more mixed load,
|
|
at the moment it results in "every other".
|
|
*/
|
|
for (ptr_statement= query_statements, x= 0;
|
|
x < auto_generate_sql_unique_query_number;
|
|
x++, ptr_statement= ptr_statement->next)
|
|
{
|
|
if (coin)
|
|
{
|
|
ptr_statement->next= build_insert_string();
|
|
coin= 0;
|
|
}
|
|
else
|
|
{
|
|
ptr_statement->next= build_select_string(TRUE);
|
|
coin= 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (create_string && my_stat(create_string, &sbuf, MYF(0)))
|
|
{
|
|
File data_file;
|
|
if (!MY_S_ISREG(sbuf.st_mode))
|
|
{
|
|
fprintf(stderr,"%s: Create file was not a regular file\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
if ((data_file= my_open(create_string, O_RDWR, MYF(0))) == -1)
|
|
{
|
|
fprintf(stderr,"%s: Could not open create file\n", my_progname);
|
|
exit(1);
|
|
}
|
|
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
my_read(data_file, tmp_string, sbuf.st_size, MYF(0));
|
|
tmp_string[sbuf.st_size]= '\0';
|
|
my_close(data_file,MYF(0));
|
|
parse_delimiter(tmp_string, &create_statements, delimiter[0]);
|
|
my_free(tmp_string, MYF(0));
|
|
}
|
|
else if (create_string)
|
|
{
|
|
parse_delimiter(create_string, &create_statements, delimiter[0]);
|
|
}
|
|
|
|
if (user_supplied_query && my_stat(user_supplied_query, &sbuf, MYF(0)))
|
|
{
|
|
File data_file;
|
|
if (!MY_S_ISREG(sbuf.st_mode))
|
|
{
|
|
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
if ((data_file= my_open(user_supplied_query, O_RDWR, MYF(0))) == -1)
|
|
{
|
|
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
|
|
exit(1);
|
|
}
|
|
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
my_read(data_file, tmp_string, sbuf.st_size, MYF(0));
|
|
tmp_string[sbuf.st_size]= '\0';
|
|
my_close(data_file,MYF(0));
|
|
if (user_supplied_query)
|
|
actual_queries= parse_delimiter(tmp_string, &query_statements,
|
|
delimiter[0]);
|
|
my_free(tmp_string, MYF(0));
|
|
}
|
|
else if (user_supplied_query)
|
|
{
|
|
actual_queries= parse_delimiter(user_supplied_query, &query_statements,
|
|
delimiter[0]);
|
|
}
|
|
}
|
|
|
|
if (user_supplied_pre_statements && my_stat(user_supplied_pre_statements, &sbuf, MYF(0)))
|
|
{
|
|
File data_file;
|
|
if (!MY_S_ISREG(sbuf.st_mode))
|
|
{
|
|
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
if ((data_file= my_open(user_supplied_pre_statements, O_RDWR, MYF(0))) == -1)
|
|
{
|
|
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
|
|
exit(1);
|
|
}
|
|
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
my_read(data_file, tmp_string, sbuf.st_size, MYF(0));
|
|
tmp_string[sbuf.st_size]= '\0';
|
|
my_close(data_file,MYF(0));
|
|
if (user_supplied_pre_statements)
|
|
actual_queries= parse_delimiter(tmp_string, &pre_statements,
|
|
delimiter[0]);
|
|
my_free(tmp_string, MYF(0));
|
|
}
|
|
else if (user_supplied_pre_statements)
|
|
{
|
|
actual_queries= parse_delimiter(user_supplied_pre_statements,
|
|
&pre_statements,
|
|
delimiter[0]);
|
|
}
|
|
|
|
if (user_supplied_post_statements && my_stat(user_supplied_post_statements, &sbuf, MYF(0)))
|
|
{
|
|
File data_file;
|
|
if (!MY_S_ISREG(sbuf.st_mode))
|
|
{
|
|
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
|
|
my_progname);
|
|
exit(1);
|
|
}
|
|
if ((data_file= my_open(user_supplied_post_statements, O_RDWR, MYF(0))) == -1)
|
|
{
|
|
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
|
|
exit(1);
|
|
}
|
|
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
my_read(data_file, tmp_string, sbuf.st_size, MYF(0));
|
|
tmp_string[sbuf.st_size]= '\0';
|
|
my_close(data_file,MYF(0));
|
|
if (user_supplied_post_statements)
|
|
parse_delimiter(tmp_string, &post_statements,
|
|
delimiter[0]);
|
|
my_free(tmp_string, MYF(0));
|
|
}
|
|
else if (user_supplied_post_statements)
|
|
{
|
|
parse_delimiter(user_supplied_post_statements, &post_statements,
|
|
delimiter[0]);
|
|
}
|
|
|
|
if (verbose >= 2)
|
|
printf("Parsing engines to use.\n");
|
|
|
|
if (default_engine)
|
|
parse_option(default_engine, &engine_options, ',');
|
|
|
|
if (tty_password)
|
|
opt_password= get_tty_password(NullS);
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
static int run_query(MYSQL *mysql, const char *query, int len)
|
|
{
|
|
if (opt_only_print)
|
|
{
|
|
printf("%.*s;\n", len, query);
|
|
return 0;
|
|
}
|
|
|
|
if (verbose >= 3)
|
|
printf("%.*s;\n", len, query);
|
|
return mysql_real_query(mysql, query, len);
|
|
}
|
|
|
|
|
|
static int
|
|
generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
|
|
{
|
|
MYSQL_RES *result;
|
|
MYSQL_ROW row;
|
|
unsigned long long counter;
|
|
DBUG_ENTER("generate_primary_key_list");
|
|
|
|
/*
|
|
Blackhole is a special case, this allows us to test the upper end
|
|
of the server during load runs.
|
|
*/
|
|
if (opt_only_print || (engine_stmt &&
|
|
strstr(engine_stmt->string, "blackhole")))
|
|
{
|
|
primary_keys_number_of= 1;
|
|
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
|
|
primary_keys_number_of),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
/* Yes, we strdup a const string to simplify the interface */
|
|
primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
|
|
}
|
|
else
|
|
{
|
|
if (run_query(mysql, "SELECT id from t1", strlen("SELECT id from t1")))
|
|
{
|
|
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
|
|
mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
|
|
result= mysql_store_result(mysql);
|
|
primary_keys_number_of= mysql_num_rows(result);
|
|
|
|
/* So why check this? Blackhole :) */
|
|
if (primary_keys_number_of)
|
|
{
|
|
/*
|
|
We create the structure and loop and create the items.
|
|
*/
|
|
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
|
|
primary_keys_number_of),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
row= mysql_fetch_row(result);
|
|
for (counter= 0; counter < primary_keys_number_of;
|
|
counter++, row= mysql_fetch_row(result))
|
|
primary_keys[counter]= my_strdup(row[0], MYF(0));
|
|
}
|
|
|
|
mysql_free_result(result);
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
static int
|
|
drop_primary_key_list(void)
|
|
{
|
|
unsigned long long counter;
|
|
|
|
if (primary_keys_number_of)
|
|
{
|
|
for (counter= 0; counter < primary_keys_number_of; counter++)
|
|
my_free(primary_keys[counter], MYF(0));
|
|
|
|
my_free(primary_keys, MYF(0));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
create_schema(MYSQL *mysql, const char *db, statement *stmt,
|
|
option_string *engine_stmt)
|
|
{
|
|
char query[HUGE_STRING_LENGTH];
|
|
statement *ptr;
|
|
statement *after_create;
|
|
int len;
|
|
ulonglong count;
|
|
DBUG_ENTER("create_schema");
|
|
|
|
len= snprintf(query, HUGE_STRING_LENGTH, "CREATE SCHEMA `%s`", db);
|
|
|
|
if (verbose >= 2)
|
|
printf("Loading Pre-data\n");
|
|
|
|
if (run_query(mysql, query, len))
|
|
{
|
|
fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
|
|
mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
|
|
if (opt_only_print)
|
|
{
|
|
printf("use %s;\n", db);
|
|
}
|
|
else
|
|
{
|
|
if (verbose >= 3)
|
|
printf("%s;\n", query);
|
|
|
|
if (mysql_select_db(mysql, db))
|
|
{
|
|
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
|
|
mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if (engine_stmt)
|
|
{
|
|
len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
|
|
engine_stmt->string);
|
|
if (run_query(mysql, query, len))
|
|
{
|
|
fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
|
|
mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
count= 0;
|
|
after_create= stmt;
|
|
|
|
limit_not_met:
|
|
for (ptr= after_create; ptr && ptr->length; ptr= ptr->next, count++)
|
|
{
|
|
if (auto_generate_sql && ( auto_generate_sql_number == count))
|
|
break;
|
|
|
|
if (engine_stmt && engine_stmt->option && ptr->type == CREATE_TABLE_TYPE)
|
|
{
|
|
char buffer[HUGE_STRING_LENGTH];
|
|
|
|
snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
|
|
engine_stmt->option);
|
|
if (run_query(mysql, buffer, strlen(buffer)))
|
|
{
|
|
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
|
|
my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (run_query(mysql, ptr->string, ptr->length))
|
|
{
|
|
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
|
|
my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (auto_generate_sql && (auto_generate_sql_number > count ))
|
|
{
|
|
/* Special case for auto create, we don't want to create tables twice */
|
|
after_create= stmt->next;
|
|
goto limit_not_met;
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
static int
|
|
drop_schema(MYSQL *mysql, const char *db)
|
|
{
|
|
char query[HUGE_STRING_LENGTH];
|
|
int len;
|
|
DBUG_ENTER("drop_schema");
|
|
len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
|
|
|
|
if (run_query(mysql, query, len))
|
|
{
|
|
fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
|
|
my_progname, db, mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
static int
|
|
run_statements(MYSQL *mysql, statement *stmt)
|
|
{
|
|
statement *ptr;
|
|
DBUG_ENTER("run_statements");
|
|
|
|
for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
|
|
{
|
|
if (run_query(mysql, ptr->string, ptr->length))
|
|
{
|
|
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
|
|
my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
static int
|
|
run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit)
|
|
{
|
|
uint x;
|
|
struct timeval start_time, end_time;
|
|
thread_context con;
|
|
pthread_t mainthread; /* Thread descriptor */
|
|
pthread_attr_t attr; /* Thread attributes */
|
|
DBUG_ENTER("run_scheduler");
|
|
|
|
con.stmt= stmts;
|
|
con.limit= limit;
|
|
|
|
pthread_attr_init(&attr);
|
|
pthread_attr_setdetachstate(&attr,
|
|
PTHREAD_CREATE_DETACHED);
|
|
|
|
pthread_mutex_lock(&counter_mutex);
|
|
thread_counter= 0;
|
|
|
|
pthread_mutex_lock(&sleeper_mutex);
|
|
master_wakeup= 1;
|
|
pthread_mutex_unlock(&sleeper_mutex);
|
|
for (x= 0; x < concur; x++)
|
|
{
|
|
/* now you create the thread */
|
|
if (pthread_create(&mainthread, &attr, run_task,
|
|
(void *)&con) != 0)
|
|
{
|
|
fprintf(stderr,"%s: Could not create thread\n",
|
|
my_progname);
|
|
exit(0);
|
|
}
|
|
thread_counter++;
|
|
}
|
|
pthread_mutex_unlock(&counter_mutex);
|
|
pthread_attr_destroy(&attr);
|
|
|
|
pthread_mutex_lock(&sleeper_mutex);
|
|
master_wakeup= 0;
|
|
pthread_mutex_unlock(&sleeper_mutex);
|
|
pthread_cond_broadcast(&sleep_threshhold);
|
|
|
|
gettimeofday(&start_time, NULL);
|
|
|
|
/*
|
|
We loop until we know that all children have cleaned up.
|
|
*/
|
|
pthread_mutex_lock(&counter_mutex);
|
|
while (thread_counter)
|
|
{
|
|
struct timespec abstime;
|
|
|
|
set_timespec(abstime, 3);
|
|
pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
|
|
}
|
|
pthread_mutex_unlock(&counter_mutex);
|
|
|
|
gettimeofday(&end_time, NULL);
|
|
|
|
|
|
sptr->timing= timedif(end_time, start_time);
|
|
sptr->users= concur;
|
|
sptr->rows= limit;
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
pthread_handler_t run_task(void *p)
|
|
{
|
|
ulonglong counter= 0, queries;
|
|
MYSQL *mysql;
|
|
MYSQL_RES *result;
|
|
MYSQL_ROW row;
|
|
statement *ptr;
|
|
thread_context *con= (thread_context *)p;
|
|
|
|
DBUG_ENTER("run_task");
|
|
DBUG_PRINT("info", ("task script \"%s\"", con->stmt ? con->stmt->string : ""));
|
|
|
|
pthread_mutex_lock(&sleeper_mutex);
|
|
while (master_wakeup)
|
|
{
|
|
pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
|
|
}
|
|
pthread_mutex_unlock(&sleeper_mutex);
|
|
|
|
if (!(mysql= mysql_init(NULL)))
|
|
{
|
|
fprintf(stderr,"%s: mysql_init() failed ERROR : %s\n",
|
|
my_progname, mysql_error(mysql));
|
|
exit(0);
|
|
}
|
|
|
|
if (mysql_thread_init())
|
|
{
|
|
fprintf(stderr,"%s: mysql_thread_init() failed ERROR : %s\n",
|
|
my_progname, mysql_error(mysql));
|
|
exit(0);
|
|
}
|
|
|
|
DBUG_PRINT("info", ("trying to connect to host %s as user %s", host, user));
|
|
|
|
if (!opt_only_print)
|
|
{
|
|
/* Connect to server */
|
|
static ulong connection_retry_sleep= 100000; /* Microseconds */
|
|
int i, connect_error= 1;
|
|
for (i= 0; i < 10; i++)
|
|
{
|
|
if (mysql_real_connect(mysql, host, user, opt_password,
|
|
create_schema_string,
|
|
opt_mysql_port,
|
|
opt_mysql_unix_port,
|
|
connect_flags))
|
|
{
|
|
/* Connect suceeded */
|
|
connect_error= 0;
|
|
break;
|
|
}
|
|
my_sleep(connection_retry_sleep);
|
|
}
|
|
if (connect_error)
|
|
{
|
|
fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
|
|
my_progname, mysql_errno(mysql), mysql_error(mysql));
|
|
goto end;
|
|
}
|
|
}
|
|
DBUG_PRINT("info", ("connected."));
|
|
if (verbose >= 3)
|
|
printf("connected!\n");
|
|
queries= 0;
|
|
|
|
limit_not_met:
|
|
for (ptr= con->stmt; ptr && ptr->length; ptr= ptr->next)
|
|
{
|
|
/*
|
|
We have to execute differently based on query type. This should become a function.
|
|
*/
|
|
if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
|
|
(ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
|
|
{
|
|
int length;
|
|
unsigned int key_val;
|
|
char *key;
|
|
char buffer[HUGE_STRING_LENGTH];
|
|
|
|
/*
|
|
This should only happen if some sort of new engine was
|
|
implemented that didn't properly handle UPDATEs.
|
|
|
|
Just in case someone runs this under an experimental engine we don't
|
|
want a crash so the if() is placed here.
|
|
*/
|
|
DBUG_ASSERT(primary_keys_number_of);
|
|
if (primary_keys_number_of)
|
|
{
|
|
key_val= (unsigned int)(random() % primary_keys_number_of);
|
|
key= primary_keys[key_val];
|
|
|
|
DBUG_ASSERT(key);
|
|
|
|
length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
|
|
(int)ptr->length, ptr->string, key);
|
|
|
|
if (run_query(mysql, buffer, length))
|
|
{
|
|
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
|
|
my_progname, (uint)length, buffer, mysql_error(mysql));
|
|
exit(0);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (run_query(mysql, ptr->string, ptr->length))
|
|
{
|
|
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
|
|
my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
if (mysql_field_count(mysql))
|
|
{
|
|
result= mysql_store_result(mysql);
|
|
while ((row = mysql_fetch_row(result)))
|
|
counter++;
|
|
mysql_free_result(result);
|
|
}
|
|
queries++;
|
|
|
|
if (con->limit && queries == con->limit)
|
|
goto end;
|
|
}
|
|
|
|
if (con->limit && queries < con->limit)
|
|
goto limit_not_met;
|
|
|
|
end:
|
|
|
|
if (!opt_only_print)
|
|
mysql_close(mysql);
|
|
|
|
my_thread_end();
|
|
|
|
pthread_mutex_lock(&counter_mutex);
|
|
thread_counter--;
|
|
pthread_cond_signal(&count_threshhold);
|
|
pthread_mutex_unlock(&counter_mutex);
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
uint
|
|
parse_option(const char *origin, option_string **stmt, char delm)
|
|
{
|
|
char *retstr;
|
|
char *ptr= (char *)origin;
|
|
option_string **sptr= stmt;
|
|
option_string *tmp;
|
|
uint length= strlen(origin);
|
|
uint count= 0; /* We know that there is always one */
|
|
|
|
for (tmp= *sptr= (option_string *)my_malloc(sizeof(option_string),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
(retstr= strchr(ptr, delm));
|
|
tmp->next= (option_string *)my_malloc(sizeof(option_string),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
|
|
tmp= tmp->next)
|
|
{
|
|
char buffer[HUGE_STRING_LENGTH];
|
|
char *buffer_ptr;
|
|
|
|
count++;
|
|
strncpy(buffer, ptr, (size_t)(retstr - ptr));
|
|
if ((buffer_ptr= strchr(buffer, ':')))
|
|
{
|
|
char *option_ptr;
|
|
|
|
tmp->length= (size_t)(buffer_ptr - buffer);
|
|
tmp->string= my_strndup(ptr, (uint)tmp->length, MYF(MY_FAE));
|
|
|
|
option_ptr= ptr + 1 + tmp->length;
|
|
|
|
/* Move past the : and the first string */
|
|
tmp->option_length= (size_t)(retstr - option_ptr);
|
|
tmp->option= my_strndup(option_ptr, (uint)tmp->option_length,
|
|
MYF(MY_FAE));
|
|
}
|
|
else
|
|
{
|
|
tmp->string= my_strndup(ptr, (size_t)(retstr - ptr), MYF(MY_FAE));
|
|
tmp->length= (size_t)(retstr - ptr);
|
|
}
|
|
|
|
ptr+= retstr - ptr + 1;
|
|
if (isspace(*ptr))
|
|
ptr++;
|
|
count++;
|
|
}
|
|
|
|
if (ptr != origin+length)
|
|
{
|
|
char *origin_ptr;
|
|
|
|
if ((origin_ptr= strchr(ptr, ':')))
|
|
{
|
|
char *option_ptr;
|
|
|
|
tmp->length= (size_t)(origin_ptr - ptr);
|
|
tmp->string= my_strndup(origin, tmp->length, MYF(MY_FAE));
|
|
|
|
option_ptr= (char *)ptr + 1 + tmp->length;
|
|
|
|
/* Move past the : and the first string */
|
|
tmp->option_length= (size_t)((ptr + length) - option_ptr);
|
|
tmp->option= my_strndup(option_ptr, tmp->option_length,
|
|
MYF(MY_FAE));
|
|
}
|
|
else
|
|
{
|
|
tmp->length= (size_t)((ptr + length) - ptr);
|
|
tmp->string= my_strndup(ptr, tmp->length, MYF(MY_FAE));
|
|
}
|
|
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
|
|
uint
|
|
parse_delimiter(const char *script, statement **stmt, char delm)
|
|
{
|
|
char *retstr;
|
|
char *ptr= (char *)script;
|
|
statement **sptr= stmt;
|
|
statement *tmp;
|
|
uint length= strlen(script);
|
|
uint count= 0; /* We know that there is always one */
|
|
|
|
for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
(retstr= strchr(ptr, delm));
|
|
tmp->next= (statement *)my_malloc(sizeof(statement),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
|
|
tmp= tmp->next)
|
|
{
|
|
count++;
|
|
tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
|
|
tmp->length= (size_t)(retstr - ptr);
|
|
ptr+= retstr - ptr + 1;
|
|
if (isspace(*ptr))
|
|
ptr++;
|
|
count++;
|
|
}
|
|
|
|
if (ptr != script+length)
|
|
{
|
|
tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
|
|
MYF(MY_FAE));
|
|
tmp->length= (size_t)((script + length) - ptr);
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
|
|
uint
|
|
parse_comma(const char *string, uint **range)
|
|
{
|
|
uint count= 1,x; /* We know that there is always one */
|
|
char *retstr;
|
|
char *ptr= (char *)string;
|
|
uint *nptr;
|
|
|
|
for (;*ptr; ptr++)
|
|
if (*ptr == ',') count++;
|
|
|
|
/* One extra spot for the NULL */
|
|
nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
|
|
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
|
|
|
|
ptr= (char *)string;
|
|
x= 0;
|
|
while ((retstr= strchr(ptr,',')))
|
|
{
|
|
nptr[x++]= atoi(ptr);
|
|
ptr+= retstr - ptr + 1;
|
|
}
|
|
nptr[x++]= atoi(ptr);
|
|
|
|
return count;
|
|
}
|
|
|
|
void
|
|
print_conclusions(conclusions *con)
|
|
{
|
|
printf("Benchmark\n");
|
|
if (con->engine)
|
|
printf("\tRunning for engine %s\n", con->engine);
|
|
printf("\tAverage number of seconds to run all queries: %ld.%03ld seconds\n",
|
|
con->avg_timing / 1000, con->avg_timing % 1000);
|
|
printf("\tMinimum number of seconds to run all queries: %ld.%03ld seconds\n",
|
|
con->min_timing / 1000, con->min_timing % 1000);
|
|
printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
|
|
con->max_timing / 1000, con->max_timing % 1000);
|
|
printf("\tNumber of clients running queries: %d\n", con->users);
|
|
printf("\tAverage number of queries per client: %llu\n", con->avg_rows);
|
|
printf("\n");
|
|
}
|
|
|
|
void
|
|
print_conclusions_csv(conclusions *con)
|
|
{
|
|
char buffer[HUGE_STRING_LENGTH];
|
|
const char *ptr= auto_generate_sql_type ? auto_generate_sql_type : "query";
|
|
snprintf(buffer, HUGE_STRING_LENGTH,
|
|
"%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%d,%llu\n",
|
|
con->engine ? con->engine : "", /* Storage engine we ran against */
|
|
ptr, /* Load type */
|
|
con->avg_timing / 1000, con->avg_timing % 1000, /* Time to load */
|
|
con->min_timing / 1000, con->min_timing % 1000, /* Min time */
|
|
con->max_timing / 1000, con->max_timing % 1000, /* Max time */
|
|
con->users, /* Children used */
|
|
con->avg_rows /* Queries run */
|
|
);
|
|
my_write(csv_file, buffer, (uint)strlen(buffer), MYF(0));
|
|
}
|
|
|
|
void
|
|
generate_stats(conclusions *con, option_string *eng, stats *sptr)
|
|
{
|
|
stats *ptr;
|
|
unsigned int x;
|
|
|
|
con->min_timing= sptr->timing;
|
|
con->max_timing= sptr->timing;
|
|
con->min_rows= sptr->rows;
|
|
con->max_rows= sptr->rows;
|
|
|
|
/* At the moment we assume uniform */
|
|
con->users= sptr->users;
|
|
con->avg_rows= sptr->rows;
|
|
|
|
/* With no next, we know it is the last element that was malloced */
|
|
for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
|
|
{
|
|
con->avg_timing+= ptr->timing;
|
|
|
|
if (ptr->timing > con->max_timing)
|
|
con->max_timing= ptr->timing;
|
|
if (ptr->timing < con->min_timing)
|
|
con->min_timing= ptr->timing;
|
|
}
|
|
con->avg_timing= con->avg_timing/iterations;
|
|
|
|
if (eng && eng->string)
|
|
con->engine= eng->string;
|
|
else
|
|
con->engine= NULL;
|
|
}
|
|
|
|
void
|
|
option_cleanup(option_string *stmt)
|
|
{
|
|
option_string *ptr, *nptr;
|
|
if (!stmt)
|
|
return;
|
|
|
|
for (ptr= stmt; ptr; ptr= nptr)
|
|
{
|
|
nptr= ptr->next;
|
|
if (ptr->string)
|
|
my_free(ptr->string, MYF(0));
|
|
if (ptr->option)
|
|
my_free(ptr->option, MYF(0));
|
|
my_free(ptr, MYF(0));
|
|
}
|
|
}
|
|
|
|
void
|
|
statement_cleanup(statement *stmt)
|
|
{
|
|
statement *ptr, *nptr;
|
|
if (!stmt)
|
|
return;
|
|
|
|
for (ptr= stmt; ptr; ptr= nptr)
|
|
{
|
|
nptr= ptr->next;
|
|
if (ptr->string)
|
|
my_free(ptr->string, MYF(0));
|
|
my_free(ptr, MYF(0));
|
|
}
|
|
}
|