diff options
444 files changed, 17002 insertions, 18448 deletions
diff --git a/.bzrignore b/.bzrignore index 18ad5e18be6..dd77bcb1d12 100644 --- a/.bzrignore +++ b/.bzrignore @@ -38,7 +38,11 @@ COPYING.LIB Docs/#manual.texi# Docs/INSTALL-BINARY Docs/include.texi +Docs/internals.html Docs/internals.info +Docs/internals.pdf +Docs/internals.txt +Docs/internals_toc.html Docs/manual.aux Docs/manual.cp Docs/manual.cps @@ -239,6 +243,7 @@ client/select_test client/ssl_test client/thimble client/thread_test +client_test cmd-line-utils/libedit/common.h comon.h config.cache @@ -272,6 +277,7 @@ help.h include/my_config.h include/my_global.h include/mysql_version.h +include/readline/*.h include/readline/readline.h include/widec.h innobase/autom4te-2.53.cache/output.0 @@ -287,6 +293,7 @@ innobase/conftest.subs innobase/ib_config.h innobase/ib_config.h.in innobase/stamp-h1 +insert_test isam/isamchk isam/isamlog isam/pack_isam @@ -341,6 +348,7 @@ libmysqld/item_buff.cc libmysqld/item_cmpfunc.cc libmysqld/item_create.cc libmysqld/item_func.cc +libmysqld/item_geofunc.cc libmysqld/item_row.cc libmysqld/item_strfunc.cc libmysqld/item_sum.cc @@ -497,6 +505,7 @@ scripts/make_win_src_distribution scripts/msql2mysql scripts/mysql_config scripts/mysql_convert_table_format +scripts/mysql_create_system_tables scripts/mysql_explain_log scripts/mysql_find_rows scripts/mysql_fix_extensions @@ -513,6 +522,7 @@ scripts/mysqld_safe scripts/mysqldumpslow scripts/mysqlhotcopy scripts/safe_mysqld +select_test sql-bench/Results-linux/ATIS-mysql_bdb-Linux_2.2.14_my_SMP_i686 sql-bench/bench-count-distinct sql-bench/bench-init.pl @@ -578,6 +588,7 @@ strings/ctype_autoconf.c strings/ctype_extra_sources.c support-files/MacOSX/Description.plist support-files/MacOSX/Info.plist +support-files/MacOSX/ReadMe.txt support-files/MacOSX/StartupParameters.plist support-files/MacOSX/postinstall support-files/MacOSX/preinstall @@ -597,6 +608,7 @@ support-files/mysql.spec tags test_xml tests/client_test +thread_test tmp/* tools/my_vsnprintf.c tools/mysqlmanager @@ -607,7 +619,4 @@ vio/test-ssl vio/test-sslclient vio/test-sslserver vio/viotest-ssl -client_test -thread_test -select_test -insert_test +sql/client.c diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh index 9a092b84a8f..4a19c490e5d 100644 --- a/BUILD/SETUP.sh +++ b/BUILD/SETUP.sh @@ -52,7 +52,7 @@ debug_cflags="-DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -DSAFEMA base_cxxflags="-felide-constructors -fno-exceptions -fno-rtti" -base_configs="--prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client" +base_configs="--prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-readline" static_link="--with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static" alpha_configs="" # Not used yet pentium_configs="" @@ -71,4 +71,6 @@ else make=make fi -CXX=gcc +if test -z $CXX ; then + CXX=gcc +fi diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index b6f9647ea49..5fc0be183e1 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -5,6 +5,7 @@ Administrator@fred. Miguel@light.local Sinisa@sinisa.nasamreza.org WAX@sergbook.mysql.com +administrador@light.hegel.local ahlentz@co3064164-a.rochd1.qld.optusnet.com.au akishkin@work.mysql.com arjen@co3064164-a.bitbike.com @@ -28,6 +29,7 @@ heikki@rescue. heikki@work.mysql.com hf@bison.(none) hf@bisonxp.(none) +hf@deer.(none) hf@deer.mysql.r18.ru hf@genie.(none) igor@hundin.mysql.fi @@ -51,6 +53,7 @@ miguel@hegel.br miguel@hegel.local miguel@light. miguel@light.local +mmatthew@markslaptop. monty@bitch.mysql.fi monty@butch. monty@donna.mysql.fi @@ -67,6 +70,7 @@ mwagner@cash.mwagner.org mwagner@evoq.mwagner.org mwagner@work.mysql.com mysql@home.(none) +mysqldev@build.mysql2.com nick@mysql.com nick@nick.leippe.com papa@gbichot.local @@ -75,6 +79,7 @@ paul@teton.kitebird.com pem@mysql.com peter@linux.local peter@mysql.com +peterg@mysql.com pgulutzan@linux.local ram@gw.udmsearch.izhnet.ru ram@mysql.r18.ru @@ -110,6 +115,7 @@ venu@myvenu.com venu@work.mysql.com vva@eagle.mysql.r18.ru vva@genie.(none) +vva@mysql.r18.ru walrus@kishkin.ru walrus@mysql.com wax@kishkin.ru diff --git a/Build-tools/Do-compile b/Build-tools/Do-compile index b499e3059b3..07657c0bdeb 100755 --- a/Build-tools/Do-compile +++ b/Build-tools/Do-compile @@ -276,7 +276,11 @@ if ($opt_stage <= 3) my $flags= ""; log_timestamp(); log_system("rm -fr mysql-3* mysql-4* $pwd/$host/*.tar.gz"); - log_system("nm -n sql/mysqld | gzip -9 -v 2>&1 > sql/mysqld.sym.gz | cat"); + # No need to add the debug symbols, if the binaries are not stripped (saves space) + unless ($opt_with_debug || $opt_no_strip) + { + log_system("nm -n sql/mysqld | gzip -9 -v 2>&1 > sql/mysqld.sym.gz | cat"); + } $flags.= "--no-strip" if ($opt_no_strip || $opt_with_debug); check_system("scripts/make_binary_distribution --tmp=$opt_tmp --suffix=$opt_suffix $flags",".tar.gz created"); diff --git a/Docs/Makefile.am b/Docs/Makefile.am index af771a5728d..cf0a4632eda 100644 --- a/Docs/Makefile.am +++ b/Docs/Makefile.am @@ -27,7 +27,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) $(BUILT_SOURCES) mysqld_error.txt \ all: $(targets) txt_files txt_files: ../INSTALL-SOURCE ../COPYING ../COPYING.LIB \ - INSTALL-BINARY + INSTALL-BINARY ../support-files/MacOSX/ReadMe.txt CLEAN_FILES: $(BUILD_SOURCES) touch $(BUILD_SOURCES) @@ -156,54 +156,6 @@ manual_letter.de.ps: manual.de.texi include.texi $(DVIPS) -t letter manual.de.dvi -o $@ touch $@ - -# -# Internals Manual -# - -# GNU Info -internals.info: internals.texi include.texi - cd $(srcdir) && $(MAKEINFO) --no-split -I $(srcdir) $< - -# Plain Text -internals.txt: internals.texi include.texi - cd $(srcdir) && \ - $(MAKEINFO) -I $(srcdir) --no-headers --no-split --output $@ $< - -# HTML, all in one file -internals.html: internals.texi include.texi $(srcdir)/Support/texi2html - cd $(srcdir) && @PERL@ $(srcdir)/Support/texi2html $(TEXI2HTML_FLAGS) $< -internals_toc.html: internals.html - -# PDF, Portable Document Format -internals.pdf: internals.texi - sed -e 's|@image{[^}]*} *||g' <$< >internals-tmp.texi - pdftex --interaction=nonstopmode internals-tmp.texi - texindex internals-tmp.?? - pdftex --interaction=nonstopmode internals-tmp.texi - texindex internals-tmp.?? - pdftex --interaction=nonstopmode internals-tmp.texi - mv internals-tmp.pdf $@ - rm -f internals-tmp.* - touch $@ - -# Postscript, A4 Paper -internals_a4.ps: internals.texi include.texi - TEXINPUTS=$(srcdir):$$TEXINPUTS \ - MAKEINFO='$(MAKEINFO) -I $(srcdir)' \ - $(TEXI2DVI) --batch --texinfo --quiet '@afourpaper' $< - $(DVIPS) -t a4 internals.dvi -o $@ - touch $@ - -# Postscript, US Letter Paper -internals_letter.ps: internals.texi include.texi - TEXINPUTS=$(srcdir):$$TEXINPUTS \ - MAKEINFO='$(MAKEINFO) -I $(srcdir)' \ - $(TEXI2DVI) --batch $< - $(DVIPS) -t letter internals.dvi -o $@ - touch $@ - - # # Miscellaneous # @@ -254,5 +206,8 @@ INSTALL-BINARY: mysql.info $(GT) ../COPYING.LIB: mysql.info $(GT) perl -w $(GT) mysql.info "LGPL license" "Function Index" > $@ +../support-files/MacOSX/ReadMe.txt: mysql.info $(GT) + perl -w $(GT) mysql.info "Mac OS X installation" "Netware installation" > $@ + # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/Docs/internals.texi b/Docs/internals.texi deleted file mode 100644 index 9f9b08b96c3..00000000000 --- a/Docs/internals.texi +++ /dev/null @@ -1,6426 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@c Copyright 2002 MySQL AB -@c -@c %**start of header -@setfilename internals.info - -@c We want the types in the same index -@synindex cp fn - -@iftex -@afourpaper -@end iftex - -@c Get version and other info -@include include.texi - -@ifclear tex-debug -@c This removes the black squares in the right margin -@finalout -@end ifclear - -@c Set background for HTML -@set _body_tags BGCOLOR=#FFFFFF TEXT=#000000 LINK=#101090 VLINK=#7030B0 -@settitle @strong{MySQL} Internals Manual for version @value{mysql_version}. -@setchapternewpage odd -@paragraphindent 0 - -@c %**end of header - -@ifinfo -@format -START-INFO-DIR-ENTRY -* mysql-internals: (mysql-internals). @strong{MySQL} internals. -END-INFO-DIR-ENTRY -@end format -@end ifinfo - -@titlepage -@sp 10 -@center @titlefont{@strong{MySQL} Internals Manual} -@sp 10 -@center Copyright @copyright{} 1998-2002 MySQL AB -@page -@end titlepage - -@node Top, caching, (dir), (dir) - -@ifinfo -This is a manual about @strong{MySQL} internals. -@end ifinfo - -@menu -* caching:: How MySQL Handles Caching -* join_buffer_size:: -* flush tables:: How MySQL Handles @code{FLUSH TABLES} -* filesort:: How MySQL Does Sorting (@code{filesort}) -* selects:: How MySQL performs different selects -* transformations:: How MySQL transforms subqueries -* coding guidelines:: Coding Guidelines -* mysys functions:: Functions In The @code{mysys} Library -* DBUG:: DBUG Tags To Use -* protocol:: MySQL Client/Server Protocol -* Fulltext Search:: Fulltext Search in MySQL -* MyISAM Record Structure:: MyISAM Record Structure -* InnoDB Record Structure:: InnoDB Record Structure -* InnoDB Page Structure:: InnoDB Page Structure -* Files in MySQL Sources:: Annotated List Of Files in the MySQL Source Code Distribution -* Files in InnoDB Sources:: Annotated List Of Files in the InnoDB Source Code Distribution -@end menu - - -@node caching, join_buffer_size, Top, Top -@chapter How MySQL Handles Caching - -@strong{MySQL} has the following caches: -(Note that the some of the filename have a wrong spelling of cache. :) - -@table @strong - -@item Key Cache -A shared cache for all B-tree index blocks in the different NISAM -files. Uses hashing and reverse linked lists for quick caching of the -last used blocks and quick flushing of changed entries for a specific -table. (@file{mysys/mf_keycash.c}) - -@item Record Cache -This is used for quick scanning of all records in a table. -(@file{mysys/mf_iocash.c} and @file{isam/_cash.c}) - -@item Table Cache -This holds the last used tables. (@file{sql/sql_base.cc}) - -@item Hostname Cache -For quick lookup (with reverse name resolving). Is a must when one has a -slow DNS. -(@file{sql/hostname.cc}) - -@item Privilege Cache -To allow quick change between databases the last used privileges are -cached for each user/database combination. -(@file{sql/sql_acl.cc}) - -@item Heap Table Cache -Many use of @code{GROUP BY} or @code{DISTINCT} caches all found rows in -a @code{HEAP} table. (This is a very quick in-memory table with hash index.) - -@item Join buffer Cache -For every full join in a @code{SELECT} statement (a full join here means -there were no keys that one could use to find the next table in a list), -the found rows are cached in a join cache. One @code{SELECT} query can -use many join caches in the worst case. -@end table - -@node join_buffer_size, flush tables, caching, Top -@chapter How MySQL uses the join_buffer cache - -Basic information about @code{join_buffer_size}: - -@itemize @bullet -@item -It's only used in the case when join type is of type @code{ALL} or -@code{index}; In other words: no possible keys can be used. -@item -A join buffer is never allocated for the first not-const table, -even it it would be of type @code{ALL}/@code{index}. -@item -The buffer is allocated when we need to do a each full join between two -tables and freed after the query is done. -@item -Accepted row combinations of tables before the @code{ALL}/@code{index} -able is stored in the cache and is used to compare against each read -row in the @code{ALL} table. -@item -We only store the used fields in the join_buffer cache, not the -whole rows. -@end itemize - -Assume you have the following join: - -@example -Table name Type -t1 range -t2 ref -t3 @code{ALL} -@end example - -The join is then done as follows: - -@example -- While rows in t1 matching range - - Read through all rows in t2 according to reference key - - Store used fields form t1,t2 in cache - - If cache is full - - Read through all rows in t3 - - Compare t3 row against all t1,t2 combination in cache - - If rows satisfying join condition, send it to client - - Empty cache - -- Read through all rows in t3 - - Compare t3 row against all stored t1,t2 combinations in cache - - If rows satisfying join condition, send it to client -@end example - -The above means that table t3 is scanned - -@example -(size-of-stored-row(t1,t2) * accepted-row-cominations(t1,t2))/ -join_buffer_size+1 -@end example -times. - -Some conclusions: - -@itemize @bullet -@item -The larger the join_buff_size, the fewer scans of t3. -If @code{join_buff_size} is already large enough to hold all previous row -combinations then there is no speed to gain by making it bigger. -@item -If there is several tables of @code{ALL}/@code{index} then the we -allocate one @code{join_buffer_size buffer} for each of them and use the -same algorithm described above to handle it. (In other words, we store -the same row combination several times into different buffers) -@end itemize - -@node flush tables, filesort, join_buffer_size, Top -@chapter How MySQL Handles @code{FLUSH TABLES} - -@itemize @bullet - -@item -Flush tables is handled in @file{sql/sql_base.cc::close_cached_tables()}. - -@item -The idea of flush tables is to force all tables to be closed. This -is mainly to ensure that if someone adds a new table outside of -@strong{MySQL} (for example with @code{cp}) all threads will start using -the new table. This will also ensure that all table changes are flushed -to disk (but of course not as optimally as simple calling a sync on -all tables)! - -@item -When one does a @code{FLUSH TABLES}, the variable @code{refresh_version} -will be incremented. Every time a thread releases a table it checks if -the refresh version of the table (updated at open) is the same as -the current @code{refresh_version}. If not it will close it and broadcast -a signal on @code{COND_refresh} (to wait any thread that is waiting for -all instanses of a table to be closed). - -@item -The current @code{refresh_version} is also compared to the open -@code{refresh_version} after a thread gets a lock on a table. If the -refresh version is different the thread will free all locks, reopen the -table and try to get the locks again; This is just to quickly get all -tables to use the newest version. This is handled by -@file{sql/lock.cc::mysql_lock_tables()} and -@file{sql/sql_base.cc::wait_for_tables()}. - -@item -When all tables has been closed @code{FLUSH TABLES} will return an ok -to client. - -@item -If the thread that is doing @code{FLUSH TABLES} has a lock on some tables, -it will first close the locked tables, then wait until all other threads -have also closed them, and then reopen them and get the locks. -After this it will give other threads a chance to open the same tables. - -@end itemize - -@node filesort, selects, flush tables, Top -@chapter How MySQL Does Sorting (@code{filesort}) - -@itemize @bullet - -@item -Read all rows according to key or by table scanning. - -@item -Store the sort-key in a buffer (@code{sort_buffer}). - -@item -When the buffer gets full, run a @code{qsort} on it and store the result -in a temporary file. Save a pointer to the sorted block. - -@item -Repeat the above until all rows have been read. - -@item -Repeat the following until there is less than @code{MERGEBUFF2} (15) -blocks left. - -@item -Do a multi-merge of up to @code{MERGEBUFF} (7) regions to one block in -another temporary file. Repeat until all blocks from the first file -are in the second file. - -@item -On the last multi-merge, only the pointer to the row (last part of -the sort-key) is written to a result file. - -@item -Now the code in @file{sql/records.cc} will be used to read through them -in sorted order by using the row pointers in the result file. -To optimize this, we read in a big block of row pointers, sort these -and then we read the rows in the sorted order into a row buffer -(@code{record_buffer}). - -@end itemize - -@node selects, transformations, flush tables, Top -@chapter How MySQL performs different selects - -@node select steps,,, -@section Steps of select executing - -Every select performed in such base steps: -@itemize -@item - JOIN::prepare -@itemize @bullet -@item - initialization and linking JOIN structure to st_select_lex -@item - fix_fields() for all items (after fix_fields we know everything - about item) -@item - moving HAVING to WHERE if possible -@item - initialization procedure if exists -@end itemize -@item - JOIN::optimize -@itemize @bullet -@item - single select optimization -@item - creation first temporary table if need -@end itemize -@item - JOIN::exec -@itemize @bullet -@item - performing select (may be created second temporary table) -@end itemize -@item - JOIN::cleanup -@itemize @bullet -@item - removing all temporary tables, other cleanup -@end itemize -@item - JOIN::reinit -@itemize @bullet -@item - prepare all structures to SELECT executing (with JOIN::exec) -@end itemize -@end itemize - -@node select select_result -@section select_result CLASS - -Very important role in SELECT performing have select_result class and -classes inherited from it (usually called with "select_" prefix). This -class provide interface for results transmitting. - -Key methods in this class are following: -@itemize @bullet -@item - @strong{send_fields} sends giving item list headers (type, name, etc..) -@item - @strong{send_data} sends giving item list values as row of table of result -@item - @strong{send_error} send error to used used mainly for error interception, - making some operation and then ::send_error will be called. -@end itemize - -For example there are fillowing select_result classes: -@itemize -@item - @strong{select_send} used for sending results though network layer -@item - @strong{select_export} used for exporting data to file -@item - @strong{multi_delete} used for multi-delete -@item - @strong{select_insert} used for INSERT ... SELECT ... -@item - @strong{multi_update} used for multi-update -@end itemize - -@node select simple -@section SIMPLE or PRIMARY SELECT. - -For performing single primary select SELECT used function mysql_select, -which: -@itemize @bullet -@item - allocate JOIN; -@item - JOIN::prepare; -@item - JOIN::optimize; -@item - JOIN::exec; -@item - JOIN::cleanup. -@end itemize -In previous versions of mysql all SELECTs was performed with help of this -function and mysql_select() was not divided on parts. - -@node select structure -@section Structure Of Complex Select - -There 2 structures which describe SELECTS: -@itemize @bullet -@item - st_select_lex (SELECT_LEX) it represent SELECT itself -@item - st_select_lex_unit (SELECT_LEX_UNIT) group several selects in bunch -@end itemize -and represent UNION operation (absence of UNION is union -with 1 SELECT and this structure present in any case). In future this -structure will be used for EXCEPT and INTERSECT. - -For example: -@example -(SELECT ... )UNION(SELECT ... (SELECT...)...(SELECT...UNION...SELECT)) - 1 2 3 4 5 6 7 -@end example - -will be represent as -@example ------------------------------------------------------------------------- - level 1 -SELECT_LEX_UNIT(2) -| -+---------------+ -| | -SELECT_LEX(1) SELECT_LEX(3) - | ---------------- | ------------------------------------------------------ - | level 2 - +-------------------+ - | | - SELECT_LEX_UNIT(4) SELECT_LEX_UNIT(6) - | | - | +--------------+ - | | | - SELECT_LEX(4) SELECT_LEX(5) SELECT_LEX(7) - ------------------------------------------------------------------------- -@end example -Note: single subselect 4 have it's own SELECT_LEX_UNIT. - -Most upper SELECT_LEX_UNIT (#2 in example) stored in LEX. -First and most upper SELECT_LEX (#1 in example) stored in LEX, too. -This two structures always exist. - -In time of creating or performing any JOIN::* operation -LEX::current_select point on appropriate SELECT_LEX. - -Only during parsing global (for whole UNION) ORDER_BY & LIMIT clauses -LEX::current_select points to SELECT_LEX_UNIT of this unit to store this -parameter in this SELECT_LEX_UNIT (SELECT_LEX and SELECT_LEX_UNIT are -inherited from st_select_lex_node). - -@node select union -@section Non-Subselect UNIONs Executing - -Non subselect unions performed with help of mysql_union(). for now it -divided on following steps: -@itemize -@item - st_select_lex_unit::prepare -@itemize @bullet -@item - create temporary table for union results storing (if UNION witout - ALL option, 'distinct' parameter will be passed to table creation - procedure). Types/lengths of table's fields will be determinated - by first SELECT item list. -@item - create select_union (inherited from select_result) which will - write selects results in this temporary table -@item - allocate JOIN and perform JOIN::prepare for all SELECTs belonged - to UNION -@end itemize -@item - st_select_lex_unit::exec -@itemize @bullet -@item - delete rows from temporary table if it is not first call -@item - if first call call JOIN::optimize else JOIN::reinit and then - JOIN::exec for all SELECTs (select_union will write result for - temporary table). If union is cacheable and this method called - second, (third, ...) time it will do nothing. -@item - call mysql_select on temporary table with global ORDER BY and - LIMIT parameters after collecting results from all SELECTs. -@end itemize -@end itemize -As far as mysql_select need SELECT_LEX structure SELECT_LEX of first -SELECT of this UNION will be passed to it, but also fake_select_lex -parameter will be passed to mysql_select() too, to prevent linking -this SELECT_LEX with JOIN on this mysql_select() session. - -PROBLEM: this fake select need workaround in many places. - -@node select derived -@section Derived Tables Executing - -Derived tables processing is first operation on any query. It performed -before creation list of tables of whole query and opening/locking this -tables. - -If lex->derived_tables flag present will be scanned all SELECT_LEX (there -are list of all SELECT_LEX in reverse order (first SELECT in query will -be last in this list) lex->all_selects_list). - -Pointer on derived table SELECT_LEX_UNIT stored in TABLE_LIST structure -(TABLE_LIST::derived). And for any table which have this pointer will -be called mysql_derived(). - -mysql_derived(): -@itemize @bullet -@item - Creates list of all tables used in this query, opens and locks it -@item - Creates temporary table for storing results -@item - Creates union_result for writing result in this table -@item - Calls mysql_select or mysql_union for execute query -@item - Removes all derived table subtree from SELECTs tree (if it is - not EXPLAIN) -@item - Stores pointer to this temporary table in TABLE_LIST structure, then - this table will be used by outer query. This table table will not be - skipped in checking grants, because tables from which this table was - received was checked in mysql_derived. -@item - Links this temporary table in thd->derived_tables for removing after - query executing. this table will be closed in close_thread_tables if - second parameter of it (bool skip_derived) will be true. -@end itemize - -@node select subselect -@section Subselects - -In expression subselect represented by Item inherited from Item_subselect. - -To hide difference in performing single SELECTs and UNIONs -Item_subselect use two different engines, which provide uniformed -interface for access to underplaid SELECT or UNION -(subselect_single_select_engine and subselect_union_engine, both are -inherited from subselect_engine). - -Engine will be created in time of Item_select constructing -(Item_subselect::init method). - -On Item_subselect::fix_fields() will be called engine->prepare(). - -Before calling any value getting method (val, val_int, val_str, -bring_value (in case of row result)) will be called engine->exec(), -which execute query or just do nothing if subselect is cacheable and -already executed. - -Items inherited from provide it's own select_result classes. There are -2 type of it: -@itemize @bullet -@item - select_singlerow_subselect it store values of giving row in - Item_singlerow_subselect cache on send_data() call and report error - if Item_subselect have 'assigned' attribute. -@item - select_exists_subselect just store 1 as value of - Item_exists_subselect on send_data() call. As far as - Item_in_subselect and Item_allany_subselect inherited from - Item_exists_subselect, they use same select_result class. -@end itemize - -Item_select will never call cleanup() procedure for JOIN. Every -JOIN::cleanup will call cleanup() for inner JOINs. Most upper -JOIN::cleanup will be called by mysql_select() or mysql_union(). - -@node select select engine -@section Single Select Engine - -subselect_single_select_engine: -@itemize @bullet -@item - @strong{constructor} allocate JOIN and store pointers on SELECT_LEX and JOIN -@item - @strong{prepare()} call JOIN::prepare -@item - @strong{fix_length_and_dec()} prepare cache and receive type and - parameters of returning items (it called only by - Item_singlerow_subselect) -@item - @strong{exec()} drop 'assigned flag of Item_subselect. If called first time - JOIN::optimize and JOINexec(), else do nothing or JOIN::reinit() - JOIN::exec() depending of type of subquery. -@end itemize - -@node select union engine -@section Union Engine - -subselect_union_engine: -@itemize @bullet -@item - @strong{constructor} just store pointer to st_select_lex_union - (SELECT_LEX_UNION) -@item - @strong{prepare()} call st_select_lex_unit::prepare -@item - @strong{fix_length_and_dec()} prepare cache and receive type and - parameters (maximum of length) of returning items (it called - only by Item_singlerow_subselect) -@item - @strong{exec()} call st_select_lex_unit::exec(). st_select_lex_unit::exec() - can drop 'assigned' flag of Item_subselect if - st_select_lex_unit::item is not 0. -@end itemize - -@node selectexplain -@section Explain Execution - -For EXPLAIN result showing for every SELECT will be called mysql_select -with option SELECT_DESCRIBE. - -For main UNION will be called mysql_explain_union. - -mysql_explain_union call mysql_explain_select for every SELECT in given -union. - -mysql_explain_select call mysql_select with SELECT_DESCRIBE. - -mysql_select create JOIN for select (if it not exists, because if it -called for subselect JOIN can be created in JOIN::optimize of outer -query when it decided to calculate value of subselect). Then it call -JOIN::prepare, JOIN::optimize, JOIN exec and JOIN::cleanup as usual. - -JOIN::exec called for SELECT with SELECT_DESCRIBE option call -select_describe. - -select_describe return to user description of SELECT and call -mysql_explain_union for every inner UNION - -PROBLEM: how it will work with global query optimization? - -@node transformations, coding guidelines, selects, Top -@chapter How MySQL transforms subqueries - -Item_subselect virtual method select_transformer is used to rewrite -subqueries. It is called from Item_subselect::init (which called in -Item_subselect constructor) - -@node transformation IN -@section Item_in_subselect::select_transformer - -Item_in_subselect::select_transformer is divided on two parts for -scalar left part and row left part: - -@node transformation scalar IN -@subsection Scalar IN Subselect - -To rewrite scalar IN subselect used method -Item_in_subselect::single_value_transformer, Scalar IN subselect will -be replaced with Item_in_optimizer. - -Item_in_optimizer item is special boolean function. On value request -(one of val, val_int or val_str methods) it evaluate left expression of -IN by storing it value in cache item (one of Item_cache* items), then it -test cache is it NULL. If left expression (cache) is NULL then -Item_in_optimizer return NULL, else it evaluate Item_in_subselect. - -Example queries. -@example -a) SELECT * from t1 where t1.a in (SELECT t2.a FROM t2); -b) SELECT * from t1 where t1.a in (SELECT t2.a FROM t2 GROUP BY t2.a); -@end example - -@itemize -@item -Item_in_subselect inherit mechanism of getting value from - Item_exists_subselect. -@item -Select_transformer stores reference to left expression in its - conditions: (in WHERE & HAVING in case 'a' and in a HAVING in case 'b') -@item -Item from item list of this select (t2.a) can be referred with special - reference (Item_ref_null_helper or Item_asterisk_remover). - This reference informs Item_in_optimizer if item (t2.a) is NULL by - setting the 'was_null' flag. -@item -The return value from Item_in_subselect will be evaluated as following: -@itemize @bullet -@item - If TRUE return true -@item - If NULL return null -@item - If FALSE and 'was_null' is set, return null -@item - return FALSE -@end itemize -@end itemize - -<left_expression> IN (SELECT <item> ...) will be represented like -following: -@example - +-----------------+ - |Item_in_optimizer| - +-----------------+ - | - +---------------------+------------+ - | | -+-----------------------+ +-----------------+ -| <left_expression> | |Item_in_subselect| -| | +-----------------+ -+-----------------------+ | -|<left_expression cache>| +-----------+-----------+ -| | | | -+-----------------------+ | | - ^ +----------+ +--------------------+ - +<<<<<<<<<<<<<<<<<| Item_ref | +<<<|Item_ref_null_helper| - +----------+ V +--------------------+ - V +--------------------+ - +>>>| <item> | - +--------------------+ -@end example -where '<<<<<<<<<' is reference in meaning of Item_ref. - -Item_ref used for point to <left_expression cache>, because in time of -transformation we know only address of variable where pointer on cache -will be stored. - -If select have ORDER BY clause it will be wiped out, because no sense in -ORDER BY without LIMIT here. - -If IN subselect union condition of every select in UNION will be changed -personally. - -If condition should be added to WHERE clause it will be presented as -"(item OR item IS NULL)" and Item_is_not_null_test(item) will be added -to HAVING clause. Item_is_not_null_test register NULL value as -Item_ref_null_helper does it and return FALSE if argument is NULL. -With above trick we will register NULL value of Item even in case -of index optimization of WHERE clause (case 'a' of following example). - -Following is examples of IN transformations: -@example -a) <left_expression> IN (SELECT <item> FROM t - WHERE <where_exp>) - -will be represented as - - (SELECT 1 FROM t - WHERE - <where_exp> and - (Item_ref(<cached_left_expression>)=<Item_asterisk_remover(<Item>)> or - <Item> is null) - HAVING Item_is_not_null_test(<Item>)) - - -b) <left_expression> IN (SELECT <item> FROM t - HAVING <having_expr> - ORDER BY 1) - -will be represented as - (SELECT <item> as ref_null_helper FROM t - HAVING <having_exp> AND - Item_ref(<cached_left_expression>) = ref_null_helper) - - -c) <left_expression> IN (SELECT <item> UNION ...) - -will be represented as - - (SELECT 1 - HAVING Item_ref(<cached_left_expression>)= - <Item_asterisk_remover(<Item>)> - UNION ...) - -(having without FROM is syntax error, but having condition is checked -even for subselect without FROM) - -d) <left_expression> IN (select <item>) - -will be completely replaced with <left_expression> = <item> -@end example - -Now conditions (WHERE (a) or HAVING (b)) will be changed depends of -select in following way: - -If subselect have HAVING , sum function or GROUP BY (case a) then item -list will be unchanged and Item_ref_null_helper reference will be -created on item list element. Condition will be added to HAVING condition. - -If subselect have not HAVING, sum function or GROUP BY (case b) then: -@itemize @bullet -@item - @strong{item list} will be replaced with 1. -@item - @strong{<item>} from item list will be stored in Item_asterisk_remover, which - inherit from Item_ref_null_helper, but store item on which refer by - itself, and also it can resolve '*' item. -@item - @strong{<left_expression cache> = <Item_ref_null_helper>} will be added to - WHERE clause this item or to HAVING clause if this subselect have - no FROM clause and subselect is union (case c). -@end itemize - -Single select without FROM will be reduced to just -<left_expression> = <item> without using Item_in_optimizer. - -@node transformations row IN -@subsection Row IN Subselect - -To rewrite row IN subselect used method -Item_in_subselect::row_value_transformer. It work in almost same way as -scalar analog, but work with Item_cache_row for caching left expression -and use references on elements of Item_cache_row. -To refer on item list it use Item_ref_on_list_position. - -Item_ref_on_list_position::fix_fields will find item in item list of -subselect by number and create Item_ref_null_helper to refer on it. It -used to find reference when all '*' items will be translated in item -list. Subselect with have HAVING, sum functions or GROUP BY will -transformed in following way: - -@example -ROW(l1, l2, ... lN) IN (SELECT i1, i2, ... iM FROM t HAVING <having_expr>) - -will be following: - -(SELECT i1, i2, ... iM FROM t - HAVING <having_expr> and - <cache_l1> = <ref_on_list_position(1)> AND - <cache_l2> = <ref_on_list_position(2)> AND - ... - <cache_lN> = <ref_on_list_position(N)>) -@end example - -In this way will be transformed select without FROM, too. - -For other subselect it will be same but for WHERE clause. - -@node transformations all any -@section Item_allany_subselect - -Item_allany_subselect is inherited from Item_in_subselect. -ALL/ANY/SOME use same algorithm (and same method of Item_in_subselect) -as scalar IN, but use different function instead of '='. - -ANY/SOME use same function that was listed after left expression. - -ALL use inverted function, and all subselect passed as argument to -Item_func_not. - -@node transformations singlerow -@section Item_singlerow_subselect - -Item_singlerow_subselect will be rewritten only if it have not FROM -clause, it is not part of UNION and it is scalar subselect. For now will -not be converted subselects with field or reference on top of item list -(we can't change name of such items from one hand, but from other hand -we should assign to it name of whole subselect which will be reduced); - -Following will not be reduced: -@example -SELECT a; -SELECT 1 UNION SELECT 2; -SELECT 1 FROM t1; -@end example - -Following select will be reduced: -@example -SELECT 1; -SELECT a+2; -@end example - -Such subselect will be completely replaced by its expression from item -list and its SELECT_LEX and SELECT_LEX_UNIT will be removed from -SELECT_LEX's tree. - -But all Item_fields and Item_ref of that expression will be marked for -special fix_fields() procedure. fix_fields() for such Item will be -performed is same way as for items of inner subselect. Also if this -expression is Item_fields or Item_ref then name of this new item will -be same as name of this item (but not '(SELECT ...)'). It is done to -prevent broke references on such items from more inner subselects. - -@node coding guidelines, mysys functions, transformations, Top -@chapter Coding Guidelines - -@itemize @bullet - -@item -We are using @uref{http://www.bitkeeper.com/, BitKeeper} for source management. - -@item -You should use the @strong{MySQL} 4.0 source for all developments. - -@item -If you have any questions about the @strong{MySQL} source, you can post these -to @email{dev-public@@mysql.com} and we will answer them. Please -remember to not use this internal email list in public! - -@item -Try to write code in a lot of black boxes that can be reused or use at -least a clean, easy to change interface. - -@item -Reuse code; There is already a lot of algorithms in MySQL for list handling, -queues, dynamic and hashed arrays, sorting, etc. that can be reused. - -@item -Use the @code{my_*} functions like @code{my_read()}/@code{my_write()}/ -@code{my_malloc()} that you can find in the @code{mysys} library instead -of the direct system calls; This will make your code easier to debug and -more portable. - -@item -Try to always write optimized code, so that you don't have to -go back and rewrite it a couple of months later. It's better to -spend 3 times as much time designing and writing an optimal function than -having to do it all over again later on. - -@item -Avoid CPU wasteful code, even where it does not matter, so that -you will not develop sloppy coding habits. - -@item -If you can write it in fewer lines, do it (as long as the code will not -be slower or much harder to read). - -@item -Don't use two commands on the same line. - -@item -Do not check the same pointer for @code{NULL} more than once. - -@item -Use long function and variable names in English. This makes your code -easier to read. - -@item -Use @code{my_var} as opposed to @code{myVar} or @code{MyVar} (@samp{_} -rather than dancing SHIFT to seperate words in identifiers). - -@item -Think assembly - make it easier for the compiler to optimize your code. - -@item -Comment your code when you do something that someone else may think -is not ``trivial''. - -@item -Use @code{libstring} functions (in the @file{strings} directory) -instead of standard @code{libc} string functions whenever possible. - -@item -Avoid using @code{malloc()} (its REAL slow); For memory allocations -that only need to live for the lifetime of one thread, one should use -@code{sql_alloc()} instead. - -@item -Before making big design decisions, please first post a summary of -what you want to do, why you want to do it, and how you plan to do -it. This way we can easily provide you with feedback and also -easily discuss it thoroughly if some other developer thinks there is better -way to do the same thing! - -@item -Class names start with a capital letter. - -@item -Structure types are @code{typedef}'ed to an all-caps identifier. - -@item -Any @code{#define}'s are in all-caps. - -@item -Matching @samp{@{} are in the same column. - -@item -Put the @samp{@{} after a @code{switch} on the same line, as this gives -better overall indentation for the switch statement: - -@example -switch (arg) @{ -@end example - -@item -In all other cases, @samp{@{} and @samp{@}} should be on their own line, except -if there is nothing inside @samp{@{} and @samp{@}}. - -@item -Have a space after @code{if} - -@item -Put a space after @samp{,} for function arguments - -@item -Functions return @samp{0} on success, and non-zero on error, so you can do: - -@example -if(a() || b() || c()) @{ error("something went wrong"); @} -@end example - -@item -Using @code{goto} is okay if not abused. - -@item -Avoid default variable initalizations, use @code{LINT_INIT()} if the -compiler complains after making sure that there is really no way -the variable can be used uninitialized. - -@item -Do not instantiate a class if you do not have to. - -@item -Use pointers rather than array indexing when operating on strings. - -@end itemize - -Suggested mode in emacs: - -@example -(load "cc-mode") -(setq c-mode-common-hook '(lambda () - (turn-on-font-lock) - (setq comment-column 48))) -(setq c-style-alist - (cons - '("MY" - (c-basic-offset . 2) - (c-comment-only-line-offset . 0) - (c-offsets-alist . ((statement-block-intro . +) - (knr-argdecl-intro . 0) - (substatement-open . 0) - (label . -) - (statement-cont . +) - (arglist-intro . c-lineup-arglist-intro-after-paren) - (arglist-close . c-lineup-arglist) - )) - ) - c-style-alist)) -(c-set-style "MY") -(setq c-default-style "MY") -@end example - - -@node mysys functions, DBUG, coding guidelines, Top -@chapter Functions In The @code{mysys} Library - -Functions in @code{mysys}: (For flags see @file{my_sys.h}) - -@table @code -@item int my_copy _A((const char *from, const char *to, myf MyFlags)); -Copy file from @code{from} to @code{to}. - -@item int my_delete _A((const char *name, myf MyFlags)); -Delete file @code{name}. - -@item int my_getwd _A((string buf, uint size, myf MyFlags)); -@item int my_setwd _A((const char *dir, myf MyFlags)); -Get and set working directory. - -@item string my_tempnam _A((const char *pfx, myf MyFlags)); -Make a unique temporary file name by using dir and adding something after -@code{pfx} to make name unique. The file name is made by adding a unique -six character string and @code{TMP_EXT} after @code{pfx}. -Returns pointer to @code{malloc()}'ed area for filename. Should be freed by -@code{free()}. - -@item File my_open _A((const char *FileName,int Flags,myf MyFlags)); -@item File my_create _A((const char *FileName, int CreateFlags, int AccsesFlags, myf MyFlags)); -@item int my_close _A((File Filedes, myf MyFlags)); -@item uint my_read _A((File Filedes, byte *Buffer, uint Count, myf MyFlags)); -@item uint my_write _A((File Filedes, const byte *Buffer, uint Count, myf MyFlags)); -@item ulong my_seek _A((File fd,ulong pos,int whence,myf MyFlags)); -@item ulong my_tell _A((File fd,myf MyFlags)); -Use instead of open, open-with-create-flag, close, read, and write -to get automatic error messages (flag @code{MYF_WME}) and only have -to test for != 0 if error (flag @code{MY_NABP}). - -@item int my_rename _A((const char *from, const char *to, myf MyFlags)); -Rename file from @code{from} to @code{to}. - -@item FILE *my_fopen _A((const char *FileName,int Flags,myf MyFlags)); -@item FILE *my_fdopen _A((File Filedes,int Flags,myf MyFlags)); -@item int my_fclose _A((FILE *fd,myf MyFlags)); -@item uint my_fread _A((FILE *stream,byte *Buffer,uint Count,myf MyFlags)); -@item uint my_fwrite _A((FILE *stream,const byte *Buffer,uint Count, myf MyFlags)); -@item ulong my_fseek _A((FILE *stream,ulong pos,int whence,myf MyFlags)); -@item ulong my_ftell _A((FILE *stream,myf MyFlags)); -Same read-interface for streams as for files. - -@item gptr _mymalloc _A((uint uSize,const char *sFile,uint uLine, myf MyFlag)); -@item gptr _myrealloc _A((string pPtr,uint uSize,const char *sFile,uint uLine, myf MyFlag)); -@item void _myfree _A((gptr pPtr,const char *sFile,uint uLine)); -@item int _sanity _A((const char *sFile,unsigned int uLine)); -@item gptr _myget_copy_of_memory _A((const byte *from,uint length,const char *sFile, uint uLine,myf MyFlag)); -@code{malloc(size,myflag)} is mapped to these functions if not compiled -with @code{-DSAFEMALLOC}. - -@item void TERMINATE _A((void)); -Writes @code{malloc()} info on @code{stdout} if compiled with -@code{-DSAFEMALLOC}. - -@item int my_chsize _A((File fd, ulong newlength, myf MyFlags)); -Change size of file @code{fd} to @code{newlength}. - -@item void my_error _D((int nr, myf MyFlags, ...)); -Writes message using error number (see @file{mysys/errors.h}) on @code{stdout}, -or using curses, if @code{MYSYS_PROGRAM_USES_CURSES()} has been called. - -@item void my_message _A((const char *str, myf MyFlags)); -Writes @code{str} on @code{stdout}, or using curses, if -@code{MYSYS_PROGRAM_USES_CURSES()} has been called. - -@item void my_init _A((void )); -Start each program (in @code{main()}) with this. - -@item void my_end _A((int infoflag)); -Gives info about program. -If @code{infoflag & MY_CHECK_ERROR}, prints if some files are left open. -If @code{infoflag & MY_GIVE_INFO}, prints timing info and malloc info -about program. - -@item int my_redel _A((const char *from, const char *to, int MyFlags)); -Delete @code{from} before rename of @code{to} to @code{from}. Copies state -from old file to new file. If @code{MY_COPY_TIME} is set, sets old time. - -@item int my_copystat _A((const char *from, const char *to, int MyFlags)); -Copy state from old file to new file. If @code{MY_COPY_TIME} is set, -sets old time. - -@item string my_filename _A((File fd)); -Returns filename of open file. - -@item int dirname _A((string to, const char *name)); -Copy name of directory from filename. - -@item int test_if_hard_path _A((const char *dir_name)); -Test if @code{dir_name} is a hard path (starts from root). - -@item void convert_dirname _A((string name)); -Convert dirname according to system. -In MSDOS, changes all characters to capitals and changes @samp{/} to @samp{\}. - -@item string fn_ext _A((const char *name)); -Returns pointer to extension in filename. - -@item string fn_format _A((string to,const char *name,const char *dsk,const char *form,int flag)); - format a filename with replace of library and extension and - converts between different systems. - params to and name may be identicall - function dosn't change name if name != to - Flag may be: 1 force replace filnames library with 'dsk' - 2 force replace extension with 'form' */ - 4 force Unpack filename (replace ~ with home) - 8 Pack filename as short as possibly for output to - user. - All open requests should allways use at least: - "open(fn_format(temp_buffe,name,"","",4),...)" to unpack home and - convert filename to system-form. - -@item string fn_same _A((string toname, const char *name, int flag)); -Copys directory and extension from @code{name} to @code{toname} if neaded. -Copying can be forced by same flags used in @code{fn_format()}. - -@item int wild_compare _A((const char *str, const char *wildstr)); -Compare if @code{str} matches @code{wildstr}. @code{wildstr} can contain -@samp{*} and @samp{?} as wildcard characters. -Returns 0 if @code{str} and @code{wildstr} match. - -@item void get_date _A((string to, int timeflag)); -Get current date in a form ready for printing. - -@item void soundex _A((string out_pntr, string in_pntr)) -Makes @code{in_pntr} to a 5 char long string. All words that sound -alike have the same string. - -@item int init_key_cache _A((ulong use_mem, ulong leave_this_much_mem)); -Use caching of keys in MISAM, PISAM, and ISAM. -@code{KEY_CACHE_SIZE} is a good size. -Remember to lock databases for optimal caching. - -@item void end_key_cache _A((void)); -End key caching. -@end table - - - -@node DBUG, protocol, mysys functions, Top -@chapter DBUG Tags To Use - -Here is some of the tags we now use: -(We should probably add a couple of new ones) - -@table @code -@item enter -Arguments to the function. - -@item exit -Results from the function. - -@item info -Something that may be interesting. - -@item warning -When something doesn't go the usual route or may be wrong. - -@item error -When something went wrong. - -@item loop -Write in a loop, that is probably only useful when debugging -the loop. These should normally be deleted when one is -satisfied with the code and it has been in real use for a while. -@end table - -Some specific to mysqld, because we want to watch these carefully: - -@table @code -@item trans -Starting/stopping transactions. - -@item quit -@code{info} when mysqld is preparing to die. - -@item query -Print query. -@end table - - -@node protocol, Fulltext Search, DBUG, Top -@chapter MySQL Client/Server Protocol - -@menu -* raw packet without compression:: -* raw packet with compression:: -* basic packets:: -* communication:: -* fieldtype codes:: -* protocol functions:: -* protocol version 2:: -@end menu - -@node raw packet without compression, raw packet with compression, protocol, protocol -@section Raw Packet Without Compression - -@example -+-----------------------------------------------+ -| Packet Length | Packet no | Data | -| 3 Bytes | 1 Byte | n Bytes | -+-----------------------------------------------+ -@end example - -@table @asis -@item 3 Byte packet length -The length is calculated with int3store -See include/global.h for details. -The max packetsize can be 16 MB. - -@item 1 Byte packet no -If no compression is used the first 4 bytes of each packet is the header -of the packet. The packet number is incremented for each sent packet. -The first packet starts with 0. -@item n Byte data - -@end table - -The packet length can be recalculated with: - -@example -length = byte1 + (256 * byte2) + (256 * 256 * byte3) -@end example - - -@node raw packet with compression, basic packets, raw packet without compression, protocol -@section Raw Packet With Compression - -@example -+---------------------------------------------------+ -| Packet Length | Packet no | Uncomp. Packet Length | -| 3 Bytes | 1 Byte | 3 Bytes | -+---------------------------------------------------+ -@end example - -@table @asis -@item 3 Byte packet length -The length is calculated with int3store -See include/global.h for details. -The max packetsize can be 16 MB. - -@item 1 Byte packet no -@item 3 Byte uncompressed packet length -@end table - -If compression is used the first 7 bytes of each packet -is the header of the packet. - - -@node basic packets, communication, raw packet with compression, protocol -@section Basic Packets - -@menu -* ok packet:: -* error packet:: -@end menu - - -@node ok packet, error packet, basic packets, basic packets -@subsection OK Packet - -For details, see @file{sql/net_pkg.cc::send_ok()}. - -@example -+-----------------------------------------------+ -| Header | No of Rows | Affected Rows | -| | 1 Byte | 1-8 Byte | -|-----------------------------------------------| -| ID (last_insert_id) | Status | Length | -| 1-8 Byte | 2 Byte | 1-8 Byte | -|-----------------------------------------------| -| Messagetext | -| n Byte | -+-----------------------------------------------+ -@end example - -@table @asis -@item Header -@item 1 byte number of rows ? (always 0 ?) -@item 1-8 bytes affected rows -@item 1-8 byte id (last_insert_id) -@item 2 byte Status (usually 0) -@item If the OK-packege includes a message: -@item 1-8 bytes length of message -@item n bytes messagetext -@end table - - -@node error packet, , ok packet, basic packets -@subsection Error Packet - -@example -+-----------------------------------------------+ -| Header | Status code | Error no | -| | 1 Byte | 2 Byte | -|-----------------------------------------------| -| Messagetext | 0x00 | -| n Byte | 1 Byte | -+-----------------------------------------------+ -@end example - -@table @asis -@item Header -@item 1 byte status code (0xFF = ERROR) -@item 2 byte error number (is only sent to new 3.23 clients. -@item n byte errortext -@item 1 byte 0x00 -@end table - - -@node communication, fieldtype codes, basic packets, protocol -@section Communication - -> Packet from server to client -< Paket from client tor server - - Login - ------ - > 1. packet - Header - 1 byte protocolversion - n byte serverversion - 1 byte 0x00 - 4 byte threadnumber - 8 byte crypt seed - 1 byte 0x00 - 2 byte CLIENT_xxx options (see include/mysql_com.h - that is supported by the server - 1 byte number of current server charset - 2 byte server status variables (SERVER_STATUS_xxx flags) - 13 byte 0x00 (not used yet). - - < 2. packet - Header - 2 byte CLIENT_xxx options - 3 byte max_allowed_packet for the client - n byte username - 1 byte 0x00 - 8 byte crypted password - 1 byte 0x00 - n byte databasename - 1 byte 0x00 - - > 3. packet - OK-packet - - - Command - -------- - < 1. packet - Header - 1 byte command type (e.g.0x03 = query) - n byte query - - Result set (after command) - -------------------------- - > 2. packet - Header - 1-8 byte field_count (packed with net_store_length()) - - If field_count == 0 (command): - 1-8 byte affected rows - 1-8 byte insert id - 2 bytes server_status (SERVER_STATUS_xx) - - If field_count == NULL_LENGTH (251) - LOAD DATA LOCAL INFILE - - If field_count > 0 Result Set: - - > n packets - Header Info - Column description: 5 data object /column - (See code in unpack_fields()) - - Columninfo for each column: - 1 data block table_name - 1 byte length of block - n byte data - 1 data block field_name - 1 byte length of block... - n byte data - 1 data block display length of field - 1 byte length of block - 3 bytes display length of filed - 1 data block type field of type (enum_field_types) - 1 byte length of block - 1 bytexs field of type - 1 data block flags - 1 byte length of block - 2 byte flags for the columns (NOT_NULL_FLAG, ZEROFILL_FLAG....) - 1 byte decimals - - if table definition: - 1 data block default value - - Actual result (one packet per row): - 4 byte header - 1-8 byte length of data - n data - - -@node fieldtype codes, protocol functions, communication, protocol -@section Fieldtype Codes - -@example - display_length |enum_field_type |flags - ---------------------------------------------------- -Blob 03 FF FF 00 |01 FC |03 90 00 00 -Mediumblob 03 FF FF FF |01 FC |03 90 00 00 -Tinyblob 03 FF 00 00 |01 FC |03 90 00 00 -Text 03 FF FF 00 |01 FC |03 10 00 00 -Mediumtext 03 FF FF FF |01 FC |03 10 00 00 -Tinytext 03 FF 00 00 |01 FC |03 10 00 00 -Integer 03 0B 00 00 |01 03 |03 03 42 00 -Mediumint 03 09 00 00 |01 09 |03 00 00 00 -Smallint 03 06 00 00 |01 02 |03 00 00 00 -Tinyint 03 04 00 00 |01 01 |03 00 00 00 -Varchar 03 XX 00 00 |01 FD |03 00 00 00 -Enum 03 05 00 00 |01 FE |03 00 01 00 -Datetime 03 13 00 00 |01 0C |03 00 00 00 -Timestamp 03 0E 00 00 |01 07 |03 61 04 00 -Time 03 08 00 00 |01 0B |03 00 00 00 -Date 03 0A 00 00 |01 0A |03 00 00 00 -@end example - -@node protocol functions, protocol version 2, fieldtype codes, protocol -@section Functions used to implement the protocol - -This should be merged with the above one and changed to texi format - -Raw packets ------------ - -- The my_net_xxxx() functions handles the packaging of a stream of data - into a raw packet that contains a packet number, length and data. - -- This is implemented for the server in sql/net_serv.cc. - The client file, libmysql/net.c, is symlinked to this file - -The important functions are: - -my_net_write() Store a packet (= # number of bytes) to be sent -net_flush() Send the packets stored in the buffer -net_write_command() Send a command (1 byte) + packet to the server. -my_net_read() Read a packet - - -Include files -------------- - -- include/mysql.h is included by all MySQL clients. It includes the - MYSQL and MYSQL_RES structures. -- include/mysql_com.h is include by mysql.h and mysql_priv.h (the - server) and includes a lot of common functions and structures to - handle the client/server protocol. - - -Packets from server to client: ------------------------------ - -sql/net_pkg.cc: - - - Sending of error packets - - Sending of OK packets (= end of data) - - Storing of values in a packet - - -sql/sql_base.cc: - - - Function send_fields() sends the field description to the client. - -sql/sql_show.cc: - - - Sends results for a lot of SHOW commands, including: - SHOW DATABASES [like 'wildcard'] - SHOW TABLES [like 'wildcard'] - - -Packets from client to server: ------------------------------- - -This is done in libmysql/libmysql.c - -The important ones are: - -- mysql_real_connect() Connects to a mysqld server -- mysql_real_query() Sends a query to the server and - reads the ok packet or columns header. -- mysql_store_result() Read a result set from the server to memory -- mysql_use_result() Read a result set row by row from the server. - -- net_safe_read() Read a packet from the server with - error handling. -- net_field_length() Reads the length of a packet string. -- simple_command() Sends a command/query to the server. - - - -Connecting to mysqld (the MySQL server) ---------------------------------------- - -- On the client side: libmysql/libmysql.c::mysql_real_connect(). -- On the server side: sql/sql_parse.cc::check_connections() - -The packets sent during a connection are as follows - -Server: Send greeting package (includes server capabilites, server - version and a random string of bytes to be used to scramble - the password. -Client: Sends package with client capabilites, user name, scrambled - password, database name - -Server: Sends ok package or error package. - -Client: If init command specified, send it t the server and read - ok/error package. - - -Password functions ------------------- - -The passwords are scrambled to a random number and are stored in hex -format on the server. - -The password handling is done in sql/password.c. The important -function is 'scramble()', which takes the a password in clear text -and uses this to 'encrypt' the random string sent by the server -to a new message. - -The encrypted message is sent to the server which uses the stored -random number password to encrypt the random string sent to the -client. If this is equal to the new message the client sends to the -server then the password is accepted. - -@node protocol version 2, , protocol functions, protocol -@section Another description of the protocol - -This should be merged with the above one and changed to texi format. - -***************************** -* -* PROTOCOL OVERVIEW -* -***************************** - -The MySQL protocol is relatively simple, and is designed for high performance -through minimisation of overhead, and extensibility through versioning and -options flags. It is a request-response protocol, and does not allow -multitasking or multiplexing over a single connection. There are two packet -formats, 'raw' and 'compressed' (which is used when both client and -server support zlib compression, and the client requests that data be -compressed): - -* RAW PACKET, shorter than 16 M * - -+-----------------------------------------------+ -| Packet Length | Packet no | Data | -| 3 Bytes | 1 Byte | n Bytes | -+-----------------------------------------------+ -^ ^ -| 'HEADER' | -+-------------------------------+ - - - * Packet Length: Calculated with int3store. See include/global.h for - details. The basic computation is length = byte1 + - (256 * byte2) + (256 * 256 * byte3). The max packetsize - can be 16 MB. - - * Packet no: The packet number is incremented for each sent packet. - The first packet for each query from the client - starts with 0. - - * Data: Specific to the operation being performed. Most often - used to send string data, such as a SQL query. - -* COMPRESSED PACKET * - -+---------------------------------------------------+-----------------+ -| Packet Length | Packet no | Uncomp. Packet Length | Compressed Data | -| 3 Bytes | 1 Byte | 3 Bytes | n bytes | -+---------------------------------------------------+-----------------+ -^ ^ -| 'HEADER' | -+---------------------------------------------------+ - - * Packet Length: Calculated with int3store. See include/my_global.h for - details. The basic computation is length = byte1 + - (256 * byte2) + (256 * 256 * byte3). The max packetsize - can be 16 MB. - - * Packet no: The packet number is incremented for each sent packet. - The first packet starts with 0. - - * Uncomp. Packet Length: The length of the original, uncompressed packet - If this is zero then the data is not compressed. - - * Compressed Data: The original packet, compressed with zlib compression - - -When using the compressed protocol, the client/server will only compress -send packets where the new packet is smaller than the not compressed one. -In other words, some packets may be compressed while others will not. - -The 'compressed data' is one or more packets in *RAW PACKET* format. - -***************************** -* -* FLOW OF EVENTS -* -***************************** - -To understand how a client communicates with a MySQL server, it is easiest -to start with a high-level flow of events. Each event section will then be -followed by details of the exact contents of each type of packet involved -in the event flow. - -* * -* CONNECTION ESTABLISHMENT * -* * - -Clients connect to the server via a TCP/IP socket (port 3306 by default), a -Unix Domain Socket, or named pipes (on Windows). Once connected, the -following connection establishment sequence is followed: - -+--------+ +--------+ -| Client | | Server | -+--------+ +--------+ - | | - | Handshake initialisation, including MySQL server version, | - | protocol version and options supported, as well as the seed | - | for the password hash | - | | - | <-------------------------------------------------------------- | - | | - | Client options supported, max packet size for client | - | username, password crypted with seed from server, database | - | name. | - | | - | --------------------------------------------------------------> | - | | - | 'OK' packet if authentication succeeds, 'ERROR' packet if | - | authentication fails. | - | | - | <-------------------------------------------------------------- | - | | - - - -* HANDSHAKE INITIALISATION PACKET * - - -+--------------------------------------------------------------------+ -| Header | Prot. Version | Server Version String | 0x00 | -| | 1 Byte | n bytes | 1 byte | -|--------------------------------------------------------------------| -| Thread Number | Crypt Seed | 0x00 | CLIENT_xxx options | -| | | | supported by server | -| 4 Bytes | 8 Bytes | 1 Byte | 2 Bytes | -|--------------------------------------------------------------------| -| Server charset no. | Server status variables | 0x00 padding | -| 1 Byte | 2 Bytes | 13 bytes | -+--------------------------------------------------------------------+ - - * Protocol version (currently '10') - * Server Version String (e.g. '4.0.5-beta-log'). Can be any length as - it's followed by a 0 byte. - * Thread Number - ID of server thread handling this connection - * Crypt seed - seed used to crypt password in auth packet from client - * CLIENT_xxx options - see include/mysql_com.h - * Server charset no. - Index of charset in use by server - * Server status variables - see include/mysql_com.h - * The padding bytes are reserverd for future extensions to the protocol - -* CLIENT AUTH PACKET * - - -+--------------------------------------------------------------------+ -| Header | CLIENT_xxx options supported | max_allowed_packet | -| | by client | for client | -| | 2 Bytes | 3 bytes | -|--------------------------------------------------------------------| -| User Name | 0x00 | Crypted Password | 0x00 | Database Name | -| n Bytes | 1 Byte | 8 Bytes | 1 Byte | n Bytes | -|--------------------------------------------------------------------| -| 0x00 | -| 1 Byte | -+--------------------------------------------------------------------+ - - * CLIENT_xxx options that this client supports: - -#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ -#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ -#define CLIENT_LONG_FLAG 4 /* Get all column flags */ -#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */ -#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */ -#define CLIENT_COMPRESS 32 /* Can use compression protocol */ -#define CLIENT_ODBC 64 /* Odbc client */ -#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */ -#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */ -#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */ -#define CLIENT_SSL 2048 /* Switch to SSL after handshake */ -#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ -#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */ - - * max_allowed_packet for the client (in 'int3store' form) - * User Name - user to authenticate as. Is followed by a null byte. - * Crypted Password - password crypted with seed given in packet from - server, see scramble() in sql/password.c - * Database name (optional) - initial database to use once connected - Is followed by a null byte - -At the end of every client/server exchange there is either an 'OK' packet -or an 'ERROR' packet sent from the server. To determine whether a packet is -an 'OK' packet, or an 'ERROR' packet, check if the first byte (after the -header) is 0xFF. If it has the value of 0xFF, the packet is an 'ERROR' -packet. - - -* OK PACKET * - -For details, see sql/net_pkg.cc::send_ok() - -+-----------------------------------------------+ -| Header | No of Rows | Affected Rows | -| | 1 Byte | 1-9 Byte | -|-----------------------------------------------| -| ID (last_insert_id) | Status | Length | -| 1-9 Byte | 2 Byte | 1-9 Byte | -|-----------------------------------------------| -| Messagetext | -| n Byte | -+-----------------------------------------------+ - - * Number of rows, always 0 - * Affected rows - * ID (last_insert_id) - value for auto_increment column (if any) - * Status (usually 0) - -In general, in the MySQL protocol, fields in a packet that that -represent numeric data, such as lengths, that are labeled as '1-9' -bytes can be decoded by the following logic: - - If the first byte is '251', the - corresponding column value is NULL (only appropriate in - 'ROW DATA' packets). - - If the first byte is '252', the value stored can be read - from the following 2 bytes as a 16-bit integer. - - - If the first byte is '253' the value stored can be read - from the following 4 bytes as a 32-bit long integer - - - If the first byte is '254', the value stored can be read - from the following 8 bytes as a 64-byte long - - Otherwise (values 0-250), the value stored is the value of the - first byte itself. - - -If the OK-packet includes a message: - - * Length of message - * Message Text - - -* ERROR PACKET * - -+-----------------------------------------------+ -| Header | Status code | Error no | -| | 1 Byte | 2 Byte | -|-----------------------------------------------| -| Messagetext | | -| n Byte | | -+-----------------------------------------------+ - - * Status code (0xFF = ERROR) - * Error number (is only sent to 3.23 and newer clients) - * Error message text (ends at end of packet) - -Note that the error message is not null terminated. -The client code can however assume that the packet ends with a null -as my_net_read() will always add an end-null to all read packets to -make things easier for the client. - -Example: - -Packet dump of client connecting to server: - -+------------------------- Protocol Version (10) -| -| +---------------------- Server Version String (0x00 terminated) -| | -| | -0a 34 2e 30 2e 35 2d 62 . 4 . 0 . 5 - b -65 74 61 2d 6c 6f 67 00 e t a - l o g . -15 00 00 00 2b 5a 65 6c . . . . + Z e l - | | - | +------------ First 4 bytes of crypt seed - | - +------------------------ Thread Number - -+------------------------- Last 4 bytes of crypt seed -| -| +-------- CLIENT_XXX Options supported by server -| | -| +-+--+ +--- Server charset index -| | | | -6f 69 41 46 00 2c 28 08 o i A F . , ( . -02 00 00 00 00 00 00 00 . . . . . . . . -| | -| +---------------------- 0x00 padding begins -| -+------------------------- Server status (0x02 = - SERVER_STATUS_AUTOCOMMIT) - -00 00 00 00 00 00 00 00 . . . . . . . . - -* Client Authentication Response (Username 'test', no database - selected) * - - +--------------------- Packet Length (0x13 = 19 bytes) - | - | +--------------- Packet Sequence # - | | - | | +----------- CLIENT_XXX Options supported by client - | | -+---+---+ | +-+-+ -| | | | | -13 00 00 01 03 00 1e 00 . . . . . . . . -00 74 65 73 74 00 48 5e . t e s t . H ^ - | | | - +----+-----+ +------- Scrambled password, 0x00 terminated - | - +----------------- Username, 0x00 terminated - -57 4a 4e 41 4a 4e 00 00 W J N A J N . . -00 . - - ->From this point on, the server waits for 'commands' from the client -which include queries, database shutdown, quit, change user, etc (see -the COM_xxxx values in include/mysql_com.h for the latest -command codes). - -* * -* COMMAND PROCESSING * -* * - -+--------+ +--------+ -| Client | | Server | -+--------+ +--------+ - | | - | A command packet, with a command code, and string data | - | when appropriate (e.g. a query), (see the COM_xxxx values | - | in include/mysql_com.h for the command codes) | - | | - | --------------------------------------------------------------> | - | | - | A 'RESULT' packet if the command completed successfully, | - | an 'ERROR' packet if the command failed. 'RESULT' packets | - | take different forms (see the details following this chart) | - | depending on whether or not the command returns rows. | - | | - | <-------------------------------------------------------------- | - | | - | n 'FIELD PACKET's (if rows are returned) | - | | - | <-------------------------------------------------------------- | - | | - | 'LAST DATA' packet | - | | - | <-------------------------------------------------------------- | - | | - | n 'ROW PACKET's (if rows are returned) | - | | - | <-------------------------------------------------------------- | - | | - | 'LAST DATA' packet | - | | - | <-------------------------------------------------------------- | - | | - - -* Command Packet * - -+------------------------------------------------------+ -| Header | Command type | Query (if applicable) | -| | 1 Byte | n Bytes | -+------------------------------------------------------+ - - * Command type: (e.g.0x03 = query, see the COM_xxxx values in - include/mysql_com.h) - * Query (if applicable) - -Note that my_net_read() null-terminates all packets on the -receiving side of the channel to make it easier for the code -examining the packets. - -The current command codes are: - - 0x00 COM_SLEEP - 0x01 COM_QUIT - 0x02 COM_INIT_DB - 0x03 COM_QUERY - 0x04 COM_FIELD_LIST - 0x05 COM_CREATE_DB - 0x06 COM_DROP_DB - 0x07 COM_REFRESH - 0x08 COM_SHUTDOWN - 0x09 COM_STATISTICS - 0x0a COM_PROCESS_INFO - 0x0b COM_CONNECT - 0x0c COM_PROCESS_KILL - 0x0d COM_DEBUG - 0x0e COM_PING - 0x0f COM_TIME - 0x10 COM_DELAYED_INSERT - 0x11 COM_CHANGE_USER - 0x12 COM_BINLOG_DUMP - 0x13 COM_TABLE_DUMP - 0x14 COM_CONNECT_OUT - 0x15 COM_REGISTER_SLAVE - -* Result Packet * - -Result packet for a command returning _no_ rows: - -+-----------------------------------------------+ -| Header | Field Count | Affected Rows | -| | 1-9 Bytes | 1-9 Bytes | -|-----------------------------------------------| -| ID (last_insert_id) | Server Status | -| 1-9 Bytes | 2 Bytes | -+-----------------------------------------------+ - - * Field Count: Has value of '0' for commands returning _no_ rows - * Affected rows: Count of rows affected by INSERT/UPDATE/DELETE, etc. - * ID: value of auto_increment column in row (if any). 0 if - * Server Status: Usually 0 - -Result packet for a command returning rows: - -+-------------------------------+ -| Header | Field Count | -| | 1-9 Bytes | -+-------------------------------+ - - * Field Count: number of columns/fields in result set, - (packed with net_store_length() in sql/net_pkg.cc) - -This is followed by as many packets as the number of fields ('Field Count') -that contain the metadata for each column/field (see unpack_fields() in -libmysql/libmysql.c): - - -* FIELD PACKET * - -+-----------------------------------------------+ -| Header | Table Name | -| | length-coded-string | -|-----------------------------------------------| -| Field Name | -| length-code-string | -|-----------------------------------------------| -| Display length of field -| length-coded-binary (4 bytes) | -|-----------------------------------------------| -| Field Type (enum_field_types in mysql_com.h) | -| length-coded-binary (2 bytes) | -|-----------------------------------------------| -| Field Flags | Decimal Places| -| length-coded-binary (3 bytes) | 1 Byte | -+--------------+-------------+------------------+ - - * A length coded string is a string where we first have a packet - length (1-9 bytes, packed_with net_store_length()) followed - by a string. - * A length coded binary is a length (1 byte) followed by an integer - value in low-byte-first order. For the moment this type is always - fixed length in this packet. - - * Table Name - the name of the table the column comes from - * Field Name - the name of the column/field - * Display length of field - length of field - * Field Type - Type of field, see enum_field_types in - include/mysql_com.h - - Current field types are: - - 0x00 FIELD_TYPE_DECIMAL - 0x01 FIELD_TYPE_TINY - 0x02 FIELD_TYPE_SHORT - 0x03 FIELD_TYPE_LONG - 0x04 FIELD_TYPE_FLOAT - 0x05 FIELD_TYPE_DOUBLE - 0x06 FIELD_TYPE_NULL - 0x07 FIELD_TYPE_TIMESTAMP - 0x08 FIELD_TYPE_LONGLONG - 0x09 FIELD_TYPE_INT24 - 0x0a FIELD_TYPE_DATE - 0x0b FIELD_TYPE_TIME - 0x0c FIELD_TYPE_DATETIME - 0x0d FIELD_TYPE_YEAR - 0x0e FIELD_TYPE_NEWDATE - 0xf7 FIELD_TYPE_ENUM - 0xf8 FIELD_TYPE_SET - 0xf9 FIELD_TYPE_TINY_BLOB - 0xfa FIELD_TYPE_MEDIUM_BLOB - 0xfb FIELD_TYPE_LONG_BLOB - 0xfc FIELD_TYPE_BLOB - 0xfd FIELD_TYPE_VAR_STRING - 0xfe FIELD_TYPE_STRING - 0xff FIELD_TYPE_GEOMETRY - - * Field Flags - NOT_NULL_FLAG, PRI_KEY_FLAG, xxx_FLAG in - include/mysql_com.h - - -Note that the packet format in 4.1 has slightly changed to allow more values. - - -* ROW PACKET * - -+-----------------------------------------------+ -| Header | Data Length | Column Data | ....for each column -| | 1-9 Bytes | n Bytes | -+-----------------------------------------------+ - - * Data Length: (packed with net_store_length() in sql/net_pkg.cc) - - If 'Data Length' == 0, this is an 'ERROR PACKET'. - - * Column Data: String representation of data. MySQL always sends result set - data as strings. - -* LAST DATA PACKET * - -Packet length is < 9 bytes, and first byte is 0xFE - -+--------+ -| 0xFE | -| 1 Byte | -+--------+ - -Examples: - -*********** -* -* INITDB Command -* -*********** - -A client issuing an 'INITDB' (select the database to use) command, -followed by an 'OK' packet with no rows and no affected rows from -the server: - -* INITDB (select database to use) 'COMMAND' Packet * - - +--------------------- Packet Length (5 bytes) - | - | +--------------- Packet Sequence # - | | - | | +------------ Command # (INITDB = 0x02) - | | -+---+---+ | | +---------- Beginning of query data -| | | | | -05 00 00 00 02 74 65 73 . . . . . t e s -74 t - -* 'OK' Packet with no rows, and no rows affected * - - +--------------------- Packet Length (3 bytes) - | - | +--------------- Packet Sequence # - | | -+---+---+ | -| | | -03 00 00 01 00 00 00 . . . . . . . - - -*********** -* -* SELECT query example -* -*********** - -Client issuing a 'SELECT *' query on the following table: - - CREATE TABLE number_test (minBigInt bigint, - maxBigInt bigint, - testBigInt bigint) - -* 'COMMAND' Packet with QUERY (select ...) * - - +--------------------- Packet Length (26) - | - | +--------------- Packet Sequence # - | | - | | +------------ Command # (QUERY = 0x03) - | | -+---+---+ | | +---------- Beginning of query data -| | | | | -1a 00 00 00 03 53 45 4c . . . . . S E L -45 43 54 20 2a 20 66 72 E C T . * . f r -6f 6d 20 6e 75 6d 62 65 o m . n u m b e -72 5f 74 65 73 74 r _ t e s t - - -and receiving an 'OK' packet with a 'FIELD COUNT' of 3 - - -* 'OK' Packet with 3 fields * - - +--------------------- Packet Length (3 bytes) - | - | +--------------- Packet Sequence # - | | -+---+---+ | -| | | -01 00 00 01 03 . . . . . - -Followed immediately by 3 'FIELD' Packets. Note, the individual packets -are delimitted by =======, so that all fields can be annotated in the first -'FIELD' packet example: - -============================================================= - - +--------------------- Packet Length (0x1f = 31 bytes) - | - | +--------------- Packet Sequence # - | | - | | +------------ Block Length (0x0b = 11 bytes) - | | | -+---+---+ | | +--------- Table Name (11 bytes long) -| | | | | -1f 00 00 02 0b 6e 75 6d . . . . . n u m -62 65 72 5f 74 65 73 74 b e r _ t e s t - - +------------------------ Block Length (9 bytes) - | - | +--------------------- Column Name (9 bytes long) - | | -09 6d 69 6e 42 69 67 49 . m i n B i g I -6e 74 03 14 00 00 01 08 n t . . . . . . - | | | | | - | +---+---+ | +--- Field Type (0x08 = FIELD_TYPE_LONGLONG) - | | | - | | +------ Block Length (1) - | | - | +--------------- Display Length (0x14 = 20 chars) - | - +------------------ Block Length (3) - - +------------------------ Block Length (2) - | - | +-------------------- Field Flags (0 - no flags set) - | | - | +---+ +--------------- Decimal Places (0) - | | | | -02 00 00 00 . . . . - -============================================================= - -'FIELD' packet for the 'number_Test.maxBigInt' column - -1f 00 00 03 0b 6e 75 6d . . . . . n u m -62 65 72 5f 74 65 73 74 b e r _ t e s t -09 6d 61 78 42 69 67 49 . m a x B i g I -6e 74 03 14 00 00 01 08 n t . . . . . . -02 00 00 00 . . . . - -============================================================= - -'FIELD' packet for the 'number_test.testBigInt' column - -20 00 00 04 0b 6e 75 6d . . . . . n u m -62 65 72 5f 74 65 73 74 b e r _ t e s t -0a 74 65 73 74 42 69 67 . t e st B i g -49 6e 74 03 14 00 00 01 I n t . . . . . -08 02 00 00 00 . . . . . -============================================================= - -Followed immediately by one 'LAST DATA' packet: - -fe 00 . . - -Followed immediately by 'n' row packets (in this case, only -one packet is sent from the server, for simplicity's sake): - - - +--------------------- Packet Length (0x52 = 82 bytes) - | - | +--------------- Packet Sequence # - | | - | | +------------ Data Length (0x14 = 20 bytes) - | | | -+---+---+ | | +--------- String Data '-9223372036854775808' -| | | | | (repeat Data Length/Data sequence) - -52 00 00 06 14 2d 39 32 . . . . . - 9 2 -32 33 33 37 32 30 33 36 2 3 3 7 2 0 3 6 -38 35 34 37 37 35 38 30 8 5 4 7 7 5 8 0 -38 13 39 32 32 33 33 37 8 . 9 2 2 3 3 7 -32 30 33 36 38 35 34 37 2 0 3 6 8 5 4 7 -37 35 38 30 37 0a 36 31 7 5 8 0 7 . 6 1 -34 37 34 38 33 36 34 37 4 7 4 8 3 6 4 7 - -Followed immediately by one 'LAST DATA' packet: - -fe 00 . . - - - -@c The Index was empty, and ugly, so I removed it. (jcole, Sep 7, 2000) - -@c @node Index -@c @unnumbered Index - -@c @printindex fn - -@c @node 4.1 protocol,,, -@c @chapter MySQL 4.1 protocol - -@node 4.1 protocol changes,,, -@section Changes to 4.0 protocol in 4.1 - -All basic packet handling is identical to 4.0. When communication -with an old 4.0 or 3.x client we will use the old protocol. - -The new things that we support with 4.1 are: - -@itemize @bullet -@item -Warnings -@item -Prepared statements -@item -Binary protocol (will be faster than the current protocol that -converts everything to strings) -@end itemize - - -What has changed in 4.1 are: - -@itemize @bullet -@item -A lot of new field information (database, real table name etc) -@item -The 'ok' packet has more status fields -@item -The 'end' packet (send last for each result set) now contains some -extra information -@item -New protocol for prepared statements. In this case all parameters and -results will sent as binary (low-byte-first). -@end itemize - - -@node 4.1 field packet,,, -@section 4.1 field description packet - -The field description packet is sent as a response to a query that -contains a result set. It can be distinguished from a ok packet by -the fact that the first byte can't be 0 for a field packet. -@xref{4.1 ok packet}. - -The header packet has the following structure: - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 1-9 @tab Number of columns in result set (never 0) -@item 1-9 @tab Extra information sent be some command (SHOW COLUMNS -uses this to send the number of rows in the table) -@end multitable - -This packet is always followed by a field description set. -@xref{4.1 field desc}. - -@node 4.1 field desc,,, -@section 4.1 field description result set - -The field description result set contains the meta info for a result set. - -@multitable @columnfractions .20 .80 -@item Type @tab Comment -@item string @tab Database name -@item string @tab Table name alias (or table name if no alias) -@item string @tab Real table name -@item string @tab Alias for column name (or column name if not used) - -@item 11 byte @tab Fixed length fields in one field part: -@itemize -@item 2 byte int @tab Character set number -@item 3 byte int @tab Length of column definition -@item 1 byte int @tab Enum value for field type -@item 3 byte int @tab 2 byte column flags (NOT_NULL_FLAG etc..) + 1 byte number of decimals. -@item 2 byte int @tab zero (reserved for future use) -@end itemize - -@item string int @tab Default value, only set when using mysql_list_fields(). -@end multitable - - -@node 4.1 ok packet,,, -@section 4.1 ok packet - -The ok packet is the first that is sent as an response for a query -that didn't return a result set. - -The ok packet has the following structure: - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 1 @tab 0 ; Marker for ok packet -@item 1-9 @tab Affected rows -@item 1-9 @tab Last insert id (0 if one wasn't used) -@item 2 @tab Server status; Can be used by client to check if we are inside an transaction -@item 2 @tab Warning count -@item 1-9 @tab Message length (optional) -@item xxx @tab Message (optional) -@end multitable - -Size 1-9 means that the parameter is packed in to 1-9 bytes depending on -the value. (See function sql/net_pkg.cc::net_store_length). - -The message is optional. For example for multi line INSERT it -contains a string for how many rows was inserted / deleted. - - -@node 4.1 end packet,,, -@section 4.1 end packet - -The end packet is sent as the last packet for - -@itemize @bullet -@item -End of field information -@item -End of parameter type information -@item -End of result set -@end itemize - -The end packet has the following structure: - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 1 @tab 254 ; Marker for EOF packet -@item 2 @tab Warning count -@item 2 @tab Status flags (For flags like SERVER_STATUS_MORE_RESULTS) -@end multitable - -Note that a normal packet may start with byte 254, which means -'length stored in 9 bytes'. One can different between these cases -by checking the packet length < 9 bytes (in which case it's and end -packet). - - -@node 4.1 error packet -@section 4.1 error packet. - -The error packet is sent when something goes wrong. -The error packet has the following structure: - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 1 @tab 255 Error packet marker -@item 2 @tab Error code -@item 1-255 @tab Null terminated error message -@end multitable - -The client/server protocol is designed in such a way that a packet -can only start with 255 if it's an error packet. - - -@node 4.1 prep init,,, -@section 4.1 prepared statement init packet - -This is the return packet when one sends a query with the COM_PREPARE -command (packet length is always '9'). - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 1 @tab 0 ; Marker for OK packet -@item 4 @tab Statement handler id -@item 2 @tab Number of columns in result set -@item 2 @tab Number of parameters in query -@end multitable - -After this, there is a packet that contains the following for each -parameter in the query: - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 2 @tab Enum value for field type. (MYSQL_TYPE_UNKNOWN if not known) -@item 2 @tab 2 byte column flags (NOT_NULL_FLAG etc) -@item 1 @tab Number of decimals -@item 4 @tab Max column length. -@end multitable - -Note that the above is not yet in 4.1 but will be added this month. - -As MySQL can have a parameter 'anywhere' it will in many cases not be -able to provide the optimal information for all parameters. - -If number of columns, in the header packet, is not 0 then the -prepared statement will contain a result set. In this case the packet -is followed by a field description result set. @xref{4.1 field desc}. - - -@node 4.1 long data,,, -@section 4.1 long data handling - -This is used by mysql_send_long_data() to set any parameter to a string -value. One can call mysql_send_long_data() multiple times for the -same parameter; The server will concatenate the results to a one big -string. - -The server will not require an end packet for the string. -mysql_send_long_data() is responsible updating a flag that all data -has been sent. (Ie; That the last call to mysql_send_long_data() has -the 'last_data' flag set). - -This packet is sent from client -> server: - -@multitable @columnfractions .10 .90 -@item Size @tab Comment -@item 4 @tab Statement handler -@item 2 @tab Parameter number -@item 2 @tab Type of parameter (not used at this point) -@item # @tab data (Rest of packet) -@end multitable - -The server will NOT send an @code{ok} or @code{error} packet in -responce for this. If there is any errors (like to big string), one -will get the error when calling execute. - -@node 4.1 execute,,, -@section 4.1 execute - -On execute we send all parameters to the server in a COM_EXECUTE -packet. - -The packet contains the following information: - -@multitable @columnfractions .30 .70 -@item Size @tab Comment -@item (param_count+9)/8 @tab Null bit map (2 bits reserved for protocol) -@item 1 @tab new_parameter_bound flag. Is set to 1 for first -execute or if one has rebound the parameters. -@item 2*param_count @tab Type of parameters (only given if new_parameter_bound flag is 1) -@item # @tab Parameter data, repeated for each parameter that are -NOT NULL and not used with mysql_send_long_data(). -@end multitable - -The null-bit-map is for all parameters (including parameters sent with -'mysql_send_long_data). If parameter 0 is NULL, then bit 0 in the -null-bit-map should be 1 (ie: first byte should be 1) - -The parameters are stored the following ways: - -@multitable @columnfractions .20 .10 .70 -@item Type @tab Size @tab Comment -@item tinyint @tab 1 @tab One byte integer -@item short @tab 2 @tab -@item int @tab 4 @tab -@item longlong @tab 8 @tab -@item float @tab 4 @tab -@item double @tab 8 @tab -@item string @tab 1-9 + # @tab Packed string length + string -@end multitable - -The result for this will be either an ok packet or a binary result -set. - -@node 4.1 binary result,,, -@section 4.1 binary result set - -A binary result are sent the following way. - -For each result row: - -@itemize -@item -null bit map with first two bits set to 01 (bit 0,1 value 1) -@item -parameter data, repeated for each not null result column. -@end itemize - -The idea with the reserving two bits in the null map is that we can -use standard error (first byte 255) and ok packets (first byte 0) -to end a result sets. - -Except that the null-bit-map is shifted two steps, the server is -sending the data to the client the same way that the server is sending -bound parameters to the client. The server is always sending the data -as type given for 'column type' for respective column. It's up to the -client to convert the parameter to the requested type. - -DATETIME, DATE and TIME are sent to the server in a binary format as follows: - -@multitable @columnfractions .20 .10 .70 -@item Type @tab Size @tab Comment -@item date @tab 1 + 0-11 @tab Length + 2 byte year, 1 byte MMDDHHMMSS, 4 byte billionth of a second -@item datetime @tab 1 + 0-11 @tab Length + 2 byte year, 1 byte MMDDHHMMSS, 4 byte billionth of a second -@item time @tab 1 + 0-14 @tab Length + sign (0 = pos, 1= neg), 4 byte days, 1 byte HHMMDD, 4 byte billionth of a second -@end multitable - -The first byte is a length byte and then comes all parameters that are -not 0. (Always counted from the beginning). - -@node Fulltext Search, MyISAM Record Structure, protocol, Top -@chapter Fulltext Search in MySQL - -Hopefully, sometime there will be complete description of -fulltext search algorithms. -Now it's just unsorted notes. - -@menu -* Weighting in boolean mode:: -@end menu - -@node Weighting in boolean mode, , Fulltext Search, Fulltext Search -@section Weighting in boolean mode - -The basic idea is as follows: in expression -@code{A or B or (C and D and E)}, either @code{A} or @code{B} alone -is enough to match the whole expression. While @code{C}, -@code{D}, and @code{E} should @strong{all} match. So it's -reasonable to assign weight 1 to @code{A}, @code{B}, and -@code{(C and D and E)}. And @code{C}, @code{D}, and @code{E} -should get a weight of 1/3. - -Things become more complicated when considering boolean -operators, as used in MySQL FTB. Obvioulsy, @code{+A +B} -should be treated as @code{A and B}, and @code{A B} - -as @code{A or B}. The problem is, that @code{+A B} can @strong{not} -be rewritten in and/or terms (that's the reason why this - extended - -set of operators was chosen). Still, aproximations can be used. -@code{+A B C} can be approximated as @code{A or (A and (B or C))} -or as @code{A or (A and B) or (A and C) or (A and B and C)}. -Applying the above logic (and omitting mathematical -transformations and normalization) one gets that for -@code{+A_1 +A_2 ... +A_N B_1 B_2 ... B_M} the weights -should be: @code{A_i = 1/N}, @code{B_j=1} if @code{N==0}, and, -otherwise, in the first rewritting approach @code{B_j = 1/3}, -and in the second one - @code{B_j = (1+(M-1)*2^M)/(M*(2^(M+1)-1))}. - -The second expression gives somewhat steeper increase in total -weight as number of matched B's increases, because it assigns -higher weights to individual B's. Also the first expression in -much simplier. So it is the first one, that is implemented in MySQL. - - -@node MyISAM Record Structure, InnoDB Record Structure, Fulltext Search, Top -@chapter MyISAM Record Structure - -@section Introduction - -When you say: -@* - -@strong{CREATE TABLE Table1 ...} -@* - -MySQL creates files named Table1.MYD ("MySQL Data"), Table1.MYI -("MySQL Index"), and Table1.FRM ("Format"). These files will be in the -directory: @* -/<datadir>/<database>/ -@* - -For example, if you use Linux, you might find the files here (assume -your database name is "test"): @* -/usr/local/var/test -@* - -And if you use Windows, you might find the files in this directory: @* -\mysql\data\test\ -@*@* - -Let's look at the .MYD Data file (MyISAM SQL Data file) more closely. - -@table @strong -@item Page Size -Unlike most DBMSs, MySQL doesn't store on disk using pages. Therefore -you will not see filler space between rows. (Reminder: This does not -refer to BDB and INNODB tables, which do use pages). -@* - -@item Record Header -The minimal record header is a set of flags: -@itemize @bullet -@item -"X bit" = 0 if row is deleted, = 1 if row is not deleted -@item -"Null Bits" = 0 if column is not NULL, = 1 if column is NULL -@item -"Filler Bits" = 1 -@end itemize -@end table -@* - -Here's an example. Suppose you say: -@* - -@strong{CREATE TABLE Table1 (column1 CHAR(1), column2 CHAR(1), column3 CHAR(1))} -@* - -@strong{INSERT INTO Table1 VALUES ('a', 'b', 'c')} -@* - -@strong{INSERT INTO Table1 VALUES ('d', NULL, 'e')} -@* - -A CHAR(1) column takes precisely one byte (plus one bit of overhead -that is assigned to every column -- I'll describe the details of -column storage later). So the file Table1.MYD looks like this: -@* - -@strong{Hexadecimal Display of Table1.MYD file}@* -@code{ -F1 61 62 63 00 F5 64 00 66 00 ... .abc..d e. -} -@* - -Here's how to read this hexadecimal-dump display:@* -@itemize @bullet -@item -The hexadecimal numbers @code{F1 61 62 63 00 F5 64 20 66 00} are byte -values and the column on the right is an attempt to show the -same bytes in ASCII. -@item -The @code{F1} byte means that there are no null fields in the first row. -@item -The @code{F5} byte means that the second column of the second row is NULL. -@end itemize - -(It's probably easier to understand the flag setting if you restate -@code{F5} as @code{11110101 binary}, and (a) notice that the third flag bit from the -right is @code{on}, and (b) remember that the first flag bit is the X bit.) -@* - -There are complications -- the record header is more complex if there -are variable-length fields -- but the simple display shown in the -example is exactly what you'd see if you took a debugger and looked -at the MySQL Data file. -@* - -@section Physical Attributes of Columns - -Next I'll describe the physical attributes of each column in a row. -The format depends entirely on the data type and the size of the -column, so, for every data type, I'll give a description and an example. -@* - -@table @strong -@item The character data types - -@strong{CHAR} -@itemize @bullet -@item -Storage: fixed-length string with space padding on the right. -@item -Example: a CHAR(5) column containing the value 'A' looks like:@* -@code{hexadecimal 41 20 20 20 20} -- (length = 5, value = @code{'A '}) -@end itemize - -@strong{VARCHAR} -@itemize @bullet -@item -Storage: variable-length string with a preceding length. -@item -Example: a VARCHAR(7) column containing 'A' looks like:@* -@code{hexadecimal 01 41} -- (length = 1, value = @code{'A'}) -@end itemize - -@item The numeric data types - -Important: MySQL stores all multi-byte binary numbers with the -high byte first. This is called "little-endian" numeric storage; -it's normal on Intel x86 machines; MySQL uses it even for non-Intel -machines so that databases will be portable. -@* - -@strong{TINYINT} -@itemize @bullet -@item -Storage: fixed-length binary, always one byte. -@item -Example: a TINYINT column containing 65 looks like:@* -@code{hexadecimal 41} -- (length = 1, value = 65) -@end itemize - -@strong{SMALLINT} -@itemize @bullet -@item -Storage: fixed-length binary, always two bytes. -@item -Example: a SMALLINT column containing 65 looks like:@* -@code{hexadecimal 41 00} -- (length = 2, value = 65) -@end itemize - -@strong{MEDIUMINT} -@itemize @bullet -@item -Storage: fixed-length binary, always three bytes. -@item -Example: a MEDIUMINT column containing 65 looks like:@* -@code{hexadecimal 41 00 00} -- (length = 3, value = 65) -@end itemize - -@strong{INT} -@itemize @bullet -@item -Storage: fixed-length binary, always four bytes. -@item -Example: an INT column containing 65 looks like:@* -@code{hexadecimal 41 00 00 00} -- (length = 4, value = 65) -@end itemize - -@strong{BIGINT} -@itemize @bullet -@item -Storage: fixed-length binary, always eight bytes. -@item -Example: a BIGINT column containing 65 looks like:@* -@code{hexadecimal 41 00 00 00 00 00 00 00} -- (length = 8, value = 65) -@end itemize - -@strong{FLOAT} -@itemize @bullet -@item -Storage: fixed-length binary, always four bytes. -@item -Example: a FLOAT column containing approximately 65 looks like:@* -@code{hexadecimal 00 00 82 42} -- (length = 4, value = 65) -@end itemize - -@strong{DOUBLE PRECISION} -@itemize @bullet -@item -Storage: fixed-length binary, always eight bytes. -@item -Example: a DOUBLE PRECISION column containing approximately 65 looks like:@* -@code{hexadecimal 00 00 00 00 00 40 50 40} -- (length = 8, value = 65) -@end itemize - -@strong{REAL} -@itemize @bullet -@item -Storage: same as FLOAT, or same as DOUBLE PRECISION, depending on setting of the --ansi switch. -@end itemize - -@strong{DECIMAL} -@itemize @bullet -@item -Storage: fixed-length string, with a leading byte for the sign, if any. -@item -Example: a DECIMAL(2) column containing 65 looks like:@* -@code{hexadecimal 20 36 35} -- (length = 3, value = @code{' 65'}) -@item -Example: a DECIMAL(2) UNSIGNED column containing 65 looks like:@* -@code{hexadecimal 36 35} -- (length = 2, value = @code{'65'}) -@item -Example: a DECIMAL(4,2) UNSIGNED column containing 65 looks like:@* -@code{hexadecimal 36 35 2E 30 30} -- (length = 5, value = @code{'65.00'}) -@end itemize - -@strong{NUMERIC} -@itemize @bullet -@item -Storage: same as DECIMAL. -@end itemize - -@strong{BOOL} -@itemize @bullet -@item -Storage: same as TINYINT. -@end itemize - -@item The temporal data types - -@strong{DATE} -@itemize @bullet -@item -Storage: 3 byte integer, low byte first. -Packed as: 'day + month*32 + year*16*32' -@item -Example: a DATE column containing '1962-01-02' looks like:@* -@code{hexadecimal 22 54 0F} -@end itemize - -@strong{DATETIME} -@itemize @bullet -@item -Storage: eight bytes. -@item -Part 1 is a 32-bit integer containing year*10000 + month*100 + day. -@item -Part 2 is a 32-bit integer containing hour*10000 + minute*100 + second. -@item -Example: a DATETIME column for '0001-01-01 01:01:01' looks like:@* -@code{hexadecimal B5 2E 11 5A 02 00 00 00} -@end itemize - -@strong{TIME} -@itemize @bullet -@item -Storage: 3 bytes, low byte first. -This is stored as seconds: days*24*3600+hours*3600+minutes*60+seconds -@item -Example: a TIME column containing '1 02:03:04' (1 day 2 hour 3 minutes and 4 seconds) looks like:@* -@code{hexadecimal 58 6E 01} -@end itemize - -@strong{TIMESTAMP} -@itemize @bullet -@item -Storage: 4 bytes, low byte first. -Stored as unix @code{time()}, which is seconds since the Epoch -(00:00:00 UTC, January 1, 1970). -@item -Example: a TIMESTAMP column containing '2003-01-01 01:01:01' looks like:@* -@code{hexadecimal 4D AE 12 23} -@end itemize - -@strong{YEAR} -@itemize @bullet -@item -Storage: same as unsigned TINYINT with a base value of 0 = 1901. -@end itemize - -@item Others - -@strong{SET} -@itemize @bullet -@item -Storage: one byte for each eight members in the set. -@item -Maximum length: eight bytes (for maximum 64 members). -@item -This is a bit list. The least significant bit corresponds to the -first listed member of the set. -@item -Example: a SET('A','B','C') column containing 'A' looks like:@* -@code{01} -- (length = 1, value = 'A') -@end itemize - -@strong{ENUM} -@itemize @bullet -@item -Storage: one byte if less than 256 alternatives, else two bytes. -@item -This is an index. The value 1 corresponds to the first listed -alternative. (Note: ENUM always reserves 0 for a blank '' value. This -explains why 'A' is 1 instead of 0.) -@item -Example: an ENUM('A','B','C') column containing 'A' looks like:@* -@code{01} -- (length = 1, value = 'A') -@end itemize - -@item The Large-Object data types - -Warning: Because TINYBLOB's preceding length is one byte long (the -size of a TINYINT) and MEDIUMBLOB's preceding length is three bytes -long (the size of a MEDIUMINT), it's easy to think there's some sort -of correspondence between the BLOB and the INT types. There isn't -- a -BLOB's preceding length is not four bytes long (the size of an INT). -@* - -(NOTE TO SELF: BLOB storage has not been fully addressed here.) -@* - -@strong{TINYBLOB} -@itemize @bullet -@item -Storage: variable-length string with a preceding one-byte length. -@item -Example: a TINYBLOB column containing 'A' looks like:@* -@code{hexadecimal 01 41} -- (length = 2, value = 'A') -@end itemize - -@strong{TINYTEXT} -@itemize @bullet -@item -Storage: same as TINYBLOB. -@end itemize - -@strong{BLOB} -@itemize @bullet -@item -Storage: variable-length string with a preceding two-byte length. -@item -Example: a BLOB column containing 'A' looks like:@* -@code{hexadecimal 01 00 41} -- (length = 2, value = 'A') -@end itemize - -@strong{TEXT} -@itemize @bullet -@item -Storage: same as BLOB. -@end itemize - -@strong{MEDIUMBLOB} -@itemize @bullet -@item -Storage: variable-length string with a preceding length. -@item -Example: a MEDIUMBLOB column containing 'A' looks like:@* -@code{hexadecimal 01 00 00 41} -- (length = 4, value = 'A') -@end itemize - -@strong{MEDIUMTEXT} -@itemize @bullet -@item -Storage: same as MEDIUMBLOB. -@end itemize - -@strong{LONGBLOB} -@itemize @bullet -@item -Storage: variable-length string with a preceding four-byte length. -@item -Example: a LONGBLOB column containing 'A' looks like:@* -@code{hexadecimal 01 00 00 00 41} -- (length = 5, value = 'A') -@end itemize - -@strong{LONGTEXT} -@itemize @bullet -@item -Storage: same as LONGBLOB. -@end itemize - -@end table - -@section Where to Look For More Information - -@strong{References:} @* -Most of the formatting work for MyISAM columns is visible -in the program /sql/field.cc in the source code directory. -@* - -@node InnoDB Record Structure,InnoDB Page Structure,MyISAM Record Structure,Top -@chapter InnoDB Record Structure - -This page contains: -@itemize @bullet -@item -A high-altitude "summary" picture of the parts of a MySQL/InnoDB -record structure. -@item -A description of each part. -@item -An example. -@end itemize - -After reading this page, you will know how MySQL/InnoDB stores a -physical record. -@* - -@section High-Altitude Picture - -The chart below shows the three parts of a physical record. - -@multitable @columnfractions .10 .35 - -@item @strong{Name} @tab @strong{Size} -@item Field Start Offsets -@tab (F*1) or (F*2) bytes -@item Extra Bytes -@tab 6 bytes -@item Field Contents -@tab depends on content - -@end multitable - -Legend: The letter 'F' stands for 'Number Of Fields'. - -The meaning of the parts is as follows: -@itemize @bullet -@item -The FIELD START OFFSETS is a list of numbers containing the -information "where a field starts". -@item -The EXTRA BYTES is a fixed-size header. -@item -The FIELD CONTENTS contains the actual data. -@end itemize - -@strong{An Important Note About The Word "Origin"}@* -The "Origin" or "Zero Point" of a record is the first byte of the -Field Contents -- not the first byte of the Field Start Offsets. If -there is a pointer to a record, that pointer is pointing to the -Origin. Therefore the first two parts of the record are addressed by -subtracting from the pointer, and only the third part is addressed by -adding to the pointer. - -@subsection FIELD START OFFSETS - -The Field Start Offsets is a list in which each entry is the -position, relative to the Origin, of the start of the next field. The -entries are in reverse order, that is, the first field's offset is at -the end of the list. -@* - -An example: suppose there are three columns. The first column's length -is 1, the second column's length is 2, and the third column's length is 4. -In this case, the offset values are, respectively, 1, 3 (1+2), and 7 (1+2+4). -Because values are reversed, a core dump of the Field Start Offsets -would look like this: @code{07,03,01}. -@* - -There are two complications for special cases: -@itemize @bullet -@item -Complication #1: The size of each offset can be either one byte or -two bytes. One-byte offsets are only usable if the total record size -is less than 127. There is a flag in the "Extra Bytes" part which will -tell you whether the size is one byte or two bytes. -@item -Complication #2: The most significant bits of an offset may contain -flag values. The next two paragraphs explain what the contents are. -@end itemize - -@strong{When The Size Of Each Offset Is One Byte} -@itemize @bullet -@item -1 bit = 0 if field is non-NULL, = 1 if field is NULL -@item -7 bits = the actual offset, a number between 0 and 127 -@end itemize - -@strong{When The Size Of Each Offset Is Two Bytes} -@itemize @bullet -@item -1 bit = 0 if field is non-NULL, = 1 if field is NULL -@item -1 bit = 0 if field is on same page as offset, = 1 if field and offset are on different pages -@item -14 bits = the actual offset, a number between 0 and 16383 -@end itemize - -It is unlikely that the "field and offset are on different pages" -unless the record contains a large BLOB. - -@subsection EXTRA BYTES - -The Extra Bytes are a fixed six-byte header. - -@multitable @columnfractions .10 .25 .35 - -@item @strong{Name} @tab @strong{Size} @tab @strong{Description} -@item @strong{info_bits:} -@item () -@tab 1 bit -@tab unused or unknown -@item () -@tab 1 bit -@tab unused or unknown -@item deleted_flag -@tab 1 bit -@tab 1 if record is deleted -@item min_rec_flag -@tab 1 bit -@tab 1 if record is predefined minimum record -@item n_owned -@tab 4 bits -@tab number of records owned by this record -@item heap_no -@tab 13 bits -@tab record's order number in heap of index page -@item n_fields -@tab 10 bits -@tab number of fields in this record, 1 to 1023 -@item 1byte_offs_flag -@tab 1 bit -@tab 1 if each Field Start Offsets is 1 byte long (this item is also called the "short" flag) -@item @strong{next 16 bits} -@tab 16 bits -@tab pointer to next record in page -@item @strong{TOTAL} -@tab 48 bits - -@end multitable - -Total size is 48 bits, which is six bytes. -@* - -If you're just trying to read the record, the key bit in the Extra -Bytes is 1byte_offs_flag -- you need to know if 1byte_offs_flag is 1 -(i.e.: "short 1-byteoffsets") or 0 (i.e.: "2-byte offsets"). -@* - -Given a pointer to the Origin, InnoDB finds the start of the record as follows: -@itemize @bullet -@item -Let X = n_fields (the number of fields is by definition equal to the -number of entries in the Field Start Offsets Table). -@item -If 1byte_offs_flag equals 0, then let X = X * 2 because there are -two bytes for each entry instead of just one. -@item -Let X = X + 6, because the fixed size of Extra Bytes is 6. -@item -The start of the record is at (pointer value minus X). -@end itemize - -@subsection FIELD CONTENTS - -The Field Contents part of the record has all the data. Fields are -stored in the order they were defined in. -@* - -There are no markers between fields, and there is no marker or filler -at the end of a record. -@* - -Here's an example. -@itemize @bullet -@item -I made a table with this definition: -@*@* - -@strong{CREATE TABLE T - (FIELD1 VARCHAR(3), FIELD2 VARCHAR(3), FIELD3 VARCHAR(3)) - Type=InnoDB;} -@*@* - -To understand what follows, you must know that table T has six columns --- not three -- because InnoDB automatically added three "system -columns" at the start for its own housekeeping. It happens that these -system columns are the row ID, the transaction ID, and the rollback -pointer, but their values don't matter now. Regard them as three black -boxes. -@*@* - -@item -I put some rows in the table. My last three INSERTs were: -@*@* - -@strong{INSERT INTO T VALUES ('PP', 'PP', 'PP')} -@*@* - -@strong{INSERT INTO T VALUES ('Q', 'Q', 'Q')} -@*@* - -@strong{INSERT INTO T VALUES ('R', NULL, NULL)} -@*@* - -@item -I ran Borland's TDUMP to get a hexadecimal dump of -the contents of \mysql\data\ibdata1, which (in my case) is the -MySQL/InnoDB data file (on Windows). -@end itemize - -Here is an extract of the dump: - -@multitable @columnfractions .05 .95 - -@item @strong{Address Values In Hexadecimal} @tab @strong{Values In ASCII} -@item @code{0D4280: 00 00 2D 00 84 4F 4F 4F 4F 4F 4F 4F 4F 4F 19 17} -@tab @code{..-..OOOOOOOOO..} -@item @code{0D4290: 15 13 0C 06 00 00 78 0D 02 BF 00 00 00 00 04 21} -@tab @code{......x........!} -@item @code{0D42A0: 00 00 00 00 09 2A 80 00 00 00 2D 00 84 50 50 50} -@tab @code{.....*....-..PPP} -@item @code{0D42B0: 50 50 50 16 15 14 13 0C 06 00 00 80 0D 02 E1 00} -@tab @code{PPP.............} -@item @code{0D42C0: 00 00 00 04 22 00 00 00 00 09 2B 80 00 00 00 2D} -@tab @code{....".....+....-} -@item @code{0D42D0: 00 84 51 51 51 94 94 14 13 0C 06 00 00 88 0D 00} -@tab @code{..QQQ...........} -@item @code{0D42E0: 74 00 00 00 00 04 23 00 00 00 00 09 2C 80 00 00} -@tab @code{t.....#.....,...} -@item @code{0D42F0: 00 2D 00 84 52 00 00 00 00 00 00 00 00 00 00 00} -@tab @code{.-..R...........} - -@end multitable - -A reformatted version of the dump, showing only the relevant bytes, -looks like this (I've put a line break after each field and added labels): - -@strong{Reformatted Hexadecimal Dump}@* -@code{ - 19 17 15 13 0C 06 Field Start Offsets /* First Row */@* - 00 00 78 0D 02 BF Extra Bytes@* - 00 00 00 00 04 21 System Column #1@* - 00 00 00 00 09 2A System Column #2@* - 80 00 00 00 2D 00 84 System Column #3@* - 50 50 Field1 'PP'@* - 50 50 Field2 'PP'@* - 50 50 Field3 'PP'}@* - -@code{ - 16 15 14 13 0C 06 Field Start Offsets /* Second Row */@* - 00 00 80 0D 02 E1 Extra Bytes@* - 00 00 00 00 04 22 System Column #1@* - 00 00 00 00 09 2B 80 System Column #2@* - 00 00 00 2D 00 84 System Column #3@* - 51 Field1 'Q'@* - 51 Field2 'Q'@* - 51 Field3 'Q'}@* - -@code{ - 94 94 14 13 0C 06 Field Start Offsets /* Third Row */@* - 00 00 88 0D 00 74 Extra Bytes@* - 00 00 00 00 04 23 System Column #1@* - 00 00 00 00 09 2C System Column #2@* - 80 00 00 00 2D 00 84 System Column #3@* - 52 Field1 'R'}@* -@* - -You won't need explanation if you followed everything I've said, but -I'll add helpful notes for the three trickiest details. -@itemize @bullet -@item -Helpful Notes About "Field Start Offsets": @* -Notice that the sizes of the record's fields, in forward order, are: -6, 6, 7, 2, 2, 2. Since each offset is for the start of the "next" -field, the hexadecimal offsets are 06, 0c (6+6), 13 (6+6+7), 15 -(6+6+7+2), 17 (6+6+7+2+2), 19 (6+6+7+2+2+2). Reversing the order, the -Field Start Offsets of the first record are: @code{19,17,15,13,0c,06}. -@item -Helpful Notes About "Extra Bytes": @* -Look at the Extra Bytes of the first record: @code{00 00 78 0D 02 BF}. The -fourth byte is @code{0D hexadecimal}, which is @code{1101 binary} ... the 110 is the -last bits of n_fields (@code{110 binary} is 6 which is indeed the number of -fields in the record) and the final 1 bit is 1byte_offs_flag. The -fifth and sixth bytes, which contain @code{02 BF}, constitute the "next" -field. Looking at the original hexadecimal dump, at address -@code{0D42BF} (which is position @code{02BF} within the page), you'll see the beginning bytes of -System Column #1 of the second row. In other words, the "next" field -points to the "Origin" of the following row. -@item -Helpful Notes About NULLs:@* -For the third row, I inserted NULLs in FIELD2 and FIELD3. Therefore in -the Field Start Offsets the top bit is @code{on} for these fields (the -values are @code{94 hexadecimal}, @code{94 hexadecimal}, instead of -@code{14 hexadecimal}, @code{14 hexadecimal}). And the row is -shorter because the NULLs take no space. -@end itemize - -@section Where to Look For More Information - -@strong{References:} @* -The most relevant InnoDB source-code files are rem0rec.c, rem0rec.ic, -and rem0rec.h in the rem ("Record Manager") directory. - -@node InnoDB Page Structure,Files in MySQL Sources,InnoDB Record Structure,Top -@chapter InnoDB Page Structure - -InnoDB stores all records inside a fixed-size unit which is commonly called a -"page" (though InnoDB sometimes calls it a "block" instead). -Currently all pages are the same size, 16KB. -@* - -A page contains records, but it also contains headers and trailers. -I'll start this description with a high-altitude view of a page's parts, -then I'll describe each part of a page. Finally, I'll show an example. This -discussion deals only with the most common format, for the leaf page of a data file. -@* - -@section High-Altitude View - -An InnoDB page has seven parts: -@itemize @bullet -@item -Fil Header -@item -Page Header -@item -Infimum + Supremum Records -@item -User Records -@item -Free Space -@item -Page Directory -@item -Fil Trailer -@end itemize - -As you can see, a page has two header/trailer pairs. The inner pair, "Page Header" and -"Page Directory", are mostly the concern of the \page program group, -while the outer pair, "Fil Header" and "Fil Trailer", are mostly the -concern of the \fil program group. The "Fil" header also goes goes by -the name of "File Page Header". -@* - -Sandwiched between the headers and trailers, are the records and -the free (unused) space. A page always begins with two unchanging -records called the Infimum and the Supremum. Then come the user -records. Between the user records (which grow downwards) and the page -directory (which grows upwards) there is space for new records. -@* - -@subsection Fil Header - -The Fil Header has eight parts, as follows: - -@multitable @columnfractions .10 .30 .35 - -@item @strong{Name} @tab @strong{Size} @tab @strong{Remarks} -@item FIL_PAGE_SPACE -@tab 4 -@tab 4 ID of the space the page is in -@item FIL_PAGE_OFFSET -@tab 4 -@tab ordinal page number from start of space -@item FIL_PAGE_PREV -@tab 4 -@tab offset of previous page in key order -@item FIL_PAGE_NEXT -@tab 4 -@tab offset of next page in key order -@item FIL_PAGE_LSN -@tab 8 -@tab log serial number of page's latest log record -@item FIL_PAGE_TYPE -@tab 2 -@tab current defined types are: FIL_PAGE_INDEX, FIL_PAGE_UNDO_LOG, FIL_PAGE_INODE, FIL_PAGE_IBUF_FREE_LIST -@item FIL_PAGE_FILE_FLUSH_LSN -@tab 8 -@tab "the file has been flushed to disk at least up to this lsn" (log serial number), - valid only on the first page of the file -@item FIL_PAGE_ARCH_LOG_NO -@tab 4 -@tab the latest archived log file number at the time that FIL_PAGE_FILE_FLUSH_LSN was written (in the log) -@end multitable - -@itemize -@item -FIL_PAGE_SPACE is a necessary identifier because different pages might belong to -different (table) spaces within the same file. The word -"space" is generic jargon for either "log" or "tablespace". -@*@* - -@item -FIL_PAGE_PREV and FIL_PAGE_NEXT are the page's "backward" and -"forward" pointers. To show what they're about, I'll draw a two-level -B-tree. -@*@* - -@example - -------- - - root - - -------- - | - ---------------------- - | | - | | - -------- -------- - - leaf - <--> - leaf - - -------- -------- -@end example -@* - -Everyone has seen a B-tree and knows that the entries in the root page -point to the leaf pages. (I indicate those pointers with vertical '|' -bars in the drawing.) But sometimes people miss the detail that leaf -pages can also point to each other (I indicate those pointers with a horizontal -two-way pointer '<-->' in the drawing). This feature allows InnoDB to navigate from -leaf to leaf without having to back up to the root level. This is a -sophistication which you won't find in the classic B-tree, which is -why InnoDB should perhaps be called a B+-tree instead. -@*@* - -@item -The fields FIL_PAGE_FILE_FLUSH_LSN, FIL_PAGE_PREV, and FIL_PAGE_NEXT -all have to do with logs, so I'll refer you to my article "How Logs -Work With MySQL And InnoDB" on devarticles.com. -@*@* - -@item -FIL_PAGE_FILE_FLUSH_LSN and FIL_PAGE_ARCH_LOG_NO are only valid for -the first page of a data file. -@end itemize - -@subsection Page Header - -The Page Header has 14 parts, as follows: -@*@* - -@multitable @columnfractions .10 .20 .30 - -@item @strong{Name} @tab @strong{Size} @tab @strong{Remarks} -@item PAGE_N_DIR_SLOTS -@tab 2 -@tab number of directory slots in the Page Directory part; initial value = 2 -@item PAGE_HEAP_TOP -@tab 2 -@tab record pointer to first record in heap -@item PAGE_N_HEAP -@tab 2 -@tab number of heap records; initial value = 2 -@item PAGE_FREE -@tab 2 -@tab record pointer to first free record -@item PAGE_GARBAGE -@tab 2 -@tab "number of bytes in deleted records" -@item PAGE_LAST_INSERT -@tab 2 -@tab record pointer to the last inserted record -@item PAGE_DIRECTION -@tab 2 -@tab either PAGE_LEFT, PAGE_RIGHT, or PAGE_NO_DIRECTION -@item PAGE_N_DIRECTION -@tab 2 -@tab number of consecutive inserts in the same direction, e.g. "last 5 were all to the left" -@item PAGE_N_RECS -@tab 2 -@tab number of user records -@item PAGE_MAX_TRX_ID -@tab 8 -@tab the highest ID of a transaction which might have changed a record on the page (only set for secondary indexes) -@item PAGE_LEVEL -@tab 2 -@tab level within the index (0 for a leaf page) -@item PAGE_INDEX_ID -@tab 8 -@tab identifier of the index the page belongs to -@item PAGE_BTR_SEG_LEAF -@tab 10 -@tab "file segment header for the leaf pages in a B-tree" (this is irrelevant here) -@item PAGE_BTR_SEG_TOP -@tab 10 -@tab "file segment header for the non-leaf pages in a B-tree" (this is irrelevant here) - -@end multitable -@* - -(Note: I'll clarify what a "heap" is when I discuss the User Records part of the page.) -@*@* - -Some of the Page Header parts require further explanation: -@itemize @bullet -@item -PAGE_FREE: @* -Records which have been freed (due to deletion or migration) are in a -one-way linked list. The PAGE_FREE pointer in the page header points -to the first record in the list. The "next" pointer in the record -header (specifically, in the record's Extra Bytes) points to the next -record in the list. -@item -PAGE_DIRECTION and PAGE_N_DIRECTION: @* -It's useful to know whether inserts are coming in a constantly -ascending sequence. That can affect InnoDB's efficiency. -@item -PAGE_HEAP_TOP and PAGE_FREE and PAGE_LAST_INSERT: @* -Warning: Like all record pointers, these point not to the beginning of the -record but to its Origin (see the earlier discussion of Record -Structure). -@item -PAGE_BTR_SEG_LEAF and PAGE_BTR_SEG_TOP: @* -These variables contain information (space ID, page number, and byte offset) about -index node file segments. InnoDB uses the information for allocating new pages. -There are two different variables because InnoDB allocates separately for leaf -pages and upper-level pages. -@end itemize - -@subsection The Infimum And Supremum Records - -"Infimum" and "supremum" are real English words but they are found -only in arcane mathematical treatises, and in InnoDB comments. To -InnoDB, an infimum is lower than the the lowest possible real value -(negative infinity) and a supremum is greater than the greatest -possible real value (positive infinity). InnoDB sets up an infimum -record and a supremum record automatically at page-create time, and -never deletes them. They make a useful barrier to navigation so that -"get-prev" won't pass the beginning and "get-next" won't pass the end. -Also, the infimum record can be a dummy target for temporary record -locks. -@*@* - -The InnoDB code comments distinguish between "the infimum and supremum -records" and the "user records" (all other kinds). -@*@* - -It's sometimes unclear whether InnoDB considers the infimum and -supremum to be part of the header or not. Their size is fixed and -their position is fixed, so I guess so. - -@subsection User Records - -In the User Records part of a page, you'll find all the records that the user -inserted. -@*@* - -There are two ways to navigate through the user records, depending -whether you want to think of their organization as an unordered or an -ordered list. -@*@* - -An unordered list is often called a "heap". If you make a pile of -stones by saying "whichever one I happen to pick up next will go on -top" -- rather than organizing them according to size and colour -- -then you end up with a heap. Similarly, InnoDB does not want to insert -new rows according to the B-tree's key order (that would involve -expensive shifting of large amounts of data), so it inserts new rows -right after the end of the existing rows (at the -top of the Free Space part) or wherever there's space left by a -deleted row. -@*@* - -But by definition the records of a B-tree must be accessible in order -by key value, so there is a record pointer in each record (the "next" -field in the Extra Bytes) which points to the next record in key -order. In other words, the records are a one-way linked list. So -InnoDB can access rows in key order when searching. - -@subsection Free Space - -I think it's clear what the Free Space part of a page is, from the discussion of -other parts. - -@subsection Page Directory - -The Page Directory part of a page has a variable number of record pointers. -Sometimes the record pointers are called "slots" or "directory slots". -Unlike other DBMSs, InnoDB does not have a slot for every record in -the page. Instead it keeps a sparse directory. In a fullish page, -there will be one slot for every six records. -@*@* - -The slots track the records' logical order (the order by key rather -than the order by placement on the heap). Therefore, if the records -are @code{'A' 'B' 'F' 'D'} the slots will be @code{(pointer to 'A') (pointer to -'B') (pointer to 'D') (pointer to 'F')}. Because the slots are in key -order, and each slot has a fixed size, it's easy to do a binary -search of the records on the page via the slots. -@*@* - -(Since the Page Directory does not have a slot for every record, -binary search can only give a rough position and then InnoDB must -follow the "next" record pointers. InnoDB's "sparse slots" policy also -accounts for the n_owned field in the Extra Bytes part of a record: -n_owned indicates how many more records must be gone through because -they don't have their own slots.) - -@subsection Fil Trailer - -The Fil Trailer has one part, as follows: -@*@* - -@multitable @columnfractions .10 .35 .40 - -@item @strong{Name} @tab @strong{Size} @tab @strong{Remarks} -@item FIL_PAGE_END_LSN -@tab 8 -@tab low 4 bytes = checksum of page, last 4 bytes = same as FIL_PAGE_LSN -@end multitable -@* - -The final part of a page, the fil trailer (or File Page Trailer), -exists because InnoDB's architect worried about integrity. It's -impossible for a page to be only half-written, or corrupted by -crashes, because the log-recovery mechanism restores to a consistent -state. But if something goes really wrong, then it's nice to have a -checksum, and to have a value at the very end of the page which must -be the same as a value at the very beginning of the page. - -@section Example - -For this example, I used Borland's TDUMP again, as I did for the earlier chapter on -Record Format. This is what a page looked like: -@*@* - -@multitable @columnfractions .05 .95 - -@item @strong{Address Values In Hexadecimal} @tab @strong{Values In ASCII} -@item @code{0D4000: 00 00 00 00 00 00 00 35 FF FF FF FF FF FF FF FF} -@tab @code{.......5........} -@item @code{0D4010: 00 00 00 00 00 00 E2 64 45 BF 00 00 00 00 00 00} -@tab @code{.......dE.......} -@item @code{0D4020: 00 00 00 00 00 00 00 05 02 F5 00 12 00 00 00 00} -@tab @code{................} -@item @code{0D4030: 02 E1 00 02 00 0F 00 10 00 00 00 00 00 00 00 00} -@tab @code{................} -@item @code{0D4040: 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00} -@tab @code{................} -@item @code{0D4050: 00 02 16 B2 00 00 00 00 00 00 00 02 15 F2 08 01} -@tab @code{................} -@item @code{0D4060: 00 00 03 00 89 69 6E 66 69 6D 75 6D 00 09 05 00} -@tab @code{.....infimum....} -@item @code{0D4070: 08 03 00 00 73 75 70 72 65 6D 75 6D 00 22 1D 18} -@tab @code{....supremum."..} -@item @code{0D4080: 13 0C 06 00 00 10 0D 00 B7 00 00 00 00 04 14 00} -@tab @code{................} -@item @code{0D4090: 00 00 00 09 1D 80 00 00 00 2D 00 84 41 41 41 41} -@tab @code{.........-..AAAA} -@item @code{0D40A0: 41 41 41 41 41 41 41 41 41 41 41 1F 1B 17 13 0C} -@tab @code{AAAAAAAAAAA.....} -@item @code{ ... } -@item @code{ ... } -@item @code{0D7FE0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 74} -@tab @code{...............t} -@item @code{0D7FF0: 02 47 01 AA 01 0A 00 65 3A E0 AA 71 00 00 E2 64} -@tab @code{.G.....e:..q...d} -@end multitable -@*@* - -Let's skip past the first 38 bytes, which are Fil Header. The bytes -of the Page Header start at location @code{0d4026 hexadecimal}: -@*@* - -@multitable @columnfractions .10 .45 .60 - -@item @strong{Location} @tab @strong{Name} @tab @strong{Description} -@item @code{00 05} -@tab PAGE_N_DIR_SLOTS -@tab There are 5 directory slots. -@item @code{02 F5} -@tab PAGE_HEAP_TOP -@tab At location @code{0402F5}, not shown, is the beginning of free space. -Maybe a better name would have been PAGE_HEAP_END -@item @code{00 12} -@tab PAGE_N_HEAP -@tab There are 18 (hexadecimal 12) records in the page. -@item @code{00 00} -@tab PAGE_FREE -@tab There are zero free (deleted) records. -@item @code{00 00} -@tab PAGE_GARBAGE -@tab There are zero bytes in deleted records. -@item @code{02 E1} -@tab PAGE_LAST_INSERT -@tab The last record was inserted at location @code{02E1}, not shown, within the page. -@item @code{00 02} -@tab PAGE_DIRECTION -@tab A glance at page0page.h will tell you that 2 is the #defined value for PAGE_RIGHT. -@item @code{00 0F} -@tab PAGE_N_DIRECTION -@tab The last 15 (hexadecimal 0F) inserts were all done "to the right" -because I was inserting in ascending order. -@item @code{00 10} -@tab PAGE_N_RECS -@tab There are 16 (hexadecimal 10) user records. Notice that PAGE_N_RECS is -smaller than the earlier field, PAGE_N_HEAP. -@item @code{00 00 00 00 00 00 00} -@tab PAGE_MAX_TRX_ID -@item @code{00 00} -@tab PAGE_LEVEL -@tab Zero because this is a leaf page. -@item @code{00 00 00 00 00 00 00 14} -@tab PAGE_INDEX_ID -@tab This is index number 20. -@item @code{00 00 00 00 00 00 00 02 16 B2} -@tab PAGE_BTR_SEG_LEAF -@item @code{00 00 00 00 00 00 00 02 15 F2} -@tab PAGE_BTR_SEG_TOP -@end multitable -@* - -Immediately after the page header are the infimum and supremum -records. Looking at the "Values In ASCII" column in the hexadecimal -dump, you will see that the contents are in fact the words "infimum" -and "supremum" respectively. -@*@* - -Skipping past the User Records and the Free Space, many bytes later, -is the end of the 16KB page. The values shown there are the two trailers. -@itemize @bullet -@item -The first trailer (@code{00 74, 02 47, 01 AA, 01 0A, 00 65}) is the page -directory. It has 5 entries, because the header field PAGE_N_DIR_SLOTS -says there are 5. -@item -The next trailer (@code{3A E0 AA 71, 00 00 E2 64}) is the fil trailer. Notice -that the last four bytes, @code{00 00 E2 64}, appeared before in the fil -header. -@end itemize - -@section Where to Look For More Information - -@strong{References:} @* -The most relevant InnoDB source-code files are page0page.c, -page0page.ic, and page0page.h in \page directory. - -@node Files in MySQL Sources,Files in InnoDB Sources,InnoDB Page Structure,Top -@chapter Annotated List Of Files in the MySQL Source Code Distribution - -This is a description of the files that you get when you download the -source code of MySQL. This description begins with a list -of the 43 directories and a short comment about each one. Then, for -each directory, in alphabetical order, a longer description is -supplied. When a directory contains significant program files, a list of each C -program is given along with an explanation of its intended function. - -@section Directory Listing - -@strong{Directory -- Short Comment} -@itemize @bullet -@item -bdb -- The Berkeley Database table handler -@item -BitKeeper -- BitKeeper administration -@item -BUILD -- Build switches -@item -Build-tools -- Build tools -@item -client -- Client library -@item -cmd-line-utils -- Command-line utilities -@item -dbug -- Fred Fish's dbug library -@item -div -- Deadlock test -@item -Docs -- Preliminary documents about internals and new modules -@item -extra -- Eight minor standalone utility programs -@item -fs -- File System -@item -heap -- The HEAP table handler -@item -Images -- Empty directory -@item -include -- Include (*.h) files -@item -innobase -- The Innobase (InnoDB) table handler -@item -isam -- The ISAM (MySQL) table handler -@item -libmysql -- For producing MySQL as a library (e.g. a Windows DLL) -@item -libmysql_r -- Only one file, a makefile -@item -libmysqld -- The MySQL Library -@item -man -- Manual pages -@item -merge -- The MERGE table handler (see Reference Manual section 7.2) -@item -myisam -- The MyISAM table handler -@item -myisammrg -- The MyISAM Merge table handler -@item -mysql-test -- A test suite for mysqld -@item -mysys -- MySQL system library (Low level routines for file access -etc.) -@item -netware -- Files related to the Novell NetWare version of MySQL -@item -NEW-RPMS -- New "RPM Package Manager" files -@item -os2 -- Routines for working with the OS/2 operating system -@item -pstack -- Process stack display -@item -regex -- Regular Expression library for support of REGEXP function -@item -repl-tests -- Test cases for replication -@item -SCCS -- Source Code Control System -@item -scripts -- SQL batches, e.g. for converting msql to MySQL -@item -sql -- Programs for handling SQL commands. The "core" of MySQL -@item -sql-bench -- The MySQL benchmarks -@item -SSL -- Secure Sockets Layer -@item -strings -- Library for C string routines, e.g. atof, strchr -@item -support-files -- 15 files used for building, containing switches? -@item -tests -- Tests in Perl -@item -tools -- mysqlmanager.c -@item -VC++Files -- Includes this entire directory, repeated for VC++ -(Windows) use -@item -vio -- Virtual I/O Library -@item -zlib -- data compression library -@end itemize - -@subsection bdb - -The Berkeley Database table handler. -@*@* - -The Berkeley Database (BDB) is maintained by Sleepycat Software. -@*@* - -The documentation for BDB is available at -http://www.sleepycat.com/docs/. Since it's reasonably thorough -documentation, a description of the BDB program files is not included -in this document. -@*@* - -@subsection BitKeeper - -BitKeeper administration. -@*@* - -This directory may be present if you downloaded the MySQL source using -BitKeeper rather than via the mysql.com site. The files in the -BitKeeper directory are for maintenance purposes only -- they are not -part of the MySQL package. -@*@* - -@subsection BUILD - -Build switches. -@*@* - -This directory contains the build switches for compilation on various -platforms. There is a subdirectory for each set of options. The main -ones are: -@itemize @bullet -@item -alpha -@item -ia64 -@item -pentium (with and without debug or bdb, etc.) -@item -solaris -@end itemize -@*@* - -@subsection Build-tools - -Build tools. -@*@* - -This directory contains batch files for extracting, making -directories, and making programs from source files. There are several -subdirectories -- for building Linux executables, for compiling, for -performing all build steps, etc. -@*@* - -@subsection client - -Client library. -@*@* - -The client library includes mysql.cc (the source of the 'mysql' -executable) and other utilities. Most of the utilities are mentioned -in the MySQL Reference Manual. Generally these are standalone C -programs which one runs in "client mode", that is, they call the -server. -@*@* - -The C program files in the directory are: -@itemize @bullet -@item -connect_test.c -- test that a connect is possible -@item -get_password.c -- ask for a password from the console -@item -insert_test.c -- test that an insert is possible -@item -list_test.c -- test that a select is possible -@item -mysql.cc -- "The MySQL command tool" -@item -mysqladmin.c -- maintenance of MYSQL databases -@item -mysqlcheck.c -- check all databases, check connect, etc. -@item -mysqldump.c -- dump table's contents in ascii -@item -mysqlimport.c -- import file into a table -@item -mysqlmanager-pwgen.c -- pwgen seems to stand for "password -generation" -@item -mysqlmanagerc.c -- entry point for mysql manager -@item -mysqlshow.c -- show databases, tables or columns -@item -mysqltest.c -- test program -@item -password.c -- password checking routines -@item -select_test.c -- test that a select is possible -@item -showdb_test.c -- test that a show-databases is possible -@item -ssl_test.c -- test that SSL is possible -@item -thread_test.c -- test that threading is possible -@end itemize -@*@* - -@subsection cmd-line-utils - -Command-line utilities. -@*@* - -There are two subdirectories: \readline and \libedit. All the files -here are "non-MYSQL" files, in the sense that MySQL AB didn't produce -them, it just uses them. It should be unnecessary to study the -programs in these files unless -you are writing or debugging a tty-like client for MySQL, such as -mysql.exe. -@*@* - -The \readline subdirectory contains the files of the GNU Readline -Library, "a library for reading lines of text with interactive input -and history editing". The programs are copyrighted by the Free -Software Foundation. -@*@* - -The \libedit (library of edit functions) subdirectory has files -written by Christos Zoulas. They are for editing the line contents. -These are the program files in the \libedit subdirectory: -@itemize @bullet -@item -chared.c -- character editor -@item -common.c -- common editor functions -@item -el.c -- editline interface functions -@item -emacs.c -- emacs functions -@item -fgetln.c -- get line -@item -hist.c -- history access functions -@item -history.c -- more history access functions -@item -key.c -- procedures for maintaining the extended-key map -@item -map.c -- editor function definitions -@item -parse.c -- parse an editline extended command -@item -prompt.c -- prompt printing functions -@item -read.c -- terminal read functions -@item -readline.c -- read line -@item -refresh.c -- "lower level screen refreshing functions" -@item -search.c -- "history and character search functions" -@item -sig.c -- for signal handling -@item -strlcpy.c -- string copy -@item -term.c -- "editor/termcap-curses interface" -@item -tokenizer.c -- Bourne shell line tokenizer -@item -tty.c -- for a tty interface -@item -vi.c -- commands used when in the vi (editor) mode -@end itemize -@*@* - -@subsection dbug - -Fred Fish's dbug library. -@*@* - -This is not really part of the MySQL package. Rather, it's a set of -public-domain routines which are useful for debugging MySQL programs. -@*@* - -How it works: One inserts a function call that begins with DBUG_* in -one of the regular MYSQL programs. For example, in get_password.c, you -will find this line: @* -DBUG_ENTER("get_tty_password"); @* -at the start of a routine, and this line: @* -DBUG_RETURN(my_strdup(to,MYF(MY_FAE))); @* -at the end of the routine. These lines don't affect production code. -Features of the dbug library include profiling and state pushing. -@*@* - -The C programs in this directory are: -@itemize @bullet -@item -dbug.c -- The main module -@item -dbug_analyze.c -- Reads a file produced by trace functions -@item -example1.c -- A tiny example -@item -example2.c -- A tiny example -@item -example3.c -- A tiny example -@item -factorial.c -- A tiny example -@item -main.c -- A tiny example -@item -sanity.c -- Declaration of a variable -@end itemize -@*@* - -@subsection div - -Deadlock test. -@*@* - -This file contains only one program, deadlock_test.c. -@*@* - -@subsection Docs - -Preliminary documents about internals and new modules. -@*@* - -This directory doesn't have much at present that's very useful to the -student, but the plan is that some documentation related to the source -files and the internal workings of MySQL, including perhaps some -documentation from developers themselves, will be placed here. -@*@* - -These sub-directories are part of this directory: -@itemize @bullet -@item -books -- .gif images and empty .txt files; no real information -@item -flags -- images of flags of countries -@item -images -- flag backgrounds and the MySQL dolphin logo -@item -mysql-logos -- more MySQL-related logos, some of them moving -@item -raw-flags -- more country flags, all .gif files -@item -support -- various files for generating texinfo/docbook -documentation -@item -to-be-included... -- an empty subdirectory -@item -translations -- some Portuguese myodbc documentation -@end itemize -@*@* - -In the main directory, you'll find some .txt files related to the -methods that MySQL uses to produce its printed and html documents, odd -bits in various languages, and the single file in the directory which -has any importance -- internals.texi -- The "MySQL Internals" -document. -@*@* - -Despite the name, internals.texi is not really much of a description -of MySQL internals. However, there is some useful description of the -functions in the mysys directory (see below), and of the structure of -client/server messages (doubtless very useful for people who want to -make their own JDBC drivers, or just sniff). -@*@* - -@subsection extra - -Eight minor standalone utility programs. -@*@* - -These eight programs are all standalone utilities, that is, they have -a main() function and their main role is to show information that the -MySQL server needs or produces. Most are unimportant. They are as -follows: -@itemize @bullet -@item -my_print_defaults.c -- print all parameters in a default file -@item -mysql_install.c -- startup: install MySQL server -@item -mysql_waitpid.c -- wait for a program to terminate -@item -perror.c -- "print error" -- given error number, display message -@item -replace.c -- replace strings in text files -@item -resolve_stack_dump.c -- show symbolic info from a stack dump -@item -resolveip.c -- convert an IP address to a hostname, or vice versa -@end itemize -@*@* - -@subsection fs - -File System. -@*@* - -Here the word "File System" does not refer to the mere idea of a -directory of files on a disk drive, but to object-based access. The -concept has been compared with Oracle's Internet File System (iFS). -@*@* - -The original developer of the files on this directory is Tonu Samuel, -a former MySQL AB employee. Here is a quote (somewhat edited) from -Tonu Samuel's web page (http://no.spam.ee/~tonu/index.php): -"Question: What is it? -Answer: Actually this is not filesystem in common terms. MySQL FS -makes it possible to make SQL tables and some functions available over -a filesystem. MySQL does not require disk space, it uses an ordinary -MySQL daemon to store data." -The descriptions imply that this is a development project. -@*@* - -There are four program files in the directory: -@itemize @bullet -@item -database.c -- "emulate filesystem behaviour on top of SQL database" -@item -libmysqlfs.c -- Search/replace, show-functions, and parse routines -@item -mysqlcorbafs.c -- Connection with the CORBA "Object Request Broker" -@item -mysqlcorbafs_test.c -- Utility to test the working of mysqlcorbafs.c - -@*@* - -@subsection heap - -The HEAP table handler. -@*@* - -All the MySQL table handlers (i.e. the handlers that MySQL itself -produces) have files with similar names and functions. Thus, this -(heap) directory contains a lot of duplication of the myisam directory -(for the MyISAM table handler). Such duplicates have been marked with -an "*" in the following list. For example, you will find that -\heap\hp_extra.c has a close equivalent in the myisam directory -(\myisam\mi_extra.c) with the same descriptive comment. -@*@* - -@item -hp_block.c -- Read/write a block (i.e. a page) -@item -hp_clear.c -- Remove all records in the database -@item -hp_close.c -- * close database -@item -hp_create.c -- * create a table -@item -hp_delete.c -- * delete a row -@item -hp_extra.c -- * for setting options and buffer sizes when optimizing -@item -hp_hash.c -- Hash functions used for saving keys -@item -hp_info.c -- * Information about database status -@item -hp_open.c -- * open database -@item -hp_panic.c -- * the hp_panic routine, probably for sudden shutdowns -@item -hp_rename.c -- * rename a table -@item -hp_rfirst.c -- * read first row through a specific key (very short) -@item -hp_rkey.c -- * read record using a key -@item -hp_rlast.c -- * read last row with same key as previously-read row -@item -hp_rnext.c -- * read next row with same key as previously-read row -@item -hp_rprev.c -- * read previous row with same key as previously-read -row -@item -hp_rrnd.c -- * read a row based on position -@item -hp_rsame.c -- * find current row using positional read or key-based -read -@item -hp_scan.c -- * read all rows sequentially -@item -hp_static.c -- * static variables (very short) -@item -hp_test1.c -- * testing basic functions -@item -hp_test2.c -- * testing database and storing results -@item -hp_update.c -- * update an existing row -@item -hp_write.c -- * insert a new row -@end itemize -@*@* - -There are fewer files in the heap directory than in the myisam -directory, because fewer are necessary. For example, there is no need -for a \myisam\mi_cache.c equivalent (to cache reads) or a -\myisam\log.c equivalent (to log statements). -@*@* - -@subsection Images - -Empty directory. -@*@* - -There are no files in this directory. -@*@* - -@subsection include - -Include (*.h) files. -@*@* - -These files may be included in C program files. Note that each -individual directory will also have its own *.h files, for including -in its own *.c programs. The *.h files in the include directory are -ones that might be included from more than one place. -@*@* - -For example, the mysys directory contains a C file named rijndael.c, -but does not include rijndael.h. The include directory contains -rijndael.h. Looking further, you'll find that rijndael.h is also -included in other places: by my_aes.c and my_aes.h. -@*@* - -The include directory contains 51 *.h (include) files. -@*@* - -@subsection innobase - -The Innobase (InnoDB) table handler. -@*@* - -A full description of these files can be found elsewhere in this -document. -@*@* - -@subsection isam - -The ISAM table handler. -@*@* - -The C files in this directory are: -@itemize @bullet -@item -_cache.c -- for reading records from a cache -@item -changed.c -- a single routine for setting a "changed" flag (very -short) -@item -close.c -- close database -@item -create.c -- create a table -@item -_dbug.c -- support routines for use with "dbug" (see the \dbug -description) -@item -delete.c -- delete a row -@item -_dynrec.c -- functions to handle space-packed records and blobs -@item -extra.c -- setting options and buffer sizes when optimizing table -handling -@item -info.c -- Information about database status -@item -_key.c -- for handling keys -@item -_locking.c -- lock database -@item -log.c -- save commands in log file which myisamlog program can read -@item -_packrec.c -- compress records -@item -_page.c -- read and write pages containing keys -@item -panic.c -- the mi_panic routine, probably for sudden shutdowns -@item -range.c -- approximate count of how many records lie between two -keys -@item -rfirst.c -- read first row through a specific key (very short) -@item -rkey.c -- read a record using a key -@item -rlast.c -- read last row with same key as previously-read row -@item -rnext.c -- read next row with same key as previously-read row -@item -rprev.c -- read previous row with same key as previously-read row -@item -rrnd.c -- read a row based on position -@item -rsame.c -- find current row using positional read or key-based read -@item -rsamepos.c -- positional read -@item -_search.c -- key-handling functions -@item -static.c -- static variables (very short) -@item -_statrec.c -- functions to handle fixed-length records -@item -test1.c -- testing basic functions -@item -test2.c -- testing database and storing results -@item -test3.c -- testing locking -@item -update.c -- update an existing row -@item -write.c -- insert a new row -@item -pack_isam.c -- pack isam file (NOTE TO SELF ?? equivalent to -\myisam\myisampack.c) -@end itemize -@*@* - -Except for one minor C file (pack_isam.c) every program in the ISAM -directory has a counterpart in the MyISAM directory. For example -\isam\update.c corresponds to \myisam\mi_update.c. However, the -reverse is not true -- there are many files in the MyISAM directory -which have no counterpart in the ISAM directory. -@*@* - -The reason is simple -- it's because the ISAM files are becoming -obsolete. When MySQL programmers add new features, they add them for -MyISAM only. The student can therefore ignore all files in this -directory and study the MyISAM programs instead. -@*@* - -@subsection libmysql - -The MySQL Library, Part 1. -@*@* - -The files here are for producing MySQL as a library (e.g. a Windows -DLL). The idea is that, instead of producing separate mysql (client) -and mysqld (server) programs, one produces a library. Instead of -sending messages, the client part merely calls the server part. -@*@* - -The libmysql files are split into three directories: libmysql (this -one), libmysql_r (the next one), and libmysqld (the next one after -that). It may be that the original intention was that the libmysql -directory would hold the "client part" files, and the libmysqld -directory would hold the "server part" files. -@*@* - -The program files on this directory are: -@itemize @bullet -@item -conf_to_src.c -- has to do with charsets -@item -dll.c -- initialization of the dll library -@item -errmsg.c -- English error messages, compare \mysys\errors.c -@item -get_password.c -- get password -@item -libmysql.c -- the main "packet-sending emulation" program -@item -manager.c -- initialize/connect/fetch with MySQL manager -@end itemize -@*@* - -@subsection libmysql_r - -The MySQL Library, Part 2. -@*@* - -This is a continuation of the libmysql directory. There is only one -file here: -@itemize @bullet -@item -makefile.am -@end itemize -@*@* - -@subsection libmysqld - -The MySQL library, Part 3. -@*@* - -This is a continuation of the libmysql directory. The program files on -this directory are: -@itemize @bullet -@item -libmysqld.c -- The called side, compare the mysqld.exe source -@item -lib_vio.c -- Emulate the vio directory's communication buffer -@end itemize -@*@* - -@subsection man - -Manual pages. -@*@* - -These are not the actual "man" (manual) pages, they are switches for -the production. -@*@* - -@subsection merge - -The MERGE table handler. -@*@* - -For a description of the MERGE table handler, see the MySQL Reference -Manual, section 7.2. -@*@* - -You'll notice that there seem to be several directories with -similar-sounding names of C files in them. That's because the MySQL -table handlers are all quite similar. -@*@* - -The related directories are: -@itemize @bullet -@item -\isam -- for ISAM -@item -\myisam -- for MyISAM -@item -\merge -- for ISAM MERGE (mostly call functions in \isam programs) -@item -\myisammrg -- for MyISAM MERGE (mostly call functions in \myisam -programs) -@end itemize -@*@* - -To avoid duplication, only the \myisam program versions are discussed. -@*@* - -The C programs in this (merge) directory are: -@itemize @bullet -@item -mrg_close.c -- compare \isam's close.c -@item -mrg_create.c -- "" create.c -@item -mrg_delete.c -- "" delete.c -@item -mrg_extra.c -- "" extra.c -@item -mrg_info.c -- "" info.c -@item -mrg_locking.c -- "" locking.c -@item -mrg_open.c -- "" open.c -@item -mrg_panic.c -- "" panic.c -@item -mrg_rrnd.c -- "" rrnd.c -@item -mrg_rsame.c -- "" rsame.c -@item -mrg_static.c -- "" static.c -@item -mrg_update.c -- "" update.c -@end itemize -@*@* - -@subsection myisam - -The MyISAM table handler. -@*@* - -The C files in this subdirectory come in six main groups: -@itemize @bullet -@item -ft*.c files -- ft stands for "Full Text", code contributed by Sergei -Golubchik -@item -mi*.c files -- mi stands for "My Isam", these are the main programs -for Myisam -@item -myisam*.c files -- for example, "myisamchk" utility routine -functions source -@item -rt*.c files -- rt stands for "rtree", some code was written by -Alexander Barkov -@item -sp*.c files -- sp stands for "spatial", some code was written by -Ramil Kalimullin -@item -sort.c -- this is a single file that sorts keys for index-create -purposes -@end itemize -@*@* - -The "full text" and "rtree" and "spatial" program sets are for special -purposes, so this document focuses only on the mi*.c "myisam" C -programs. They are: -@itemize @bullet -@item -mi_cache.c -- for reading records from a cache -@item -mi_changed.c -- a single routine for setting a "changed" flag (very -short) -@item -mi_check.c -- doesn't just do checks, ?? for myisamchk program? -@item -mi_checksum.c -- calculates a checksum for a row -@item -mi_close.c -- close database -@item -mi_create.c -- create a table -@item -mi_dbug.c -- support routines for use with "dbug" (see \dbug -description) -@item -mi_delete.c -- delete a row -@item -mi_delete_all.c -- delete all rows -@item -mi_delete_table.c -- delete a table (very short) -@item -mi_dynrec.c -- functions to handle space-packed records and blobs -@item -mi_extra.c -- setting options and buffer sizes when optimizing -@item -mi_info.c -- "Ger tillbaka en struct med information om isam-filen" -@item -mi_key.c -- for handling keys -@item -mi_locking.c -- lock database -@item -mi_log.c -- save commands in log file which myisamlog program can -read -@item -mi_open.c -- open database -@item -mi_packrec.c -- compress records -@item -mi_page.c -- read and write pages containing keys -@item -mi_panic.c -- the mi_panic routine, probably for sudden shutdowns -@item -mi_range.c -- approximate count of how many records lie between two -keys -@item -mi_rename.c -- rename a table -@item -mi_rfirst.c -- read first row through a specific key (very short) -@item -mi_rkey.c -- read a record using a key -@item -mi_rlast.c -- read last row with same key as previously-read row -@item -mi_rnext.c -- read next row with same key as previously-read row -@item -mi_rnext_same.c -- same as mi_rnext.c, but abort if the key changes -@item -mi_rprev.c -- read previous row with same key as previously-read row -@item -mi_rrnd.c -- read a row based on position -@item -mi_rsame.c -- find current row using positional read or key-based -read -@item -mi_rsamepos.c -- positional read -@item -mi_scan.c -- read all rows sequentially -@item -mi_search.c -- key-handling functions -@item -mi_static.c -- static variables (very short) -@item -mi_statrec.c -- functions to handle fixed-length records -@item -mi_test1.c -- testing basic functions -@item -mi_test2.c -- testing database and storing results -@item -mi_test3.c -- testing locking -@item -mi_unique.c -- functions to check if a row is unique -@item -mi_update.c -- update an existing row -@item -mi_write.c -- insert a new row -@end itemize -@*@* - -@subsection myisammrg - -MyISAM Merge table handler. -@*@* - -As with other table handlers, you'll find that the *.c files in the -myissammrg directory have counterparts in the myisam directory. In -fact, this general description of a myisammrg program is almost always -true: The myisammrg -function checks an argument, the myisammrg function formulates an -expression for passing to a myisam function, the myisammrg calls a -myisam function, the myisammrg function returns. -@*@* - -These are the 21 files in the myisammrg directory, with notes about -the myisam functions or programs they're connected with: -@itemize @bullet -@item -myrg_close.c -- mi_close.c -@item -myrg_create.c -- mi_create.c -@item -myrg_delete.c -- mi_delete.c / delete last-read record -@item -myrg_extra.c -- mi_extra.c / "extra functions we want to do ..." -@item -myrg_info.c -- mi_info.c / display information about a mymerge file -@item -myrg_locking.c -- mi_locking.c / lock databases -@item -myrg_open.c -- mi_open.c / open a MyISAM MERGE table -@item -myrg_panic.c -- mi_panic.c / close in a hurry -@item -myrg_queue.c -- read record based on a key -@item -myrg_range.c -- mi_range.c / find records in a range -@item -myrg_rfirst.c -- mi_rfirst.c / read first record according to -specific key -@item -myrg_rkey.c -- mi_rkey.c / read record based on a key -@item -myrg_rlast.c -- mi_rlast.c / read last row with same key as previous -read -@item -myrg_rnext.c -- mi_rnext.c / read next row with same key as previous -read -@item -myrg_rnext_same.c -- mi_rnext_same.c / read next row with same key -@item -myrg_rprev.c -- mi_rprev.c / read previous row with same key -@item -myrg_rrnd.c -- mi_rrnd.c / read record with random access -@item -myrg_rsame.c -- mi_rsame.c / call mi_rsame function, see -\myisam\mi_rsame.c -@item -myrg_static.c -- mi_static.c / static variable declaration -@item -myrg_update.c -- mi_update.c / call mi_update function, see -\myisam\mi_update.c -@item -myrg_write.c -- mi_write.c / call mi_write function, see -\myisam\mi_write.c -@end itemize -@*@* - -@subsection mysql-test - -A test suite for mysqld. -@*@* - -The directory has a README file which explains how to run the tests, -how to make new tests (in files with the filename extension "*.test"), -and how to report errors. -@*@* - -There are four subdirectories: -@itemize @bullet -@item -\misc -- contains one minor Perl program -@item -\r -- contains *.result, i.e. "what happened" files and -*.required, i.e. "what should happen" file -@item -\std_data -- contains standard data for input to tests -@item -\t -- contains tests -@end itemize -@*@* - -There are 186 *.test files in the \t subdirectory. Primarily these are -SQL scripts which try out a feature, output a result, and compare the -result with what's required. Some samples of what the test files check -are: latin1_de comparisons, date additions, the HAVING clause, outer -joins, openSSL, load data, logging, truncate, and UNION. -@*@* - -There are other tests in these directories: -@itemize @bullet -@item -sql-bench -@item -repl-tests -@item -tests -@end itemize - -@subsection mysys - -MySQL system library (Low level routines for file access etc.). -@*@* - -There are 115 *.c programs in this directory: -@itemize @bullet -@item -array.c -- Dynamic array handling -@item -charset.c -- Using dynamic character sets, set default character -set, ... -@item -charset2html.c -- Checking what character set a browser is using -@item -checksum.c -- Calculate checksum for a memory block, used for -pack_isam -@item -default.c -- Find defaults from *.cnf or *.ini files -@item -errors.c -- English text of global errors -@item -hash.c -- Hash search/compare/free functions "for saving keys" -@item -list.c -- Double-linked lists -@item -make-conf.c -- "Make a charset .conf file out of a ctype-charset.c -file" -@item -md5.c -- MD5 ("Message Digest 5") algorithm from RSA Data Security -@item -mf_brkhant.c -- Prevent user from doing a Break during critical -execution -@item -mf_cache.c -- "Open a temporary file and cache it with io_cache" -@item -mf_dirname.c -- Parse/convert directory names -@item -mf_fn_ext.c -- Get filename extension -@item -mf_format.c -- Format a filename -@item -mf_getdate.c -- Get date, return in yyyy-mm-dd hh:mm:ss format -@item -mf_iocache.c -- Cached read/write of files in fixed-size units -@item -mf_iocache2.c -- Continuation of mf_iocache.c -@item -mf_keycache.c -- Key block caching for certain file types -@item -mf_loadpath.c -- Return full path name (no ..\ stuff) -@item -mf_pack.c -- Packing/unpacking directory names for create purposes -@item -mf_path.c -- Determine where a program can find its files -@item -mf_qsort.c -- Quicksort -@item -mf_qsort2.c -- Quicksort, part 2 -@item -mf_radix.c -- Radix sort -@item -mf_same.c -- Determine whether filenames are the same -@item -mf_sort.c -- Sort with choice of Quicksort or Radix sort -@item -mf_soundex.c -- Soundex algorithm derived from EDN Nov. 14, 1985 -(pg. 36) -@item -mf_strip.c -- Strip trail spaces from a string -@item -mf_tempdir.c -- Initialize/find/free temporary directory -@item -mf_tempfile.c -- Create a temporary file -@item -mf_unixpath.c -- Convert filename to UNIX-style filename -@item -mf_util.c -- Routines, #ifdef'd, which may be missing on some -machines -@item -mf_wcomp.c -- Comparisons with wildcards -@item -mf_wfile.c -- Finding files with wildcards -@item -mulalloc.c -- Malloc many pointers at the same time -@item -my_aes.c -- AES encryption -@item -my_alarm.c -- Set a variable value when an alarm is received -@item -my_alloc.c -- malloc of results which will be freed simultaneously -@item -my_append.c -- one file to another -@item -my_bit.c -- smallest X where 2^X >= value, maybe useful for -divisions -@item -my_bitmap.c -- Handle uchar arrays as large bitmaps -@item -my_chsize.c -- Truncate file if shorter, else fill with a filler -character -@item -my_clock.c -- Time-of-day ("clock()") function, with OS-dependent -#ifdef's -@item -my_compress.c -- Compress packet (see also description of \zlib -directory) -@item -my_copy.c -- Copy files -@item -my_create.c -- Create file -@item -my_delete.c -- Delete file -@item -my_div.c -- Get file's name -@item -my_dup.c -- Open a duplicated file -@item -my_error.c -- Return formatted error to user -@item -my_fopen.c -- File open -@item -my_fstream.c -- Streaming file read/write -@item -my_getwd.c -- Get working directory -@item -my_gethostbyname.c -- Thread-safe version of standard net -gethostbyname() func -@item -my_getopt.c -- Find out what options are in effect -@item -my_handler.c -- Compare two keys in various possible formats -@item -my_init.c -- Initialize variables and functions in the mysys library -@item -my_lib.c -- Compare/convert directory names and file names -@item -my_lock.c -- Lock part of a file -@item -my_lockmem.c -- "Allocate a block of locked memory" -@item -my_lread.c -- Read a specified number of bytes from a file into -memory -@item -my_lwrite.c -- Write a specified number of bytes from memory into a -file -@item -my_malloc.c -- Malloc (memory allocate) and dup functions -@item -my_messnc.c -- Put out a message on stderr with "no curses" -@item -my_mkdir.c -- Make directory -@item -my_net.c -- Thread-safe version of net inet_ntoa function -@item -my_netware.c -- Functions used only with the Novell Netware version -of MySQL -@item -my_once.c -- Allocation / duplication for "things we don't need to -free" -@item -my_open.c -- Open a file -@item -my_os2cond.c -- OS2-specific: "A simple implementation of posix -conditions" -@item -my_os2dirsrch.c -- OS2-specific: Emulate a Win32 directory search -@item -my_os2dlfcn.c -- OS2-specific: Emulate UNIX dynamic loading -@item -my_os2file64.c -- OS2-specific: For File64bit setting -@item -my_os2mutex.c -- OS2-specific: For mutex handling -@item -my_os2thread.c -- OS2-specific: For thread handling -@item -my_os2tls.c -- OS2-specific: For thread-local storage -@item -my_port.c -- AIX-specific: my_ulonglong2double() -@item -my_pread.c -- Read a specified number of bytes from a file -@item -my_pthread.c -- A wrapper for thread-handling functions in different -OSs -@item -my_quick.c -- Read/write (labelled a "quicker" interface, perhaps -obsolete) -@item -my_read.c -- Read a specified number of bytes from a file, possibly -retry -@item -my_realloc.c -- Reallocate memory allocated with my_alloc.c -(probably) -@item -my_redel.c -- Rename and delete file -@item -my_rename.c -- Rename without delete -@item -my_seek.c -- Seek, i.e. point to a spot within a file -@item -my_semaphore.c -- Semaphore routines, for use on OS that doesn't -support them -@item -my_sleep.c -- Wait n microseconds -@item -my_static.c -- Static-variable definitions -@item -my_symlink.c -- Read a symbolic link (symlinks are a UNIX thing, I -guess) -@item -my_symlink2.c -- Part 2 of my_symlink.c -@item -my_tempnam.c -- Obsolete temporary-filename routine used by ISAM -table handler -@item -my_thr_init.c -- initialize/allocate "all mysys & debug thread -variables" -@item -my_wincond.c -- Windows-specific: emulate Posix conditions -@item -my_winsem.c -- Windows-specific: emulate Posix threads -@item -my_winthread.c -- Windows-specific: emulate Posix threads -@item -my_write.c -- Write a specified number of bytes to a file -@item -ptr_cmp.c -- Point to an optimal byte-comparison function -@item -queues.c -- Handle priority queues as in Robert Sedgewick's book -@item -raid2.c -- RAID support (the true implementation is in raid.cc) -@item -rijndael.c -- "Optimised ANSI C code for the Rijndael cipher (now -AES") -@item -safemalloc.c -- A version of the standard malloc() with safety -checking -@item -sha1.c -- Implementation of Secure Hashing Algorithm 1 -@item -string.c -- Initialize/append/free dynamically-sized strings -@item -testhash.c -- Standalone program: test the hash library routines -@item -test_charset.c -- Standalone program: display character set -information -@item -test_dir.c -- Standalone program: placeholder for "test all -functions" idea -@item -test_fn.c -- Standalone program: apparently tests a function -@item -test_xml.c -- Standalone program: test XML routines -@item -thr_alarm.c -- Thread alarms and signal handling -@item -thr_lock.c -- "Read and write locks for Posix threads" -@item -thr_mutex.c -- A wrapper for mutex functions -@item -thr_rwlock.c -- Synchronizes the readers' thread locks with the -writer's lock -@item -tree.c -- Initialize/search/free binary trees -@item -typelib.c -- Determine what type a field has -@end itemize -@*@* - -You can find documentation for the main functions in these files -elsewhere in this document. -For example, the main functions in my_getwd.c are described thus: -@*@* - -@example -"int my_getwd _A((string buf, uint size, myf MyFlags)); @* - int my_setwd _A((const char *dir, myf MyFlags)); @* - Get and set working directory." @* -@end example - -@subsection netware - -Files related to the Novell NetWare version of MySQL. -@*@* - -There are 39 files on this directory. Most have filename extensions of -*.def, *.sql, or *.c. -@*@* - -The twenty-five *.def files are all from Novell Inc. They contain import or -export symbols. (".def" is a common filename extension for -"definition".) -@*@* - -The two *.sql files are short scripts of SQL statements used in -testing. -@*@* - -These are the five *.c files, all from Novell Inc.: -@itemize @bullet -@item -libmysqlmain.c -- Only one function: init_available_charsets() -@item -my_manage.c -- Standalone management utility -@item -mysql_install_db.c -- Compare \scripts\mysql_install_db.sh -@item -mysql_test_run.c -- Short test program -@item -mysqld_safe.c -- Compare \scripts\mysqld_safe.sh -@end itemize - -Perhaps the most important file is: -@itemize @bullet -@item -netware.patch -- NetWare-specific build instructions and switches -(compare \mysql-4.1\ltmain.sh) -@end itemize -@*@* - -For instructions about basic installation, see "Deployment Guide For -NetWare AMP" at: -@url{http://developer.novell.com/ndk/whitepapers/namp.htm} -@* - -@subsection NEW-RPMS - -New "RPM Package Manager" files. -@*@* - -This directory is not part of the Windows distribution. Perhaps in -MYSQL's Linux distribution it has files for use with Red Hat -installations -- a point that needs checking someday. -@*@* - -@subsection os2 - -Routines for working with the OS2 operating system. -@*@* - -The files in this directory are the product of the efforts of three -people from outside MySQL: Yuri Dario, Timo Maier, and John M -Alfredsson. There are no .C program files in this directory. -@*@* - -The contents of \os2 are: -@itemize @bullet -@item -A Readme.Txt file -@item -An \include subdirectory containing .h files which are for OS/2 only -@item -Files used in the build process (configuration, switches, and one -.obj) -@end itemize -@*@* - -The README file refers to MySQL version 3.23, which suggests that -there have been no updates for MySQL 4.0 for this section. -@*@* - -@subsection pstack - -Process stack display. -@*@* - -This is a set of publicly-available debugging aids which all do pretty -well the same thing: display the contents of the stack, along with -symbolic information, for a running process. There are versions for -various object file formats (such as ELF and IEEE-695). Most of the -programs are copyrighted by the Free Software Foundation and are -marked as "part of GNU Binutils". -@*@* - -In other words, the pstack files are not really part of the MySQL -library. They are merely useful when you re-program some MYSQL code -and it crashes. -@*@* - -@subsection regex - -Regular Expression library for support of REGEXP function. -@*@* - -This is the copyrighted product of Henry Spencer from the University -of Toronto. It's a fairly-well-known implementation of the -requirements of POSIX 1003.2 Section 2.8. The library is bundled with -Apache and is the default implementation for regular-expression -handling in BSD Unix. MySQL's Monty Widenius has made minor changes in -three programs (debug.c, engine.c, regexec.c) but this is not a MySQL -package. MySQL calls it only in order to support two MySQL functions: -REGEXP and RLIKE. -@*@* - -Some of Mr Spencer's documentation for the regex library can be found -in the README and WHATSNEW files. -@*@* - -One MySQL program which uses regex is \cmd-line-utils\libedit\search.c -@*@* - -This program calls the 'regcomp' function, which is the entry point in -\regex\regexp.c. -@*@* - -@subsection repl-tests - -Test cases for replication. -@*@* - -There are six short and trivial-looking tests in these subdirectories: -@itemize @bullet -@item -\test-auto-inc -- Do auto-Increment columns work? -@item -\test-bad-query -- Does insert in PK column work? -@item -\test-dump -- Do LOAD statements work? -@item -\test-repl -- Does replication work? -@item -\test-repl-alter -- Does ALTER TABLE work? -@item -\test-repl-ts -- Does TIMESTAMP column work? -@end itemize -@*@* - -@subsection SCCS - -Source Code Control System. -@*@* - -You will see this directory if and only if you used BitKeeper for -downloading the source. The files here are for BitKeeper -administration and are not of interest to application programmers. -@*@* - -@subsection scripts - -SQL batches, e.g. for converting msql to MySQL. -@*@* - -The *.sh filename extension apparently stands for "shell script". -Linux programmers use it where Windows programmers would use a *.bat -(batch filename extension). -@*@* - -The *.sh files on this directory are: -@itemize @bullet -@item -fill_help_tables.sh -- Create help-information tables and insert -@item -make_binary_distribution.sh -- Get configure information, make, -produce tar -@item -msql2mysql.sh -- Convert mSQL to MySQL -@item -mysqlbug.sh -- Create a bug report and mail it -@item -mysqld_multi.sh -- Start/stop any number of mysqld instances -@item -mysqld_safe-watch.sh -- Start/restart in safe mode -@item -mysqld_safe.sh -- Start/restart in safe mode -@item -mysqldumpslow.sh -- Parse and summarize the slow query log -@item -mysqlhotcopy.sh -- Hot backup -@item -mysql_config.sh -- Get configure information that client might need -@item -mysql_convert_table_format.sh -- Conversion, e.g. from ISAM to -MyISAM -@item -mysql_explain_log.sh -- Put a log (made with --log) into a MySQL -table -@item -mysql_find_rows.sh -- Search for queries containing <regexp> -@item -mysql_fix_extensions.sh -- Renames some file extensions, not -recommended -@item -mysql_fix_privilege_tables.sh -- Fix mysql.user etc. if upgrading to -MySQL 3.23.14+ -@item -mysql_install_db.sh -- Create privilege tables and func table -@item -mysql_secure_installation.sh -- Disallow remote root login, -eliminate test, etc. -@item -mysql_setpermission.sh -- Aid to add users or databases, sets -privileges -@item -mysql_tableinfo.sh -- Puts info re MySQL tables into a MySQL table -@item -mysql_zap.sh -- Kill processes which match pattern -@end itemize -@*@* - -@subsection sql - -Programs for handling SQL commands. The "core" of MySQL. -@*@* - -These are the .c and .cc files in the sql directory: -@itemize @bullet -@item -cache_manager.cc -- manages a number of blocks -@item -convert.cc -- convert tables between different character sets -@item -derror.cc -- read language-dependent message file -@item -des_key_file.cc -- load DES keys from plaintext file -@item -field.cc -- "implement classes defined in field.h" (long) -@item -field_conv.cc -- functions to copy data to or from fields -@item -filesort.cc -- sort file -@item -frm_crypt.cc -- contains only one short function: get_crypt_for_frm -@item -gen_lex_hash.cc -- Knuth's algorithm from Vol 3 Sorting and -Searching, Chapter 6.3 -@item -gstream.cc -- GTextReadStream -@item -handler.cc -- handler-calling functions -@item -hash_filo.cc -- static-sized hash tables -@item -ha_berkeley.cc -- Handler: BDB -@item -ha_heap.cc -- Handler: Heap -@item -ha_innodb.cc -- Handler: InnoDB -@item -ha_isam.cc -- Handler: ISAM -@item -ha_isammrg.cc -- Handler: (ISAM MERGE) -@item -ha_myisam.cc -- Handler: MyISAM -@item -ha_myisammrg.cc -- Handler: (MyISAM MERGE) -@item -hostname.cc -- Given IP, return hostname -@item -init.cc -- Init and dummy functions for interface with unireg -@item -item.cc -- Item functions -@item -item_buff.cc -- Buffers to save and compare item values -@item -item_cmpfunc.cc -- Definition of all compare functions -@item -item_create.cc -- Create an item. Used by lex.h. -@item -item_func.cc -- Numerical functions -@item -item_row.cc -- Row items for comparing rows and for IN on rows -@item -item_sum.cc -- Set functions (sum, avg, etc.) -@item -item_strfunc.cc -- String functions -@item -item_subselect.cc -- Item subselect -@item -item_timefunc.cc -- Date/time functions, e.g. week of year -@item -item_uniq.cc -- Empty file, here for compatibility reasons -@item -key.cc -- Functions to handle keys and fields in forms -@item -lock.cc -- Locks -@item -log.cc -- Logs -@item -log_event.cc -- Log event -@item -matherr.c -- Handling overflow, underflow, etc. -@item -mf_iocache.cc -- Caching of (sequential) reads -@item -mini_client.cc -- Client included in server for server-server -messaging -@item -mysqld.cc -- Source of mysqld.exe -@item -my_lock.c -- Lock part of a file -@item -net_serv.cc -- Read/write of packets on a network socket -@item -nt_servc.cc -- Initialize/register/remove an NT service -@item -opt_ft.cc -- Create a FT or QUICK RANGE based on a key (very short) -* opt_range.cc -- Range of keys -@item -opt_sum.cc -- Optimize functions in presence of (implied) GROUP BY -@item -password.c -- Password checking -@item -procedure.cc -- Procedure -@item -protocol.cc -- Low level functions for storing data to be sent to -client -@item -records.cc -- Functions to read, write, and lock records -@item -repl_failsafe.cc -- Replication fail-save -@item -set_var.cc -- MySQL variables -@item -slave.cc -- Procedures for a slave in a master/slave (replication?) -relation -@item -spatial.cc -- Geometry stuff (lines, points, etc.) -@item -sql_acl.cc -- Functions related to ACL security -@item -sql_analyse.cc -- Analyse an input string (?) -@item -sql_base.cc -- Basic functions needed by many modules -@item -sql_cache.cc -- SQL cache, with long comments about how caching -works -@item -sql_class.cc -- SQL class -@item -sql_crypt.cc -- Encode / decode, very short -@item -sql_db.cc -- Create / drop database -@item -sql_delete.cc -- The DELETE statement -@item -sql_derived.cc -- Derived tables, with long comments -@item -sql_do.cc -- The DO statement -@item -sql_error.cc -- Errors and warnings -@item -sql_handler.cc -- Direct access to ISAM -@item -sql_help.cc -- The HELP statement (if there is one?) -@item -sql_insert.cc -- The INSERT statement -@item -sql_lex.cc -- Related to lex or yacc -@item -sql_list.cc -- Only list_node_end_of_list, short -@item -sql_load.cc -- The LOAD DATA statement? -@item -sql_map.cc -- Memory-mapped files? -@item -sql_manager.cc -- Maintenance tasks, e.g. flushing the buffers -periodically -@item -sql_olap.cc -- ROLLUP -@item -sql_parse.cc -- Parse an SQL statement -@item -sql_prepare.cc -- Prepare an SQL statement -@item -sql_repl.cc -- Replication -@item -sql_rename.cc -- Rename table -@item -sql_select.cc -- Select and join optimisation -@item -sql_show.cc -- The SHOW statement -@item -sql_string.cc -- String functions: alloc, realloc, copy, convert, -etc. -@item -sql_table.cc -- The DROP TABLE and ALTER TABLE statements -@item -sql_test.cc -- Some debugging information -@item -sql_udf.cc -- User-defined functions -@item -sql_union.cc -- The UNION operator -@item -sql_update.cc -- The UPDATE statement -@item -stacktrace.c -- Display stack trace (Linux/Intel only?) -@item -table.cc -- Table metadata retrieval, mostly -@item -thr_malloc.cc -- Mallocs used in threads -@item -time.cc -- Date and time functions -@item -udf_example.cc -- Example file of user-defined functions -@item -uniques.cc -- Function to handle quick removal of duplicates -@item -unireg.cc -- Create a unireg form file from a FIELD and field-info struct -@end itemize -@*@* - -@subsection sql-bench - -The MySQL Benchmarks. -@*@* - -This directory has the programs and input files which MySQL uses for -its comparisons of MySQL, PostgreSQL, mSQL, Solid, etc. Since MySQL -publishes the comparative results, it's only right that it should make -available all the material necessary to reproduce all the tests. -@*@* - -There are five subdirectories and sub-subdirectories: -@itemize @bullet -@item -\Comments -- Comments about results from tests of Access, Adabas, -etc. -@item -\Data\ATIS -- .txt files containing input data for the "ATIS" tests -@item -\Data\Wisconsin -- .txt files containing input data for the -"Wisconsin" tests -@item -\Results -- old test results -@item -\Results-win32 -- old test results from Windows 32-bit tests -@end itemize -@*@* - -There are twenty-four *.sh (shell script) files, which involve Perl -programs. -@*@* - -There are three *.bat (batch) files. -@*@* - -There is one README file and one TODO file. -@*@* - -@subsection SSL - -Secure Sockets Layer. -@*@* - -This isn't a code directory. It contains a short note from Tonu Samuel -(the NOTES file) and seven *.pem files. PEM stands for "Privacy -Enhanced Mail" and is an Internet standard for adding security to -electronic mail. Finally, there are two short scripts for running -clients and servers over SSL connections. -@*@* - -@subsection strings - -The string library. -@*@* - -Many of the files in this subdirectory are equivalent to well-known -functions that appear in most C string libraries. For those, there is -documentation available in most compiler handbooks. -@*@* - -On the other hand, some of the files are MySQL additions or -improvements. Often the MySQL changes are attempts to optimize the -standard libraries. It doesn't seem that anyone tried to optimize for -recent Pentium class processors, though. -@*@* - -The .C files are: -@itemize @bullet -@item -atof.c -- ascii-to-float, MySQL version -@item -bchange.c -- short replacement routine written by Monty Widenius in -1987 -@item -bcmp.c -- binary compare, rarely used -@item -bcopy-duff.c -- block copy: attempt to copy memory blocks faster -than cmemcpy -@item -bfill.c -- byte fill, to fill a buffer with (length) copies of a -byte -@item -bmove.c -- block move -@item -bmove512.c -- "should be the fastest way to move a multiple of 512 -bytes" -@item -bmove_upp.c -- bmove.c variant, starting with last byte -@item -bzero.c -- something like bfill with an argument of 0 -@item -conf_to_src.c -- reading a configuration file (NOTE TO SELF ? what's -this doing here?) -@item -ctype*.c -- string handling programs for each char type MySQL -handles -@item -do_ctype.c -- display case-conversion and sort-conversion tables -@item -int2str.c -- integer-to-string -@item -is_prefix.c -- checks whether string1 starts with string2 -@item -llstr.c -- convert long long to temporary-buffer string, return -pointer -@item -longlong2str.c -- ditto, but to argument-buffer -@item -memcmp.c -- memory compare -@item -memset.c -- memory set -@item -my_vsnprintf.c -- variant of printf -@item -r_strinstr.c -- see if one string is within another -@item -str2int.c -- convert string to integer -@item -strappend.c -- append one string to another -@item -strcat.c -- concatenate strings -@item -strcend.c -- point to where a character C occurs within str, or NULL -@item -strchr.c -- point to first place in string where character occurs -@item -strcmp.c -- compare two strings -@item -strcont.c -- point to where any one of a set of characters appears -@item -strend.c -- point to the '\0' byte which terminates str -@item -strfill.c -- fill a string with n copies of a byte -@item -strinstr.c -- find string within string -@item -strlen.c -- return length of string in bytes -@item -strmake.c -- move n characters, or move till end -@item -strmov.c -- move source to dest and return pointer to end -@item -strnlen.c -- return length of string, or return n -@item -strnmov.c -- move source to dest for source size, or for n bytes -@item -strrchr.c -- find a character within string, searching from end -@item -strstr.c -- find an instance of pattern within source -@item -strto.c -- string to long, to long long, to unsigned long, etc. -@item -strtol.c -- string to long -@item -strtoll.c -- string to long long -@item -strtoul.c -- string to unsigned long -@item -strtoull.c -- string to unsigned long long -@item -strxmov.c -- move a series of concatenated source strings to dest -@item -strxnmov.c -- like strxmov.c but with a maximum length n -@item -str_test.c -- test of all the string functions encoded in assembler -@item -udiv.c -- unsigned long divide -@item -xml.c -- read and parse XML strings -@end itemize -@*@* - -There are also four .ASM files -- macros.asm, ptr_cmp.asm, -strings.asm, and strxmov.asm -- which can replace some of the -C-program functions. But again, they look like optimizations for old -members of the Intel processor family. -@*@* - -@subsection support-files - -Support files. -@*@* - -The files here are for building ("making") MySQL given a package -manager, compiler, linker, and other build tools. The support files -provide instructions and switches for the build processes. -@*@* - -@subsection tests - -Tests in Perl. -@*@* - -These are tests that were run once to check for bugs in various -scenarios: forks, locks, big records, exporting, truncating, etc. -@*@* - -@subsection tools - -Tools -- well, actually, one tool. -@*@* - -The only file is: -@itemize @bullet -@item -mysqlmanager.c -- A "server management daemon" by Sasha Pachev -@end itemize -@*@* - -@subsection VC++Files - -Visual C++ Files. -@*@* - -Includes this entire directory, repeated for VC++ (Windows) use. -@*@* - -VC++Files has subdirectories which are copies of the main directories. -For example there is a subdirectory \VC++Files\heap, which has the -same files as \heap. So for a description of the files in -\VC++Files\heap, see the description of the files in \heap. The same -applies for almost all of VC++Files's subdirectories (bdb, client, -isam, libmysql, etc.). The difference is that the \VC++Files variants -are specifically for compilation with Microsoft Visual C++ in 32-bit -Windows environments. -@*@* - -In addition to the "subdirectories which are duplicates of -directories", VC++Files contains these subdirectories, which are not -duplicates: -@itemize @bullet -@item -comp_err -- (nearly empty) -@item -contrib -- (nearly empty) -@item -InstallShield script files -@item -isamchk -- (nearly empty) -@item -libmysqltest -- one small non-MySQL test program: mytest.c -@item -myisamchk -- (nearly empty) -@item -myisamlog -- (nearly empty) -@item -myisammrg -- (nearly empty) -@item -mysqlbinlog -- (nearly empty) -@item -mysqlmanager -- MFC foundation class files created by AppWizard -@item -mysqlserver -- (nearly empty) -@item -mysqlshutdown -- one short program, mysqlshutdown.c -@item -mysqlwatch.c -- Windows service initialization and monitoring -@item -my_print_defaults -- (nearly empty) -@item -pack_isam -- (nearly empty) -@item -perror -- (nearly empty) -@item -prepare -- (nearly empty) -@item -replace -- (nearly empty) -@item -SCCS -- source code control system -@item -test1 -- tests connecting via X threads -@item -thr_insert_test -- (nearly empty) -@item -thr_test -- one short program used to test for memory-allocation bug -@item -winmysqladmin -- the winmysqladmin.exe source. machine-generated? -@end itemize -@*@* - -@subsection vio - -Virtual I/O Library. -@*@* - -The VIO routines are wrappers for the various network I/O calls that -happen with different protocols. The idea is that in the main modules -one won't have to write separate bits of code for each protocol. Thus -vio's purpose is somewhat like the purpose of Microsoft's winsock -library. -@*@* - -The underlying protocols at this moment are: TCP/IP, Named Pipes (for -WindowsNT), Shared Memory, and Secure Sockets (SSL). -@*@* - -The C programs are: -@itemize @bullet -@item -test-ssl.c -- Short standalone test program: SSL -@item -test-sslclient.c -- Short standalone test program: clients -@item -test-sslserver.c -- Short standalone test program: server -@item -vio.c -- Declarations + open/close functions -@item -viosocket.c -- Send/retrieve functions -@item -viossl.c -- SSL variations for the above -@item -viosslfactories.c -- Certification / Verification -@item -viotest.cc -- Short standalone test program: general -@item -viotest-ssl.c -- Short standalone test program: SSL -@item -viotest-sslconnect.cc -- Short standalone test program: SSL connect -@end itemize -@*@* - -The older functions -- raw_net_read, raw_net_write -- are now -obsolete. -@*@* - -@subsection zlib - -Data compression library. -@*@* - -Zlib -- which presumably stands for "Zip Library" -- is not a MySQL -package. It was produced by the GNU Zip (gzip.org) people. Zlib is a -variation of the famous "Lempel-Ziv" method, which is also used by -"Zip". The method for reducing the size of any arbitrary string of -bytes is as follows: -@itemize @bullet -@item -Find a substring which occurs twice in the string. -@item -Replace the second occurrence of the substring with (a) a pointer to -the first occurrence, plus (b) an indication of the length of the -first occurrence. -@end itemize - -There is a full description of the library's functions in the gzip -manual at: @* -@url{http://www.gzip.org/zlib/manual.html} @* -There is therefore no need to list the modules in this document. -@*@* - -The MySQL program that uses zlib is \mysys\my_compress.c. The use is -for packet compression. The client sends messages to the server which -are compressed by zlib. See also: \sql\net_serv.cc. - -@node Files in InnoDB Sources,,Files in MySQL Sources,Top -@chapter Annotated List Of Files in the InnoDB Source Code Distribution - -ERRATUM BY HEIKKI TUURI (START) -@*@* - -Errata about InnoDB row locks:@*@* - -@example - #define LOCK_S 4 /* shared */ - #define LOCK_X 5 /* exclusive */ -... -@strong{/* Waiting lock flag */} - #define LOCK_WAIT 256 -/* this wait bit should be so high that it can be ORed to the lock -mode and type; when this bit is set, it means that the lock has not -yet been granted, it is just waiting for its turn in the wait queue */ -... -@strong{/* Precise modes */} - #define LOCK_ORDINARY 0 -/* this flag denotes an ordinary next-key lock in contrast to LOCK_GAP -or LOCK_REC_NOT_GAP */ - #define LOCK_GAP 512 -/* this gap bit should be so high that it can be ORed to the other -flags; when this bit is set, it means that the lock holds only on the -gap before the record; for instance, an x-lock on the gap does not -give permission to modify the record on which the bit is set; locks of -this type are created when records are removed from the index chain of -records */ - #define LOCK_REC_NOT_GAP 1024 -/* this bit means that the lock is only on the index record and does -NOT block inserts to the gap before the index record; this is used in -the case when we retrieve a record with a unique key, and is also used -in locking plain SELECTs (not part of UPDATE or DELETE) when the user -has set the READ COMMITTED isolation level */ - #define LOCK_INSERT_INTENTION 2048 -/* this bit is set when we place a waiting gap type record lock -request in order to let an insert of an index record to wait until -there are no conflicting locks by other transactions on the gap; note -that this flag remains set when the waiting lock is granted, or if the -lock is inherited to a neighboring record */ -@end example -@* - -ERRATUM BY HEIKKI TUURI (END) -@*@* - -The InnoDB source files are the best place to look for information -about internals of the file structure that MySQLites can optionally -use for transaction support. But when you first look at all the -subdirectories and file names you'll wonder: Where Do I Start? It can -be daunting. -@*@* - -Well, I've been through that phase, so I'll pass on what I had to -learn on the first day that I looked at InnoDB source files. I am very -sure that this will help you grasp, in overview, the organization of -InnoDB modules. I'm also going to add comments about what is going on --- which you should mistrust! These comments are reasonable working -hypotheses; nevertheless, they have not been subjected to expert peer -review. -@*@* - -Here's how I'm going to organize the discussion. I'll take each of the -32 InnoDB subdirectories that come with the MySQL 4.0 source code in -\mysql\innobase (on my Windows directory). The format of each section -will be like this every time: -@*@* - -@strong{\subdirectory-name (LONGER EXPLANATORY NAME)}@* -@multitable @columnfractions .10 .20 .40 .50 -@item @strong{File Name} @tab @strong{What Name Stands For} @tab @strong{Size} @tab @strong{Comment Inside File} -@item file-name -@tab my-own-guess -@tab in-bytes -@tab from-the-file-itself -@end multitable -...@* -My-Comments@* -@* - -For example: @* -@example -" -@strong{\ha (HASHING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - ha0ha.c Hashing/Hashing 7,452 Hash table with external chains - - Comments about hashing will be here. -" -@end example -@* - -The "Comment Inside File" column is a direct copy from the first /* -comment */ line inside the file. All other comments are mine. After -I've discussed each directory, I'll finish with some notes about -naming conventions and a short list of URLs that you can use for -further reference. -@*@* - -Now let's begin. -@*@* - -@example - -@strong{\ha (HASHING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - ha0ha.c Hashing / Hashing 7,452 Hash table with external chains - -I'll hold my comments until the next section, \hash (HASHING). - -@strong{\hash (HASHING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - hash0hash.c Hashing / Hashing 3,257 Simple hash table utility - -The two C programs in the \ha and \hashing directories -- ha0ha.c and -hash0hash.c -- both refer to a "hash table" but hash0hash.c is -specialized, it is mostly about accessing points in the table under -mutex control. - -When a "database" is so small that InnoDB can load it all into memory -at once, it's more efficient to access it via a hash table. After all, -no disk i/o can be saved by using an index lookup, if there's no disk. - -@strong{\os (OPERATING SYSTEM)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - os0shm.c OS / Shared Memory 3,150 To shared memory primitives - os0file.c OS / File 64,412 To i/o primitives - os0thread.c OS / Thread 6,827 To thread control primitives - os0proc.c OS / Process 3,700 To process control primitives - os0sync.c OS / Synchronization 10,208 To synchronization primitives - -This is a group of utilities that other modules may call whenever they -want to use an operating-system resource. For example, in os0file.c -there is a public InnoDB function named os_file_create_simple(), which -simply calls the Windows-API function CreateFile. Naturally the -contents of this group are somewhat different for other operating systems. - -The "Shared Memory" functions in os0shm.c are only called from the -communications program com0shm.c (see \com COMMUNICATIONS). The i/o -and thread-control primitives are called extensively. The word -"synchronization" in this context refers to the mutex-create and -mutex-wait functionality. - -@strong{\ut (UTILITIES)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - ut0ut.c Utilities / Utilities 7,041 Various utilities - ut0byte.c Utilities / Debug 1,856 Byte utilities - ut0rnd.c Utilities / Random 1,475 Random numbers and hashing - ut0mem.c Utilities / Memory 5,530 Memory primitives - ut0dbg.c Utilities / Debug 642 Debug utilities - -The two functions in ut0byte.c are just for lower/upper case -conversion and comparison. The single function in ut0rnd.c is for -finding a prime slightly greater than the given argument, which is -useful for hash functions, but unrelated to randomness. The functions -in ut0mem.c are wrappers for "malloc" and "free" calls -- for the -real "memory" module see section \mem (MEMORY). Finally, the -functions in ut0ut.c are a miscellany that didn't fit better elsewhere: -get_high_bytes, clock, time, difftime, get_year_month_day, and "sprintf" -for various diagnostic purposes. - -In short: the \ut group is trivial. - -@strong{\buf (BUFFERING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - buf0buf.c Buffering / Buffering 53,246 The database buffer buf_pool - buf0flu.c Buffering / Flush 23,711 ... flush algorithm - buf0lru.c / least-recently-used 20,245 ... replacement algorithm - buf0rea.c Buffering / read 17,399 ... read - -There is a separate file group (\mem MEMORY) which handles memory -requests in general.A "buffer" usually has a more specific -definition, as a memory area which contains copies of pages that -ordinarily are in the main data file. The "buffer pool" is the set -of all buffers (there are lots of them because InnoDB doesn't -depend on the OS's caching to make things faster). - -The pool size is fixed (at the time of this writing) but the rest of -the buffering architecture is sophisticated, involving a host of -control structures. In general: when InnoDB needs to access a new page -it looks first in the buffer pool; InnoDB reads from disk to a new -buffer when the page isn't there; InnoDB chucks old buffers (basing -its decision on a conventional Least-Recently-Used algorithm) when it -has to make space for a new buffer. - -There are routines for checking a page's validity, and for read-ahead. -An example of "read-ahead" use: if a sequential scan is going on, then -a DBMS can read more than one page at a time, which is efficient -because reading 32,768 bytes (two pages) takes less than twice as long -as reading 16,384 bytes (one page). - -@strong{\btr (B-TREE)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - btr0btr.c B-tree / B-tree 74,255 B-tree - btr0cur.c B-tree / Cursor 94,950 index tree cursor - btr0sea.c B-tree / Search 36,580 index tree adaptive search - btr0pcur.c B-tree / persistent cursor 14,548 index tree persistent cursor - -If you total up the sizes of the C files, you'll see that \btr is the -second-largest file group in InnoDB. This is understandable because -maintaining a B-tree is a relatively complex task. Luckily, there has -been a lot of work done to describe efficient management of B-tree and -B+-tree structures, much of it open-source or public-domain, since -their original invention over thirty years ago. - -InnoDB likes to put everything in B-trees. This is what I'd call a -"distinguishing characteristic" because in all the major DBMSs (like -IBM DB2, Microsoft SQL Server, and Oracle), the main or default or -classic structure is the heap-and-index. In InnoDB the main structure -is just the index. To put it another way: InnoDB keeps the rows in the -leaf node of the index, rather than in a separate file. Compare -Oracle's Index Organized Tables, and Microsoft SQL Server's Clustered -Indexes. - -This, by the way, has some consequences. For example, you may as well -have a primary key since otherwise InnoDB will make one anyway. And -that primary key should be the shortest of the candidate keys, since -InnoDB -will use it as a pointer if there are secondary indexes. - -Most importantly, it means that rows have no fixed address. Therefore -the routines for managing file pages should be good. We'll see about -that when we look at the \row (ROW) program group later. - -@strong{\com (COMMUNCATION)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - com0com.c Communication 6,913 Communication primitives - com0shm.c Communication / 24,633 ... through shared memory - Shared Memory - -The communication primitives in com0com.c are said to be modelled -after the ones in Microsoft's winsock library (the Windows Sockets -interface). The communication primitives in com0shm.c are at a -slightly lower level, and are called from the routines in com0com.c. - -I was interested in seeing how InnoDB would handle inter-process -communication, since there are many options -- named pipes, TCP/IP, -Windows messaging, and Shared Memory being the main ones that come to -mind. It appears that InnoDB prefers Shared Memory. The main idea is: -there is an area of memory which two different processes (or threads, -of course) can both access. To communicate, a thread gets an -appropriate mutex, puts in a request, and waits for a response. Thread -interaction is also a subject for the os0thread.c program in another -program group, \os (OPERATING SYSTEM). - -@strong{\dyn (DYNAMICALLY ALLOCATED ARRAY)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - dyn0dyn.c Dynamic / Dynamic 994 dynamically allocated array - -There is a single function in the dyn0dyn.c program, for adding a -block to the dynamically allocated array. InnoDB might use the array -for managing concurrency between threads. - -At the moment, the \dyn program group is trivial. - -@strong{\fil (FILE)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - fil0fil.c File / File 39,725 The low-level file system - -The reads and writes to the database files happen here, in -co-ordination with the low-level file i/o routines (see os0file.h in -the \os program group). - -Briefly: a table's contents are in pages, which are in files, which -are in tablespaces. Files do not grow; instead one can add new files -to the tablespace. As we saw earlier (discussing the \btr program group) -the pages are nodes of B-trees. Since that's the case, new additions can -happen at various places in the logical file structure, not -necessarily at the end. Reads and writes are asynchronous, and go into -buffers, which are set up by routines in the \buf program group. - -@strong{\fsp (FILE SPACE)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - fsp0fsp.c File Space Management 100,271 File space management - -I would have thought that the \fil (FILE) and \fsp (FILE SPACE) -MANAGEMENT programs would fit together in the same program group; -however, I guess the InnoDB folk are splitters rather than lumpers. - -It's in fsp0fsp.c that one finds some of the descriptions and comments -of extents, segments, and headers. For example, the "descriptor bitmap -of the pages in the extent" is in here, and you can find as well how -the free-page list is maintained, what's in the bitmaps, and what -various header fields' contents are. - -@strong{\fut (FILE UTILITY)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - fut0fut.c File Utility / Utility 293 File-based utilities - fut0lst.c File Utility / List 14,129 File-based list utilities - -Mainly these small programs affect only file-based lists, so maybe -saying "File Utility" is too generic. The real work with data files -goes on in the \fsp program group. - -@strong{\log (LOGGING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - log0log.c Logging / Logging 77,834 Database log - log0recv.c Logging / Recovery 80,701 Recovery - -I've already written about the \log program group, so here's a link to -my previous article: "How Logs work with MySQL and InnoDB": -@url{http://www.devarticles.com/art/1/181/2} - -@strong{\mem (MEMORY)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - mem0mem.c Memory / Memory 9,971 The memory management - mem0dbg.c Memory / Debug 21,297 ... the debug code - mem0pool.c Memory / Pool 16,293 ... the lowest level - -There is a long comment at the start of the mem0pool.c program, which -explains what the memory-consumers are, and how InnoDB tries to -satisfy them. The main thing to know is that there are really three -pools: the buffer pool (see the \buf program group), the log pool (see the \log -program group), and the common pool, which is where everything that's -not in the buffer or log pools goes (for example the parsed SQL -statements and the data dictionary cache). - -@strong{\mtr (MINI-TRANSACTION)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - mtr0mtr.c Mini-transaction / 12,433 Mini-transaction buffer - mtr0log.c Mini-transaction / Log 8,180 ... log routines - -The mini-transaction routines are called from most of the other -program groups. I'd describe this as a low-level utility set. - -@strong{\que (QUERY GRAPH)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - que0que.c Query Graph / Query 35,964 Query graph - -The program que0que.c ostensibly is about the execution of stored -procedures which contain commit/rollback statements. I took it that -this has little importance for the average MySQL user. - -@strong{\rem (RECORD MANAGER)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - rem0rec.c Record Manager 14,961 Record Manager - rem0cmp.c Record Manager / 25,263 Comparison services for records - Comparison - -There's an extensive comment near the start of rem0rec.c title -"Physical Record" and it's recommended reading. At some point you'll -ask what are all those bits that surround the data in the rows on a page, -and this is where you'll find the answer. - -@strong{\row (ROW)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - row0row.c Row / Row 16,764 General row routines - row0uins.c Row / Undo Insert 7,199 Fresh insert undo - row0umod.c Row / Undo Modify 17,147 Undo modify of a row - row0undo.c Row / Undo 10,254 Row undo - row0vers.c Row / Version 12,288 Row versions - row0mysql.c Row / MySQL 63,556 Interface [to MySQL] - row0ins.c Row / Insert 42,829 Insert into a table - row0sel.c Row / Select 85,923 Select - row0upd.c Row / Update 44,456 Update of a row - row0purge.c Row / Purge 14,961 Purge obsolete records - -Rows can be selected, inserted, updated/deleted, or purged (a -maintenance activity). These actions have ancillary actions, for -example after insert there can be an index-update test, but it seems -to me that sometimes the ancillary action has no MySQL equivalent (yet) -and so is inoperative. - -Speaking of MySQL, notice that one of the larger programs in the \row -program group is the "interface between Innobase row operations and -MySQL" (row0mysql.c) -- information interchange happens at this level -because rows in InnoDB and in MySQL are analogous, something which -can't be said for pages and other levels. - -@strong{\srv (Server)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - srv0srv.c Server / Server 79,058 Server main program - srv0que.c Server / Query 2,361 Server query execution - srv0start.c Server / Start 34,586 Starts the server - -This is where the server reads the initial configuration files, splits -up the threads, and gets going. There is a long comment deep in the -program (you might miss it at first glance) titled "IMPLEMENTATION OF -THE SERVER MAIN PROGRAM" in which you'll find explanations about -thread priority, and about what the responsibiities are for various -thread types. - -InnoDB has many threads, for example "user threads" (which wait for -client requests and reply to them), "parallel communication threads" -(which take part of a user thread's job if a query process can be -split), "utility threads" (background priority), and a "master thread" -(high priority, usually asleep). - -@strong{\thr (Thread Local Storage)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - thr0loc.c Thread / Local 5,261 The thread local storage - -InnoDB doesn't use the Windows-API thread-local-storage functions, -perhaps because they're not portable enough. - -@strong{\trx (Transaction)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - trx0trx.c Transaction / 37,447 The transaction - trx0purge.c Transaction / Purge 26,782 ... Purge old versions - trx0rec.c Transaction / Record 36,525 ... Undo log record - trx0sys.c Transaction / System 20,671 ... System - trx0rseg.c / Rollback segment 6,214 ... Rollback segment - trx0undo.c Transaction / Undo 46,595 ... Undo log - -InnoDB's transaction management is supposedly "in the style of Oracle" -and that's close to true but can mislead you. -@itemize -@item -First: InnoDB uses rollback segments like Oracle8i does -- but -Oracle9i uses a different name -@item -Second: InnoDB uses multi-versioning like Oracle does -- but I see -nothing that looks like an Oracle ITL being stored in the InnoDB data -pages. -@item -Third: InnoDB and Oracle both have short (back-to-statement-start) -versioning for the READ COMMITTED isolation level and long -(back-to-transaction-start) versioning for higher levels -- but InnoDB -and Oracle have different "default" isolation levels. -@item -Finally: InnoDB's documentation says it has to lock "the gaps before -index keys" to prevent phantoms -- but any Oracle user will tell you that -phantoms are impossible anyway at the SERIALIZABLE isolation level, so -key-locks are unnecessary. -@end itemize - -The main idea, though, is that InnoDB has multi-versioning. So does -Oracle. This is very different from the way that DB2 and SQL Server do -things. - -@strong{\usr (USER)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - usr0sess.c User / Session 27,415 Sessions - -One user can have multiple sessions (the session being all the things -that happen betweeen a connect and disconnect). This is where InnoDB -tracks session IDs, and server/client messaging. It's another of those -items which is usually MySQL's job, though. - -@strong{\data (DATA)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - data0data.c Data / Data 26,002 SQL data field and tuple - data0type.c Data / Type 2,122 Data types - -This is a collection of minor utility routines affecting rows. - -@strong{\dict (DICTIONARY)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - dict0dict.c Dictionary / Dictionary 84,667 Data dictionary system - dict0boot.c Dictionary / boot 12,134 ... creation and booting - dict0load.c Dictionary / load 26,546 ... load to memory cache - dict0mem.c Dictionary / memory 8,221 ... memory object creation - -The data dictionary (known in some circles as the catalog) has the -metadata information about objects in the database -- column sizes, -table names, and the like. - -@strong{\eval (EVALUATING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - eval0eval.c Evaluating/Evaluating 15,682 SQL evaluator - eval0proc.c Evaluating/Procedures 5,000 Executes SQL procedures - -The evaluating step is a late part of the process of interpreting an -SQL statement -- parsing has already occurred during \pars (PARSING). - -The ability to execute SQL stored procedures is an InnoDB feature, but -not a MySQL feature, so the eval0proc.c program is unimportant. - -@strong{\ibuf (INSERT BUFFER)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - ibuf0ibuf.c Insert Buffer / 69,884 Insert buffer - -The words "Insert Buffer" mean not "buffer used for INSERT" but -"insertion of a buffer into the buffer pool" (see the \buf BUFFER -program group description). The matter is complex due to possibilities -for deadlocks, a problem to which the comments in the ibuf0ibuf.c -program devote considerable attention. - -@strong{\mach (MACHINE FORMAT)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - mach0data.c Machine/Data 2,319 Utilities for converting - -The mach0data.c program has two small routines for reading compressed -ulints (unsigned long integers). - -@strong{\lock (LOCKING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - lock0lock.c Lock / Lock 127,646 The transaction lock system - -If you've used DB2 or SQL Server, you might think that locks have their -own in-memory table, that row locks might need occasional escalation to -table locks, and that there are three lock types: Shared, Update, Exclusive. - -All those things are untrue with InnoDB! Locks are kept in the database -pages. A bunch of row locks can't be rolled together into a single table -lock. And most importantly there's only one lock type. I call this type -"Update" because it has the characteristics of DB2 / SQL Server Update -locks, that is, it blocks other updates but doesn't block reads. -Unfortunately, InnoDB comments refer to them as "x-locks" etc. - -To sum it up: if your background is Oracle you won't find too much -surprising, but if your background is DB2 or SQL Server the locking -concepts and terminology will probably confuse you at first. - -You can find an online article about the differences between -Oracle-style and DB2/SQL-Server-style locks at: -@url{http://dbazine.com/gulutzan6.html} - -@strong{\odbc (ODBC)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - odbc0odbc.c ODBC / ODBC 16,865 ODBC client library - -The odbc0odbc.c program has a small selection of old ODBC-API -functions: SQLAllocEnv, SQLAllocConnect, SQLAllocStmt, SQLConnect, -SQLError, SQLPrepare, SQLBindParameter, SQLExecute. - -@strong{\page (PAGE)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - page0page.c Page / Page 44,309 Index page routines - page0cur.c Page / Cursor 30,305 The page cursor - -It's in the page0page.c program that you'll learn as follows: index -pages start with a header, entries in the page are in order, at the -end of the page is a sparse "page directory" (what I would have called -a slot table) which makes binary searches easier. - -Incidentally, the program comments refer to "a page size of 8 kB" -which seems obsolete. In univ.i (a file containing universal -constants) the page size is now #defined as 16KB. - -@strong{\pars (PARSING)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - pars0pars.c Parsing/Parsing 49,947 SQL parser - pars0grm.c Parsing/Grammar 62,685 A Bison parser - pars0opt.c Parsing/Optimizer 30,809 Simple SQL Optimizer - pars0sym.c Parsing/Symbol Table 5,541 SQL parser symbol table - lexyy.c ?/Lexer 59,948 Lexical scanner - -The job is to input a string containing an SQL statement and output an -in-memory parse tree. The EVALUATING (subdirectory \eval) programs -will use the tree. - -As is common practice, the Bison and Flex tools were used -- pars0grm.c -is what the Bison parser produced from an original file named pars0grm.y -(not supplied), and lexyy.c is what Flex produced. - -Since InnoDB is a DBMS by itself, it's natural to find SQL parsing in -it. But in the MySQL/InnoDB combination, MySQL handles most of the -parsing. These files are unimportant. - -@strong{\read (READ)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - read0read.c Read / Read 6,244 Cursor read - -The read0read.c program opens a "read view" of a query result, using -some functions in the \trx program group. - -@strong{\sync (SYNCHRONIZATION)} - File Name What Name Stands For Size Comment Inside File - --------- -------------------- ------ ------------------- - sync0sync.c Synchronization / 35,918 Mutex, the basic sync primitive - sync0arr.c ... / array 26,461 Wait array used in primitives - sync0ipm.c ... / interprocess 4,027 for interprocess sync - sync0rw.c ... / read-write 22,220 read-write lock for thread sync - -A mutex (Mutual Exclusion) is an object which only one thread/process -can hold at a time. Any modern operating system API has some functions -for mutexes; however, as the comments in the sync0sync.c code indicate, it -can be faster to write one's own low-level mechanism. In fact the old -assembly-language XCHG trick is in here -- this is the only program -that contains any assembly code. -@end example -@* -@* - -This is the end of the section-by-section account of InnoDB -subdirectories. -@*@* - -@strong{A Note About File Naming} @*@* - -There appears to be a naming convention. The first letters of the file -name are the same as the subdirectory name, then there is a '0' -separator, then there is an individual name. For the main program in a -subdirectory, the individual name may be a repeat of the subdirectory -name. For example, there is a file named ha0ha.c (the first two -letters ha mean "it's in in subdirectory ..\ha", the next letter 0 -means "0 separator", the next two letters mean "this is the main ha -program"). This naming convention is not strict, though: for example -the file lexyy.c is in the \pars subdirectory. -@*@* - -@strong{A Note About Copyrights} @*@* - -Most of the files begin with a copyright notice or a creation date, -for example "Created 10/25/1995 Heikki Tuuri". I don't know a great -deal about the history of InnoDB, but found it interesting that most -creation dates were between 1994 and 1998. -@*@* - -@strong{References} @*@* - -Ryan Bannon, Alvin Chin, Faryaaz Kassam and Andrew Roszko @* -"InnoDB Concrete Architecture" @* -@url{http://www.swen.uwaterloo.ca/~mrbannon/cs798/assignment_02/innodb.pdf} - -A student paper. It's an interesting attempt to figure out InnoDB's -architecture using tools, but I didn't end up using it for the specific -purposes of this article. -@*@* - -Peter Gulutzan @* -"How Logs Work With MySQL And InnoDB" @* -@url{http://www.devarticles.com/art/1/181/2} -@*@* - -Heikki Tuuri @* -"InnoDB Engine in MySQL-Max-3.23.54 / MySQL-4.0.9: The Up-to-Date -Reference Manual of InnoDB" @* -@url{http://www.innodb.com/ibman.html} - -This is the natural starting point for all InnoDB information. Mr -Tuuri also appears frequently on MySQL forums. -@*@* - -@summarycontents -@contents - -@bye diff --git a/Docs/manual_toc.html b/Docs/manual_toc.html new file mode 100644 index 00000000000..b9014e5efb9 --- /dev/null +++ b/Docs/manual_toc.html @@ -0,0 +1,9 @@ +<html> +<head> +<title>Place holder for manual_toc.html</title> +</head> +<body> +This is just a place holder for the autogenerated manual_toc.html +to make "make dist" happy. +</body> +</html> diff --git a/Images/.cvsignore b/Images/.cvsignore deleted file mode 100644 index 6d0d61a83d5..00000000000 --- a/Images/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -logo_nusphere_b.tif diff --git a/Makefile.am b/Makefile.am index 26c26357400..1fcf498a84b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,7 +70,10 @@ linked_netware_sources: #avoid recursive make calls in sql directory linked_server_sources: - cd sql; rm -f mini_client_errors.c;@LN_CP_F@ ../libmysql/errmsg.c mini_client_errors.c; rm -f pack.c;@LN_CP_F@ ../sql-common/pack.c pack.c + cd sql; rm -f mini_client_errors.c;\ + @LN_CP_F@ ../libmysql/errmsg.c mini_client_errors.c;\ + rm -f pack.c;@LN_CP_F@ ../sql-common/pack.c pack.c;\ + rm -f client.c;@LN_CP_F@ ../sql-common/client.c client.c echo timestamp > linked_server_sources # Create permission databases diff --git a/VC++Files/client/mysqlclient.dsp b/VC++Files/client/mysqlclient.dsp index 7009d8f19e6..89976d7f77f 100644 --- a/VC++Files/client/mysqlclient.dsp +++ b/VC++Files/client/mysqlclient.dsp @@ -414,6 +414,10 @@ SOURCE=..\sql\net_serv.cpp # End Source File # Begin Source File +SOURCE=..\libmysql\pack.c +# End Source File +# Begin Source File + SOURCE=..\libmysql\password.c # End Source File # Begin Source File diff --git a/VC++Files/libmysql/libmysql.dsp b/VC++Files/libmysql/libmysql.dsp index 1a276c75447..bccb6d57c7f 100644 --- a/VC++Files/libmysql/libmysql.dsp +++ b/VC++Files/libmysql/libmysql.dsp @@ -25,7 +25,7 @@ CFG=libmysql - Win32 Debug # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" -CPP=cl.exe +CPP=xicl6.exe MTL=midl.exe RSC=rc.exe @@ -52,7 +52,7 @@ RSC=rc.exe BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -LINK32=link.exe +LINK32=xilink6.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 # ADD LINK32 wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /def:"libmysql.def" /out:"..\lib_release\libmysql.dll" /libpath:"." /libpath:"..\lib_release" # SUBTRACT LINK32 /pdb:none @@ -85,7 +85,7 @@ PostBuild_Cmds=xcopy release\libmysql.lib ..\lib_release /y BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -LINK32=link.exe +LINK32=xilink6.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 zlib.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug /machine:I386 /def:"libmysql.def" /out:"..\lib_debug\libmysql.dll" /pdbtype:sept /libpath:"." /libpath:"..\lib_debug" # SUBTRACT LINK32 /pdb:none @@ -215,6 +215,10 @@ SOURCE=.\libmysql.c # End Source File # Begin Source File +SOURCE=.\pack.c +# End Source File +# Begin Source File + SOURCE=.\Libmysql.def # End Source File # Begin Source File @@ -251,6 +255,10 @@ SOURCE=..\mysys\mf_pack.c # End Source File # Begin Source File +SOURCE=..\mysys\mf_path.c +# End Source File +# Begin Source File + SOURCE=..\mysys\mf_unixpath.c # End Source File # Begin Source File diff --git a/VC++Files/mysql.dsw b/VC++Files/mysql.dsw index eef82588fa8..9903c91ba1b 100644 --- a/VC++Files/mysql.dsw +++ b/VC++Files/mysql.dsw @@ -605,6 +605,9 @@ Package=<5> Package=<4> {{{ + Begin Project Dependency + Project_Dep_Name strings + End Project Dependency }}} ############################################################################### diff --git a/acconfig.h b/acconfig.h index 5f47365709c..0b822d67cf5 100644 --- a/acconfig.h +++ b/acconfig.h @@ -19,7 +19,10 @@ #undef CRAY_STACKSEG_END /* Define the default charset name */ -#undef DEFAULT_CHARSET_NAME +#undef MYSQL_DEFAULT_CHARSET_NAME + +/* Define the default charset name */ +#undef MYSQL_DEFAULT_COLLATION_NAME /* Version of .frm files */ #undef DOT_FRM_VERSION @@ -68,40 +71,37 @@ /* Define charsets you want */ #undef HAVE_CHARSET_armscii8 +#undef HAVE_CHARSET_ascii #undef HAVE_CHARSET_big5 +#undef HAVE_CHARSET_cp1250 #undef HAVE_CHARSET_cp1251 +#undef HAVE_CHARSET_cp1256 #undef HAVE_CHARSET_cp1257 -#undef HAVE_CHARSET_croat -#undef HAVE_CHARSET_czech -#undef HAVE_CHARSET_danish +#undef HAVE_CHARSET_cp850 +#undef HAVE_CHARSET_cp852 +#undef HAVE_CHARSET_cp866 #undef HAVE_CHARSET_dec8 -#undef HAVE_CHARSET_dos -#undef HAVE_CHARSET_estonia -#undef HAVE_CHARSET_euc_kr +#undef HAVE_CHARSET_euckr #undef HAVE_CHARSET_gb2312 #undef HAVE_CHARSET_gbk -#undef HAVE_CHARSET_german1 #undef HAVE_CHARSET_greek #undef HAVE_CHARSET_hebrew #undef HAVE_CHARSET_hp8 -#undef HAVE_CHARSET_hungarian -#undef HAVE_CHARSET_koi8_ru -#undef HAVE_CHARSET_koi8_ukr +#undef HAVE_CHARSET_keybcs2 +#undef HAVE_CHARSET_koi8r +#undef HAVE_CHARSET_koi8u #undef HAVE_CHARSET_latin1 -#undef HAVE_CHARSET_latin1_de #undef HAVE_CHARSET_latin2 #undef HAVE_CHARSET_latin5 +#undef HAVE_CHARSET_latin7 +#undef HAVE_CHARSET_macce +#undef HAVE_CHARSET_macroman #undef HAVE_CHARSET_sjis #undef HAVE_CHARSET_swe7 #undef HAVE_CHARSET_tis620 #undef HAVE_CHARSET_ucs2 #undef HAVE_CHARSET_ujis -#undef HAVE_CHARSET_usa7 #undef HAVE_CHARSET_utf8 -#undef HAVE_CHARSET_win1250 -#undef HAVE_CHARSET_win1250ch -#undef HAVE_CHARSET_win1251ukr -#undef HAVE_CHARSET_win1251 /* ZLIB and compress: */ #undef HAVE_COMPRESS diff --git a/acinclude.m4 b/acinclude.m4 index 970620d9be7..269b505386c 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -78,7 +78,7 @@ AC_LANG_SAVE AC_LANG_CPLUSPLUS if test "$ac_cv_prog_gxx" = "yes" then - CXXFLAGS="$CXXFLAGS -Werror" + CXXFLAGS=`echo $CXXFLAGS -Werror | sed 's/-fbranch-probabilities//'` fi mysql_cv_btype_last_arg_accept=none [AC_TRY_COMPILE([#if defined(inline) diff --git a/client/mysql.cc b/client/mysql.cc index 2623660033b..1bfadb37eb2 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -139,7 +139,7 @@ static my_string opt_mysql_unix_port=0; static int connect_flag=CLIENT_INTERACTIVE; static char *current_host,*current_db,*current_user=0,*opt_password=0, *current_prompt=0, *delimiter_str= 0, - *default_charset= (char*) MYSQL_CHARSET; + *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; static char *histfile; static String glob_buffer,old_buffer; static String processed_prompt; @@ -809,7 +809,8 @@ static int get_options(int argc, char **argv) opt_reconnect= 0; connect_flag= 0; /* Not in interactive mode */ } - if (!(charset_info= get_charset_by_name(default_charset, MYF(MY_WME)))) + if (!(charset_info= get_charset_by_csname(default_charset, + MY_CS_PRIMARY, MYF(MY_WME)))) exit(1); if (argc > 1) { @@ -1091,7 +1092,7 @@ static bool add_line(String &buffer,char *line,char *in_string, { // Add found char to buffer if (inchar == *in_string) *in_string=0; - else if (!*in_string && (inchar == '\'' || inchar == '"')) + else if (!*in_string && (inchar == '\'' || inchar == '"' || inchar == '`')) *in_string=(char) inchar; if (!(*ml_comment)) *out++ = (char) inchar; @@ -1456,6 +1457,16 @@ int mysql_store_result_for_lazy(MYSQL_RES **result) return 0; } +static void print_help_item(MYSQL_ROW *cur, int num_name, int num_cat, char *last_char) +{ + char ccat= (*cur)[num_cat][0]; + if (*last_char != ccat) + { + put_info(ccat == 'Y' ? "categories :" : "topics :", INFO_INFO); + *last_char= ccat; + } + tee_fprintf(PAGER, " %s\n", (*cur)[num_name]); +} static int com_server_help(String *buffer __attribute__((unused)), char *line __attribute__((unused)), char *help_arg) @@ -1464,14 +1475,15 @@ static int com_server_help(String *buffer __attribute__((unused)), const char *server_cmd= buffer->ptr(); char cmd_buf[100]; MYSQL_RES *result; + MYSQL_FIELD *fields; int error; - + if (help_arg[0] != '\'') { (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NullS); server_cmd= cmd_buf; } - + if (!status.batch) { old_buffer= *buffer; @@ -1481,15 +1493,16 @@ static int com_server_help(String *buffer __attribute__((unused)), if (!connected && reconnect()) return 1; - if ((error= mysql_real_query_for_lazy(server_cmd,strlen(server_cmd)))) - return error; - if ((error= mysql_store_result_for_lazy(&result))) + if ((error= mysql_real_query_for_lazy(server_cmd,strlen(server_cmd))) || + (error= mysql_store_result_for_lazy(&result))) return error; if (result) { - ulonglong num_rows= mysql_num_rows(result); - if (num_rows == 1) + unsigned int num_fields= mysql_num_fields(result); + my_ulonglong num_rows= mysql_num_rows(result); + fields= mysql_fetch_fields(result); + if (num_fields==3 && num_rows==1) { if (!(cur= mysql_fetch_row(result))) { @@ -1498,46 +1511,45 @@ static int com_server_help(String *buffer __attribute__((unused)), } init_pager(); - if (cur[1][0] == 'Y') - { - tee_fprintf(PAGER, "Help topic \'%s\'\n", cur[0]); - tee_fprintf(PAGER, "%s\n", cur[2]); - tee_fprintf(PAGER, "For help on specific function please type 'help <function>'\nwhere function is one of next:\n%s\n", cur[3]); - } - else - { - tee_fprintf(PAGER, "Name: \'%s\'\n\n", cur[0]); - tee_fprintf(PAGER, "Description:\n%s\n\n", cur[2]); - if (cur[3]) - tee_fprintf(PAGER, "Examples:\n%s\n", cur[3]); - } + tee_fprintf(PAGER, "Name: \'%s\'\n", cur[0]); + tee_fprintf(PAGER, "Description:\n%s", cur[1]); + if (cur[2] && *((char*)cur[2])) + tee_fprintf(PAGER, "Examples:\n%s", cur[2]); + tee_fprintf(PAGER, "\n"); end_pager(); } - else if (num_rows > 1) + else if (num_fields >= 2 && num_rows) { - put_info("Many help items for your request exist", INFO_INFO); - put_info("For more specific request please type 'help <item>' where item is one of next:", INFO_INFO); - init_pager(); - char last_char= '_'; - while ((cur= mysql_fetch_row(result))) + char last_char; + + int num_name, num_cat; + if (num_fields == 2) { - if (cur[1][0]!=last_char) - { - put_info("-------------------------------------------", INFO_INFO); - put_info(cur[1][0] == 'Y' ? - "categories:" : "functions:", INFO_INFO); - put_info("-------------------------------------------", INFO_INFO); - } - last_char= cur[1][0]; - tee_fprintf(PAGER, "%s\n", cur[0]); + put_info("Many help items for your request exist", INFO_INFO); + put_info("For more specific request please type 'help <item>' where item is one of next", INFO_INFO); + num_name= 0; + num_cat= 1; + last_char= '_'; + } + else if ((cur= mysql_fetch_row(result))) + { + tee_fprintf(PAGER, "You asked help about help category: \"%s\"\n", cur[0]); + put_info("For a more information type 'help <item>' where item is one of the following", INFO_INFO); + num_name= 1; + num_cat= 2; + print_help_item(&cur,1,2,&last_char); } + + while ((cur= mysql_fetch_row(result))) + print_help_item(&cur,num_name,num_cat,&last_char); tee_fprintf(PAGER, "\n"); end_pager(); } else { - put_info("\nNothing found\n", INFO_INFO); + put_info("\nNothing found", INFO_INFO); + put_info("Please try to run 'help contents' for list of all accessible topics\n", INFO_INFO); } } @@ -1792,9 +1804,8 @@ print_field_types(MYSQL_RES *result) MYSQL_FIELD *field; while ((field = mysql_fetch_field(result))) { - tee_fprintf(PAGER,"%s '%s' %d %d %d %d %d\n", - field->name, - field->table ? "" : field->table, + tee_fprintf(PAGER,"'%s.%s.%s.%s' %d %d %d %d %d\n", + field->catalog, field->db, field->table, field->name, (int) field->type, field->length, field->max_length, field->flags, field->decimals); @@ -2549,6 +2560,7 @@ sql_real_connect(char *host,char *database,char *user,char *password, select_limit,max_join_size); mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command); } + mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset); if (!mysql_real_connect(&mysql, host, user, password, database, opt_mysql_port, opt_mysql_unix_port, connect_flag | CLIENT_MULTI_QUERIES)) @@ -2709,31 +2721,32 @@ select_limit, max_join_size); static int put_info(const char *str,INFO_TYPE info_type,uint error) { + FILE *file= (info_type == INFO_ERROR ? stderr : stdout); static int inited=0; if (status.batch) { if (info_type == INFO_ERROR) { - (void) fflush(stdout); - fprintf(stderr,"ERROR"); + (void) fflush(file); + fprintf(file,"ERROR"); if (error) - (void) fprintf(stderr," %d",error); + (void) fprintf(file," %d",error); if (status.query_start_line && line_numbers) { - (void) fprintf(stderr," at line %lu",status.query_start_line); + (void) fprintf(file," at line %lu",status.query_start_line); if (status.file_name) - (void) fprintf(stderr," in file: '%s'", status.file_name); + (void) fprintf(file," in file: '%s'", status.file_name); } - (void) fprintf(stderr,": %s\n",str); - (void) fflush(stderr); + (void) fprintf(file,": %s\n",str); + (void) fflush(file); if (!ignore_errors) return 1; } else if (info_type == INFO_RESULT && verbose > 1) - tee_puts(str, stdout); + tee_puts(str, file); if (unbuffered) - fflush(stdout); + fflush(file); return info_type == INFO_ERROR ? -1 : 0; } if (!opt_silent || info_type == INFO_ERROR) @@ -2751,17 +2764,17 @@ put_info(const char *str,INFO_TYPE info_type,uint error) putchar('\007'); /* This should make a bell */ vidattr(A_STANDOUT); if (error) - (void) tee_fprintf(stderr, "ERROR %d: ", error); + (void) tee_fprintf(file, "ERROR %d: ", error); else - tee_puts("ERROR: ", stdout); + tee_puts("ERROR: ", file); } else vidattr(A_BOLD); - (void) tee_puts(str, stdout); + (void) tee_puts(str, file); vidattr(A_NORMAL); } if (unbuffered) - fflush(stdout); + fflush(file); return info_type == INFO_ERROR ? -1 : 0; } diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index a5f769c0782..ff86882bad3 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -45,6 +45,7 @@ static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace"; void sql_print_error(const char *format, ...); static bool one_database = 0; +static bool force_opt= 0; static const char* database; static bool short_form = 0; static ulonglong offset = 0; @@ -201,6 +202,9 @@ static struct my_option my_long_options[] = {"database", 'd', "List entries for just this database (local log only)", (gptr*) &database, (gptr*) &database, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"force-read", 'f', "Force reading unknown binlog events", + (gptr*) &force_opt, (gptr*) &force_opt, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"host", 'h', "Get the binlog from server", (gptr*) &host, (gptr*) &host, diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index cd8cd0ef82e..b21a73aae4f 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -38,7 +38,8 @@ static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0, static uint verbose = 0, opt_mysql_port=0; static my_string opt_mysql_unix_port = 0; static char *opt_password = 0, *current_user = 0, - *default_charset = (char *)MYSQL_CHARSET, *current_host = 0; + *default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME, + *current_host = 0; static int first_error = 0; DYNAMIC_ARRAY tables4repair; #ifdef HAVE_SMEM @@ -308,7 +309,8 @@ static int get_options(int *argc, char ***argv) else what_to_do = DO_CHECK; } - if (!(charset_info= get_charset_by_name(default_charset, MYF(MY_WME)))) + if (!(charset_info= get_charset_by_csname(default_charset, + MY_CS_PRIMARY, MYF(MY_WME)))) exit(1); if (*argc > 0 && opt_alldbs) { diff --git a/client/mysqldump.c b/client/mysqldump.c index b5e596ba072..18705b9e375 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -77,7 +77,7 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick= 1, extended_insert= 1, lock_tables=1,ignore_errors=0,flush_logs=0,replace=0, ignore=0,opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0, - opt_alldbs=0,opt_create_db=0,opt_first_slave=0, + opt_alldbs=0,opt_create_db=0,opt_first_slave=0,opt_set_names=0, opt_autocommit=0,opt_master_data,opt_disable_keys=1,opt_xml=0, opt_delete_master_logs=0, tty_password=0, opt_single_transaction=0; @@ -85,7 +85,7 @@ static MYSQL mysql_connection,*sock=0; static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, *current_host=0,*path=0,*fields_terminated=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0, - *where=0, *default_charset= (char *)MYSQL_CHARSET, + *where=0, *default_charset= (char *) "binary", *opt_compatible_mode_str= 0, *err_ptr= 0; static ulong opt_compatible_mode= 0; @@ -212,6 +212,10 @@ static struct my_option my_long_options[] = (gptr*) &tFlag, (gptr*) &tFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"no-set-names", 'N', + "'SET NAMES charset_name' will not be put in the output.", + (gptr*) &opt_set_names, (gptr*) &opt_set_names, 0, GET_BOOL, NO_ARG, 0, 0, + 0, 0, 0, 0}, {"set-variable", 'O', "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -345,6 +349,8 @@ static void write_header(FILE *sql_file, char *db_name) sql_file); fprintf(sql_file, "-- Server version\t%s\n", mysql_get_server_info(&mysql_connection)); + if (!opt_set_names) + fprintf(sql_file,"\n/*!40101 SET NAMES %s*/;\n",default_charset); } return; } /* write_header */ @@ -492,7 +498,8 @@ static int get_options(int *argc, char ***argv) my_progname); return(1); } - if (!(charset_info= get_charset_by_name(default_charset, MYF(MY_WME)))) + if (!(charset_info= get_charset_by_csname(default_charset, + MY_CS_PRIMARY, MYF(MY_WME)))) exit(1); if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs)) { @@ -556,6 +563,7 @@ static int dbConnect(char *host, char *user,char *passwd) if (shared_memory_base_name) mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); #endif + mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset); if (!(sock= mysql_real_connect(&mysql_connection,host,user,passwd, NULL,opt_mysql_port,opt_mysql_unix_port, 0))) @@ -1613,7 +1621,7 @@ int main(int argc, char **argv) else { row = mysql_fetch_row(master); - if (row[0] && row[1]) + if (row && row[0] && row[1]) { fprintf(md_result_file, "\n--\n-- Position to start replication from\n--\n\n"); diff --git a/client/mysqlimport.c b/client/mysqlimport.c index efb117280c4..8ee656f23b2 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -44,7 +44,7 @@ static char *opt_password=0, *current_user=0, *current_host=0, *current_db=0, *fields_terminated=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0, *opt_columns=0, - *default_charset= (char*) MYSQL_CHARSET; + *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; static uint opt_mysql_port=0; static my_string opt_mysql_unix_port=0; static my_string opt_ignore_lines=0; @@ -239,7 +239,8 @@ static int get_options(int *argc, char ***argv) fprintf(stderr, "You can't use --ignore (-i) and --replace (-r) at the same time.\n"); return(1); } - if (!(charset_info= get_charset_by_name(default_charset, MYF(MY_WME)))) + if (!(charset_info= get_charset_by_csname(default_charset, + MY_CS_PRIMARY, MYF(MY_WME)))) exit(1); if (*argc < 2) { diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 9b376872ff8..5bb611b713f 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -30,6 +30,7 @@ static my_string host=0,opt_password=0,user=0; static my_bool opt_show_keys=0,opt_compress=0,opt_status=0, tty_password=0; static uint opt_verbose=0; +static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; #ifdef HAVE_SMEM static char *shared_memory_base_name=0; @@ -115,6 +116,8 @@ int main(int argc, char **argv) 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 (!(mysql_real_connect(&mysql,host,user,opt_password, (first_argument_uses_wildcards) ? "" : argv[0],opt_mysql_port,opt_mysql_unix_port, 0))) @@ -155,6 +158,9 @@ static struct my_option my_long_options[] = {"character-sets-dir", 'c', "Directory where character sets are", (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"default-character-set", OPT_DEFAULT_CHARSET, + "Set the default character set.", (gptr*) &default_charset, + (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"compress", 'C', "Use compression in server/client protocol", (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -558,7 +564,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table, mysql_error(mysql)); return 1; } - end=strmov(strmov(query,"show /*!32332 FULL */ columns from "),table); + end=strmov(strmov(strmov(query,"show /*!32332 FULL */ columns from `"),table),"`"); if (wild && wild[0]) strxmov(end," like '",wild,"'",NullS); if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql))) @@ -580,7 +586,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table, print_res_top(result); if (opt_show_keys) { - end=strmov(strmov(query,"show keys from "),table); + end=strmov(strmov(strmov(query,"show keys from `"),table),"`"); if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql))) { fprintf(stderr,"%s: Cannot list keys in db: %s, table: %s: %s\n", diff --git a/client/mysqltest.c b/client/mysqltest.c index fb2104f43f4..9889d365335 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -939,16 +939,16 @@ int do_system(struct st_query* q) var_init(&v, 0, 0, 0, 0); eval_expr(&v, p, 0); /* NULL terminated */ if (v.str_val_len) - { - char expr_buf[512]; - if ((uint)v.str_val_len > sizeof(expr_buf) - 1) - v.str_val_len = sizeof(expr_buf) - 1; - memcpy(expr_buf, v.str_val, v.str_val_len); - expr_buf[v.str_val_len] = 0; - DBUG_PRINT("info", ("running system command '%s'", expr_buf)); - if (system(expr_buf) && q->abort_on_error) - die("system command '%s' failed", expr_buf); - } + { + char expr_buf[512]; + if ((uint)v.str_val_len > sizeof(expr_buf) - 1) + v.str_val_len = sizeof(expr_buf) - 1; + memcpy(expr_buf, v.str_val, v.str_val_len); + expr_buf[v.str_val_len] = 0; + DBUG_PRINT("info", ("running system command '%s'", expr_buf)); + if (system(expr_buf) && q->abort_on_error) + die("system command '%s' failed", expr_buf); + } var_free(&v); return 0; } @@ -2284,7 +2284,7 @@ void get_query_type(struct st_query* q) q->type=(enum enum_commands) type; /* Found command */ } -static byte* get_var_key(const byte* var, uint* len, +static byte *get_var_key(const byte* var, uint* len, my_bool __attribute__((unused)) t) { register char* key; @@ -2293,11 +2293,11 @@ static byte* get_var_key(const byte* var, uint* len, return (byte*)key; } -static VAR* var_init(VAR* v, const char* name, int name_len, const char* val, +static VAR *var_init(VAR *v, const char *name, int name_len, const char *val, int val_len) { int val_alloc_len; - VAR* tmp_var; + VAR *tmp_var; if (!name_len && name) name_len = strlen(name); if (!val_len && val) @@ -2327,7 +2327,7 @@ static VAR* var_init(VAR* v, const char* name, int name_len, const char* val, return tmp_var; } -static void var_free(void* v) +static void var_free(void *v) { my_free(((VAR*) v)->str_val, MYF(MY_WME)); if (((VAR*)v)->alloced) @@ -2335,10 +2335,10 @@ static void var_free(void* v) } -static void var_from_env(const char* name, const char* def_val) +static void var_from_env(const char *name, const char *def_val) { - const char* tmp; - VAR* v; + const char *tmp; + VAR *v; if (!(tmp = getenv(name))) tmp = def_val; @@ -2347,9 +2347,9 @@ static void var_from_env(const char* name, const char* def_val) } -static void init_var_hash() +static void init_var_hash(MYSQL *mysql) { - VAR* v; + VAR *v; DBUG_ENTER("init_var_hash"); if (hash_init(&var_hash, charset_info, 1024, 0, 0, get_var_key, var_free, MYF(0))) @@ -2358,16 +2358,19 @@ static void init_var_hash() var_from_env("SLAVE_MYPORT", "9307"); var_from_env("MYSQL_TEST_DIR", "/tmp"); var_from_env("BIG_TEST", opt_big_test ? "1" : "0"); - v=var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "63",0); - hash_insert(&var_hash, (byte*)v); + v= var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "62",0); + hash_insert(&var_hash, (byte*) v); + v= var_init(0,"SERVER_VERSION", 0, mysql_get_server_info(mysql), 0); + hash_insert(&var_hash, (byte*) v); + DBUG_VOID_RETURN; } -int main(int argc, char** argv) +int main(int argc, char **argv) { int error = 0; - struct st_query* q; + struct st_query *q; my_bool require_file=0, q_send_flag=0; char save_file[FN_REFLEN]; MY_INIT(argv[0]); @@ -2402,7 +2405,6 @@ int main(int argc, char** argv) embedded_server_args, (char**) embedded_server_groups)) die("Can't initialize MySQL server"); - init_var_hash(); if (cur_file == file_stack) *++cur_file = stdin; *lineno=1; @@ -2421,14 +2423,14 @@ int main(int argc, char** argv) opt_ssl_capath, opt_ssl_cipher); #endif - cur_con->name = my_strdup("default", MYF(MY_WME)); - if (!cur_con->name) + if (!(cur_con->name = my_strdup("default", MYF(MY_WME)))) die("Out of memory"); - if (safe_connect(&cur_con->mysql, host, - user, pass, db, port, unix_sock)) + if (safe_connect(&cur_con->mysql, host, user, pass, db, port, unix_sock)) die("Failed in mysql_real_connect(): %s", mysql_error(&cur_con->mysql)); + init_var_hash(&cur_con->mysql); + while (!read_query(&q)) { int current_line_inc = 1, processed = 0; @@ -2596,7 +2598,7 @@ int main(int argc, char** argv) */ -static int read_server_arguments(const char* name) +static int read_server_arguments(const char *name) { char argument[1024],buff[FN_REFLEN], *str=0; FILE *file; diff --git a/client/sql_string.cc b/client/sql_string.cc index 8ab205d9fb1..65a9ff68c53 100644 --- a/client/sql_string.cc +++ b/client/sql_string.cc @@ -97,13 +97,13 @@ bool String::set(longlong num, CHARSET_INFO *cs) if (alloc(l)) return TRUE; - if (cs->snprintf == my_snprintf_8bit) + if (cs->cset->snprintf == my_snprintf_8bit) { str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr); } else { - str_length=cs->snprintf(cs,Ptr,l,"%d",num); + str_length=cs->cset->snprintf(cs,Ptr,l,"%d",num); } str_charset=cs; return FALSE; @@ -115,13 +115,13 @@ bool String::set(ulonglong num, CHARSET_INFO *cs) if (alloc(l)) return TRUE; - if (cs->snprintf == my_snprintf_8bit) + if (cs->cset->snprintf == my_snprintf_8bit) { str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr); } else { - str_length=cs->snprintf(cs,Ptr,l,"%d",num); + str_length=cs->cset->snprintf(cs,Ptr,l,"%d",num); } str_charset=cs; return FALSE; @@ -255,7 +255,7 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *from, CHARSET for (str_length=new_length ; s < se && d < de ; ) { - if ((cnvres=from->mb_wc(from,&wc,s,se)) > 0 ) + if ((cnvres=from->cset->mb_wc(from,&wc,s,se)) > 0 ) { s+=cnvres; } @@ -268,7 +268,7 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *from, CHARSET break; outp: - if((cnvres=to->wc_mb(to,wc,d,de)) >0 ) + if((cnvres=to->cset->wc_mb(to,wc,d,de)) >0 ) { d+=cnvres; } diff --git a/configure.in b/configure.in index 90c8e81bd47..f25cb213e0b 100644 --- a/configure.in +++ b/configure.in @@ -1005,8 +1005,9 @@ case $SYSTEM_TYPE in *darwin5*) if test "$ac_cv_prog_gcc" = "yes" then - CFLAGS="$CFLAGS -traditional-cpp -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DHAVE_BROKEN_REALPATH -DFN_NO_CASE_SENCE" - CXXFLAGS="$CXXFLAGS -traditional-cpp -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DFN_NO_CASE_SENCE" + FLAGS="-traditional-cpp -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DHAVE_BROKEN_REALPATH -DFN_NO_CASE_SENCE" + CFLAGS="$CFLAGS $FLAGS" + CXXFLAGS="$CXXFLAGS $FLAGS" MAX_C_OPTIMIZE="-O" with_named_curses="" fi @@ -1014,8 +1015,9 @@ case $SYSTEM_TYPE in *darwin6*) if test "$ac_cv_prog_gcc" = "yes" then - CFLAGS="$CFLAGS -traditional-cpp -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DHAVE_BROKEN_REALPATH -DFN_NO_CASE_SENCE" - CXXFLAGS="$CXXFLAGS -traditional-cpp -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DFN_NO_CASE_SENCE" + FLAGS="-traditional-cpp -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DHAVE_BROKEN_REALPATH -DFN_NO_CASE_SENCE" + CFLAGS="$CFLAGS $FLAGS" + CXXFLAGS="$CXXFLAGS $FLAGS" MAX_C_OPTIMIZE="-O" fi ;; @@ -1365,10 +1367,8 @@ then with_named_thread="-Kthread -lsocket -lnsl" if expr "$SYSTEM_TYPE" : ".*unixware7.0.0" > /dev/null then -# AC_DEFINE(HAVE_OpenUNIX8_THREADS) AC_DEFINE(HAVE_UNIXWARE7_THREADS) else -# AC_DEFINE(HAVE_OpenUNIX8_POSIX) AC_DEFINE(HAVE_UNIXWARE7_POSIX) fi # We must have cc @@ -1377,10 +1377,8 @@ then then { echo "configure: error: On OpenUNIX8 and UnixWare7 MySQL must be compiled with cc. See the Installation chapter in the Reference Manual." 1>&2; exit 1; }; else -# CC="$CC -Kthread -DOpenUNIX8"; -# CXX="$CXX -Kthread -DOpenUNIX8"; - CC="$CC -Kthread -DUNIXWARE_7 -DHAVE_BROKEN_RWLOCK"; - CXX="$CXX -Kthread -DUNIXWARE_7 -DHAVE_BROKEN_RWLOCK" + CC="$CC -Kthread -DUNIXWARE_7 -DHAVE_BROKEN_RWLOCK"; + CXX="$CXX -Kthread -DUNIXWARE_7 -DHAVE_BROKEN_RWLOCK"; fi AC_MSG_RESULT("yes") else @@ -1877,7 +1875,7 @@ AC_LANG_SAVE AC_LANG_CPLUSPLUS if test "$ac_cv_prog_gxx" = "yes" -a "$with_other_libc" = "no" then - CXXFLAGS="$CXXFLAGS -Werror" + CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'` fi AC_TRY_COMPILE( [#undef inline @@ -1909,7 +1907,7 @@ AC_LANG_SAVE AC_LANG_CPLUSPLUS if test "$ac_cv_prog_gxx" = "yes" -a "$with_other_libc" = "no" then - CXXFLAGS="$CXXFLAGS -Werror" + CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'` fi AC_TRY_COMPILE( [#undef inline @@ -2228,28 +2226,41 @@ AC_SUBST(readline_h_ln_cmd) dnl In order to add new charset, you must add charset name to -dnl this CHARSETS_AVAILABLE list and sql/share/charsets/Index. +dnl this CHARSETS_AVAILABLE list and sql/share/charsets/Index.xml. dnl If the character set uses strcoll or other special handling, dnl you must also create strings/ctype-$charset_name.c AC_DIVERT_PUSH(0) -CHARSETS_AVAILABLE="armscii8 big5 cp1251 cp1257 - croat czech danish dec8 dos estonia euc_kr gb2312 gbk - german1 greek hebrew hp8 hungarian koi8_ru koi8_ukr - latin1 latin1_de latin2 latin5 sjis swe7 tis620 ucs2 ujis - usa7 utf8 win1250 win1250ch win1251ukr" -CHARSETS_DEPRECATED="win1251" -CHARSETS_COMPLEX="big5 czech euc_kr gb2312 gbk latin1_de sjis tis620 ucs2 ujis utf8 win1250ch" + +define(CHARSETS_AVAILABLE1,ascii armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257) +define(CHARSETS_AVAILABLE2,cp850 cp852 cp866 dec8 euckr gb2312 gbk) +define(CHARSETS_AVAILABLE3,greek hebrew hp8 keybcs2 koi8r koi8u) +define(CHARSETS_AVAILABLE4,latin1 latin2 latin5 latin7 macce macroman) +define(CHARSETS_AVAILABLE5,sjis swe7 tis620 ucs2 ujis utf8) + DEFAULT_CHARSET=latin1 -AC_DIVERT_POP +CHARSETS_AVAILABLE="CHARSETS_AVAILABLE1 CHARSETS_AVAILABLE2 CHARSETS_AVAILABLE3 CHARSETS_AVAILABLE4 CHARSETS_AVAILABLE5" +CHARSETS_COMPLEX="big5 cp1250 euckr gb2312 gbk latin1 latin2 sjis tis620 ucs2 ujis utf8" -dnl fix this later.. -dnl [ --with-charset=CHARSET Use CHARSET by default (one of: $CHARSETS_AVAILABLE; Default is $DEFAULT_CHARSET)], +AC_DIVERT_POP AC_ARG_WITH(charset, - [ --with-charset=CHARSET Use CHARSET by default (Default is latin1)], - [default_charset="$withval"], - [default_charset="$DEFAULT_CHARSET"]) + [ --with-charset=CHARSET + Default character set, use one of: + CHARSETS_AVAILABLE1 + CHARSETS_AVAILABLE2 + CHARSETS_AVAILABLE3 + CHARSETS_AVAILABLE4 + CHARSETS_AVAILABLE5], + [default_charset="$withval"], + [default_charset="$DEFAULT_CHARSET"]) + +AC_ARG_WITH(collation, + [ --with-collation=COLLATION + Default collation], + [default_collation="$withval"], + [default_collation="default"]) + AC_ARG_WITH(extra-charsets, [ --with-extra-charsets=CHARSET[,CHARSET,...] @@ -2258,73 +2269,76 @@ AC_ARG_WITH(extra-charsets, [extra_charsets="$withval"], [extra_charsets="none"]) + AC_MSG_CHECKING("character sets") +CHARSETS="$default_charset latin1 utf8" + if test "$extra_charsets" = no; then - CHARSETS="" + CHARSETS="$CHARSETS" elif test "$extra_charsets" = none; then - CHARSETS="" + CHARSETS="$CHARSETS" elif test "$extra_charsets" = complex; then - CHARSETS="$CHARSETS_COMPLEX" + CHARSETS="$CHARSETS $CHARSETS_COMPLEX" elif test "$extra_charsets" = all; then - CHARSETS="$CHARSETS_AVAILABLE $CHARSETS_DEPRECATED" + CHARSETS="$CHARSETS $CHARSETS_AVAILABLE" else - CHARSETS=`echo $extra_charsets | sed -e 's/,/ /g'` + EXTRA_CHARSETS=`echo $extra_charsets | sed -e 's/,/ /g'` + CHARSETS="$CHARSETS $EXTRA_CHARSETS" fi -CHARSETS="$default_charset $CHARSETS" - -use_mb="no" - for cs in $CHARSETS do case $cs in armscii8) AC_DEFINE(HAVE_CHARSET_armscii8) - use_mb="yes" + ;; + ascii) + AC_DEFINE(HAVE_CHARSET_ascii) ;; big5) AC_DEFINE(HAVE_CHARSET_big5) - use_mb="yes" + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) + ;; + cp1250) + AC_DEFINE(HAVE_CHARSET_cp1250) ;; cp1251) AC_DEFINE(HAVE_CHARSET_cp1251) ;; + cp1256) + AC_DEFINE(HAVE_CHARSET_cp1256) + ;; cp1257) AC_DEFINE(HAVE_CHARSET_cp1257) ;; - croat) - AC_DEFINE(HAVE_CHARSET_croat) + cp850) + AC_DEFINE(HAVE_CHARSET_cp850) ;; - czech) - AC_DEFINE(HAVE_CHARSET_czech) + cp852) + AC_DEFINE(HAVE_CHARSET_cp852) ;; - danish) - AC_DEFINE(HAVE_CHARSET_danish) + cp866) + AC_DEFINE(HAVE_CHARSET_cp866) ;; dec8) AC_DEFINE(HAVE_CHARSET_dec8) ;; - dos) - AC_DEFINE(HAVE_CHARSET_dos) - ;; - estonia) - AC_DEFINE(HAVE_CHARSET_estonia) - ;; - euc_kr) - AC_DEFINE(HAVE_CHARSET_euc_kr) - use_mb="yes" + euckr) + AC_DEFINE(HAVE_CHARSET_euckr) + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; gb2312) AC_DEFINE(HAVE_CHARSET_gb2312) - use_mb="yes" + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; gbk) AC_DEFINE(HAVE_CHARSET_gbk) - use_mb="yes" - ;; - german1) - AC_DEFINE(HAVE_CHARSET_german1) + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; greek) AC_DEFINE(HAVE_CHARSET_greek) @@ -2335,30 +2349,37 @@ do hp8) AC_DEFINE(HAVE_CHARSET_hp8) ;; - hungarian) - AC_DEFINE(HAVE_CHARSET_hungarian) + keybcs2) + AC_DEFINE(HAVE_CHARSET_keybcs2) ;; - koi8_ru) - AC_DEFINE(HAVE_CHARSET_koi8_ru) + koi8r) + AC_DEFINE(HAVE_CHARSET_koi8r) ;; - koi8_ukr) - AC_DEFINE(HAVE_CHARSET_koi8_ukr) + koi8u) + AC_DEFINE(HAVE_CHARSET_koi8u) ;; latin1) AC_DEFINE(HAVE_CHARSET_latin1) ;; - latin1_de) - AC_DEFINE(HAVE_CHARSET_latin1_de) - ;; latin2) AC_DEFINE(HAVE_CHARSET_latin2) ;; latin5) AC_DEFINE(HAVE_CHARSET_latin5) ;; + latin7) + AC_DEFINE(HAVE_CHARSET_latin7) + ;; + macce) + AC_DEFINE(HAVE_CHARSET_macce) + ;; + macroman) + AC_DEFINE(HAVE_CHARSET_macroman) + ;; sjis) AC_DEFINE(HAVE_CHARSET_sjis) - use_mb="yes" + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; swe7) AC_DEFINE(HAVE_CHARSET_swe7) @@ -2368,55 +2389,189 @@ do ;; ucs2) AC_DEFINE(HAVE_CHARSET_ucs2) - use_mb="yes" + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; ujis) AC_DEFINE(HAVE_CHARSET_ujis) - use_mb="yes" - ;; - usa7) - AC_DEFINE(HAVE_CHARSET_usa7) + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; utf8) AC_DEFINE(HAVE_CHARSET_utf8) - use_mb="yes" + AC_DEFINE(USE_MB) + AC_DEFINE(USE_MB_IDENT) ;; - win1250) - AC_DEFINE(HAVE_CHARSET_win1250) + *) + AC_MSG_ERROR([Charset $cs not available. (Available are: $CHARSETS_AVAILABLE). + See the Installation chapter in the Reference Manual.]); + esac +done + + + default_charset_collations="" + +case $default_charset in + armscii8) + default_charset_default_collation="armscii8_general_ci" + default_charset_collations="armscii8_general_ci armscii_bin" + ;; + ascii) + default_charset_default_collation="ascii_general_ci" + default_charset_collations="ascii_general_ci ascii_bin" + ;; + big5) + default_charset_default_collation="big5_chinese_ci" + default_charset_collations="big5_chinese_ci big5_bin" ;; - win1250ch) - AC_DEFINE(HAVE_CHARSET_win1250ch) + cp1250) + default_charset_default_collation="cp1250_general_ci" + default_charset_collations="cp1250_general_ci cp1250_czech_ci cp1250_bin" ;; - win1251) - AC_DEFINE(HAVE_CHARSET_win1251) + cp1251) + default_charset_default_collation="cp1251_general_ci" + default_charset_collations="cp1251_general_ci cp1251_general_cs cp1251_bin cp1251_bulgarian_ci cp1251_ukrainian_ci" + ;; + cp1256) + default_charset_default_collation="cp1256_general_ci" + default_charset_collations="cp1256_general_ci cp1256_bin" + ;; + cp1257) + default_charset_default_collation="cp1257_general_ci" + default_charset_collations="cp1257_general_ci cp1257_lithuanian_ci cp1257_bin" + ;; + cp850) + default_charset_default_collation="cp850_general_ci" + default_charset_collations="cp850_general_ci cp850_bin" + ;; + cp852) + default_charset_default_collation="cp852_general_ci" + default_charset_collations="cp852_general_ci cp852_bin" ;; - win1251ukr) - AC_DEFINE(HAVE_CHARSET_win1251ukr) + cp866) + default_charset_default_collation="cp866_general_ci" + default_charset_collations="cp866_general_ci cp866_bin" + ;; + dec8) + default_charset_default_collation="dec8_swedish_ci" + default_charset_collations="dec8_swedish_ci dec8_bin" + ;; + euckr) + default_charset_default_collation="euckr_korean_ci" + default_charset_collations="euckr_korean_ci euckr_bin" + ;; + gb2312) + default_charset_default_collation="gb2312_chinese_ci" + default_charset_collations="gb2312_chinese_ci gb2312_bin" + ;; + gbk) + default_charset_default_collation="gbk_chinese_ci" + default_charset_collations="gbk_chinese_ci gbk_bin" + ;; + greek) + default_charset_default_collation="greek_general_ci" + default_charset_collations="greek_general_ci greek_bin" + ;; + hebrew) + default_charset_default_collation="hebrew_general_ci" + default_charset_collations="hebrew_general_ci hebrew_bin" + ;; + hp8) + default_charset_default_collation="hp8_english_ci" + default_charset_collations="hp8_english_ci hp8_bin" + ;; + keybcs2) + default_charset_default_collation="keybcs2_general_ci" + default_charset_collations="keybcs2_general_ci keybcs2_bin" + ;; + koi8r) + default_charset_default_collation="koi8r_general_ci" + default_charset_collations="koi8r_general_ci koi8r_bin" + ;; + koi8u) + default_charset_default_collation="koi8u_general_ci" + default_charset_collations="koi8u_general_ci koi8u_bin" + ;; + latin1) + default_charset_default_collation="latin1_swedish_ci" + default_charset_collations="latin1_general_ci latin1_general_cs latin1_bin latin1_german1_ci latin1_german2_ci latin1_danish_ci latin1_swedish_ci" + ;; + latin2) + default_charset_default_collation="latin2_general_ci" + default_charset_collations="latin2_general_ci latin2_bin latin2_czech_ci latin2_hungarian_ci latin2_croatian_ci" + ;; + latin5) + default_charset_default_collation="latin5_turkish_ci" + default_charset_collations="latin5_turkish_ci latin5_bin" + ;; + latin7) + default_charset_default_collation="latin7_general_ci" + default_charset_collations="latin7_general_ci latin7_general_cs latin7_bin latin7_estonian_cs" + ;; + macce) + default_charset_default_collation="macce_general_ci" + default_charset_collations="macce_general_ci macce_bin" + ;; + macroman) + default_charset_default_collation="macroman_general_ci" + default_charset_collations="macroman_general_ci macroman_bin" + ;; + sjis) + default_charset_default_collation="sjis_japanese_ci" + default_charset_collations="sjis_japanese_ci sjis_bin" + ;; + swe7) + default_charset_default_collation="swe7_swedish_ci" + default_charset_collations="swe7_swedish_ci swe7_bin" + ;; + tis620) + default_charset_default_collation="tis620_thai_ci" + default_charset_collations="tis620_thai_ci tis620_bin" + ;; + ucs2) + default_charset_default_collation="ucs2_general_ci" + default_charset_collations="ucs2_general_ci ucs2_bin" + ;; + ujis) + default_charset_default_collation="ujis_japanese_ci" + default_charset_collations="ujis_japanese_ci ujis_bin" + ;; + utf8) + default_charset_default_collation="utf8_general_ci" + default_charset_collations="utf8_general_ci utf8_bin" ;; *) - AC_MSG_ERROR([Charset $cs not available. (Available $CHARSETS_AVAILABLE). + AC_MSG_ERROR([Charset $cs not available. (Available are: $CHARSETS_AVAILABLE). See the Installation chapter in the Reference Manual.]); - esac -done +esac -dnl Always compile latin1 -AC_DEFINE(HAVE_CHARSET_latin1) +if test "$default_collation" = default; then + default_collation=$default_charset_default_collation +fi -dnl Always compile utf8 -AC_DEFINE(HAVE_CHARSET_utf8) -use_mb=yes +valid_default_collation=no +for cl in $default_charset_collations +do + if test x"$cl" = x"$default_collation" + then + valid_default_collation=yes + break + fi +done -if test "$use_mb" = "yes" +if test x$valid_default_collation = xyes then - AC_DEFINE(USE_MB) - AC_DEFINE(USE_MB_IDENT) + AC_MSG_RESULT([default: $default_charset, collation: $default_collation; compiled in: $CHARSETS]) +else + AC_MSG_ERROR([ + Collation $default_collation is not valid for character set $default_charset. + Valid collations are: $default_charset_collations. + See the Installation chapter in the Reference Manual. + ]); fi -AC_SUBST(default_charset) -AC_DEFINE_UNQUOTED(DEFAULT_CHARSET_NAME,"$default_charset") - -AC_MSG_RESULT([default: $default_charset; compiled in: $CHARSETS]) - +AC_DEFINE_UNQUOTED(MYSQL_DEFAULT_CHARSET_NAME,"$default_charset") +AC_DEFINE_UNQUOTED(MYSQL_DEFAULT_COLLATION_NAME,"$default_collation") MYSQL_CHECK_ISAM MYSQL_CHECK_BDB diff --git a/heap/hp_hash.c b/heap/hp_hash.c index e315c1bbcb8..2a946dcd7b9 100644 --- a/heap/hp_hash.c +++ b/heap/hp_hash.c @@ -215,7 +215,7 @@ ulong hp_hashnr(register HP_KEYDEF *keydef, register const byte *key) } if (seg->type == HA_KEYTYPE_TEXT) { - seg->charset->hash_sort(seg->charset,pos,((uchar*)key)-pos,&nr,&nr2); + seg->charset->coll->hash_sort(seg->charset,pos,((uchar*)key)-pos,&nr,&nr2); } else { @@ -250,7 +250,7 @@ ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const byte *rec) } if (seg->type == HA_KEYTYPE_TEXT) { - seg->charset->hash_sort(seg->charset,pos,end-pos,&nr,&nr2); + seg->charset->coll->hash_sort(seg->charset,pos,end-pos,&nr,&nr2); } else { diff --git a/include/Makefile.am b/include/Makefile.am index 7372d3ab417..3a197c310aa 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -35,7 +35,7 @@ noinst_HEADERS = config-win.h config-os2.h config-netware.h \ SUPERCLEANFILES = mysql_version.h my_config.h # Some include files that may be moved and patched by configure -DISTCLEANFILES = sched.h +DISTCLEANFILES = sched.h $(SUPERCLEANFILES) clean: $(RM) -f readline/* diff --git a/include/config-win.h b/include/config-win.h index 0e01aa75570..b0a30353196 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -153,6 +153,9 @@ typedef uint rf_SetTimer; #define USE_MB_IDENT 1 #define USE_STRCOLL 1 +/* If LOAD DATA LOCAL INFILE should be enabled by default */ +#define ENABLED_LOCAL_INFILE 1 + /* Convert some simple functions to Posix */ #define sigset(A,B) signal((A),(B)) diff --git a/include/m_ctype.h b/include/m_ctype.h index e28d5687983..f6b5a1ca44f 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -61,9 +61,10 @@ typedef struct unicase_info_st #define MY_CS_BINSORT 16 /* if binary sort order */ #define MY_CS_PRIMARY 32 /* if primary collation */ #define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */ +#define MY_CS_UNICODE 128 /* is a charset is full unicode */ +#define MY_CS_NONTEXT 256 /* if a charset is not sprintf() compatible */ #define MY_CHARSET_UNDEFINED 0 -#define MY_CHARSET_CURRENT (default_charset_info->number) typedef struct my_uni_idx_st @@ -90,27 +91,11 @@ enum my_lex_states MY_LEX_STRING_OR_DELIMITER }; +struct charset_info_st; -typedef struct charset_info_st +typedef struct my_collation_handler_st { - uint number; - uint primary_number; - uint binary_number; - uint state; - const char *csname; - const char *name; - const char *comment; - uchar *ctype; - uchar *to_lower; - uchar *to_upper; - uchar *sort_order; - uint16 *tab_to_uni; - MY_UNI_IDX *tab_from_uni; - uchar state_map[256]; - uchar ident_map[256]; - /* Collation routines */ - uint strxfrm_multiply; int (*strnncoll)(struct charset_info_st *, const uchar *, uint, const uchar *, uint); int (*strnncollsp)(struct charset_info_st *, @@ -127,9 +112,21 @@ typedef struct charset_info_st const char *str,const char *str_end, const char *wildstr,const char *wildend, int escape,int w_one, int w_many); + + int (*strcasecmp)(struct charset_info_st *, const char *, const char *); + /* Hash calculation */ + void (*hash_sort)(struct charset_info_st *cs, const uchar *key, uint len, + ulong *nr1, ulong *nr2); +} MY_COLLATION_HANDLER; + +extern MY_COLLATION_HANDLER my_collation_bin_handler; +extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler; + + +typedef struct my_charset_handler_st +{ /* Multibyte routines */ - uint mbmaxlen; int (*ismbchar)(struct charset_info_st *, const char *, const char *); int (*mbcharlen)(struct charset_info_st *, uint); uint (*numchars)(struct charset_info_st *, const char *b, const char *e); @@ -147,15 +144,6 @@ typedef struct charset_info_st void (*caseup)(struct charset_info_st *, char *, uint); void (*casedn)(struct charset_info_st *, char *, uint); - /* Functions for case comparison */ - int (*strcasecmp)(struct charset_info_st *, const char *, const char *); - - /* Hash calculation */ - void (*hash_sort)(struct charset_info_st *cs, const uchar *key, uint len, - ulong *nr1, ulong *nr2); - - char max_sort_char; /* For LIKE optimization */ - /* Charset dependant snprintf() */ int (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt, ...); @@ -180,30 +168,65 @@ typedef struct charset_info_st ulong (*scan)(struct charset_info_st *, const char *b, const char *e, int sq); +} MY_CHARSET_HANDLER; + +extern MY_CHARSET_HANDLER my_charset_8bit_handler; + + + +typedef struct charset_info_st +{ + uint number; + uint primary_number; + uint binary_number; + uint state; + const char *csname; + const char *name; + const char *comment; + uchar *ctype; + uchar *to_lower; + uchar *to_upper; + uchar *sort_order; + uint16 *tab_to_uni; + MY_UNI_IDX *tab_from_uni; + uchar state_map[256]; + uchar ident_map[256]; + uint strxfrm_multiply; + uint mbmaxlen; + char max_sort_char; /* For LIKE optimization */ + + MY_CHARSET_HANDLER *cset; + MY_COLLATION_HANDLER *coll; } CHARSET_INFO; extern CHARSET_INFO my_charset_bin; +extern CHARSET_INFO my_charset_big5_chinese_ci; +extern CHARSET_INFO my_charset_big5_bin; +extern CHARSET_INFO my_charset_euckr_korean_ci; +extern CHARSET_INFO my_charset_euckr_bin; +extern CHARSET_INFO my_charset_gb2312_chinese_ci; +extern CHARSET_INFO my_charset_gb2312_bin; +extern CHARSET_INFO my_charset_gbk_chinese_ci; +extern CHARSET_INFO my_charset_gbk_bin; extern CHARSET_INFO my_charset_latin1; -extern CHARSET_INFO my_charset_big5; -extern CHARSET_INFO my_charset_czech; -extern CHARSET_INFO my_charset_euc_kr; -extern CHARSET_INFO my_charset_gb2312; -extern CHARSET_INFO my_charset_gbk; -extern CHARSET_INFO my_charset_latin1_de; -extern CHARSET_INFO my_charset_sjis; -extern CHARSET_INFO my_charset_tis620; -extern CHARSET_INFO my_charset_ucs2; -extern CHARSET_INFO my_charset_ucse; -extern CHARSET_INFO my_charset_ujis; -extern CHARSET_INFO my_charset_utf8; -extern CHARSET_INFO my_charset_win1250ch; +extern CHARSET_INFO my_charset_latin1_german2_ci; +extern CHARSET_INFO my_charset_latin1_bin; +extern CHARSET_INFO my_charset_latin2_czech_ci; +extern CHARSET_INFO my_charset_sjis_japanese_ci; +extern CHARSET_INFO my_charset_sjis_bin; +extern CHARSET_INFO my_charset_tis620_thai_ci; +extern CHARSET_INFO my_charset_tis620_bin; +extern CHARSET_INFO my_charset_ucs2_general_ci; +extern CHARSET_INFO my_charset_ucs2_bin; +extern CHARSET_INFO my_charset_ujis_japanese_ci; +extern CHARSET_INFO my_charset_ujis_bin; +extern CHARSET_INFO my_charset_utf8_general_ci; +extern CHARSET_INFO my_charset_utf8_bin; +extern CHARSET_INFO my_charset_cp1250_czech_ci; -extern my_bool my_parse_charset_xml(const char *bug, uint len, - int (*add)(CHARSET_INFO *cs)); - /* declarations for simple charsets */ extern int my_strnxfrm_simple(CHARSET_INFO *, uchar *, uint, const uchar *, uint); @@ -244,7 +267,6 @@ ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, uint l, int base, char **e, int *err); double my_strntod_8bit(CHARSET_INFO *, char *s, uint l,char **e, int *err); - int my_long10_to_str_8bit(CHARSET_INFO *, char *to, uint l, int radix, long int val); int my_longlong10_to_str_8bit(CHARSET_INFO *, char *to, uint l, int radix, @@ -269,7 +291,6 @@ uint my_numchars_8bit(CHARSET_INFO *, const char *b, const char *e); uint my_charpos_8bit(CHARSET_INFO *, const char *b, const char *e, uint pos); -#ifdef USE_MB /* Functions for multibyte charsets */ extern void my_caseup_str_mb(CHARSET_INFO *, char *); extern void my_casedn_str_mb(CHARSET_INFO *, char *); @@ -284,7 +305,10 @@ int my_wildcmp_mb(CHARSET_INFO *, uint my_numchars_mb(CHARSET_INFO *, const char *b, const char *e); uint my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, uint pos); -#endif + +extern my_bool my_parse_charset_xml(const char *bug, uint len, + int (*add)(CHARSET_INFO *cs)); + #define _U 01 /* Upper case */ #define _L 02 /* Lower case */ @@ -319,27 +343,26 @@ uint my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, uint pos); #define my_isvar_start(s,c) (my_isalpha(s,c) || (c) == '_') #define use_strnxfrm(s) ((s)->state & MY_CS_STRNXFRM) -#define my_strnxfrm(s, a, b, c, d) ((s)->strnxfrm((s), (a), (b), (c), (d))) -#define my_strnncoll(s, a, b, c, d) ((s)->strnncoll((s), (a), (b), (c), (d))) +#define my_strnxfrm(s, a, b, c, d) ((s)->coll->strnxfrm((s), (a), (b), (c), (d))) +#define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d))) #define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \ - ((s)->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j))) -#define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m))) - -#define use_mb(s) ((s)->ismbchar != NULL) -#define my_ismbchar(s, a, b) ((s)->ismbchar((s), (a), (b))) -#define my_mbcharlen(s, a) ((s)->mbcharlen((s),(a))) - -#define my_caseup(s, a, l) ((s)->caseup((s), (a), (l))) -#define my_casedn(s, a, l) ((s)->casedn((s), (a), (l))) -#define my_caseup_str(s, a) ((s)->caseup_str((s), (a))) -#define my_casedn_str(s, a) ((s)->casedn_str((s), (a))) -#define my_strcasecmp(s, a, b) ((s)->strcasecmp((s), (a), (b))) - -#define my_strntol(s, a, b, c, d, e) ((s)->strntol((s),(a),(b),(c),(d),(e))) -#define my_strntoul(s, a, b, c, d, e) ((s)->strntoul((s),(a),(b),(c),(d),(e))) -#define my_strntoll(s, a, b, c, d, e) ((s)->strntoll((s),(a),(b),(c),(d),(e))) -#define my_strntoull(s, a, b, c,d, e) ((s)->strntoull((s),(a),(b),(c),(d),(e))) -#define my_strntod(s, a, b, c, d) ((s)->strntod((s),(a),(b),(c),(d))) + ((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j))) +#define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m))) +#define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b))) + +#define use_mb(s) ((s)->cset->ismbchar != NULL) +#define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b))) +#define my_mbcharlen(s, a) ((s)->cset->mbcharlen((s),(a))) + +#define my_caseup(s, a, l) ((s)->cset->caseup((s), (a), (l))) +#define my_casedn(s, a, l) ((s)->cset->casedn((s), (a), (l))) +#define my_caseup_str(s, a) ((s)->cset->caseup_str((s), (a))) +#define my_casedn_str(s, a) ((s)->cset->casedn_str((s), (a))) +#define my_strntol(s, a, b, c, d, e) ((s)->cset->strntol((s),(a),(b),(c),(d),(e))) +#define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e))) +#define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e))) +#define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e))) +#define my_strntod(s, a, b, c, d) ((s)->cset->strntod((s),(a),(b),(c),(d))) /* XXX: still need to take care of this one */ diff --git a/include/my_base.h b/include/my_base.h index b806436fe0e..ac41d9e50ef 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -225,6 +225,7 @@ enum ha_base_keytype { /* Errorcodes given by functions */ +/* opt_sum_query() assumes these codes are > 1 */ #define HA_ERR_KEY_NOT_FOUND 120 /* Didn't find key on read or update */ #define HA_ERR_FOUND_DUPP_KEY 121 /* Dupplicate key on write */ #define HA_ERR_RECORD_CHANGED 123 /* Uppdate with is recoverable */ diff --git a/include/my_global.h b/include/my_global.h index 510de43c9ee..86fb2a5ee4d 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -287,6 +287,10 @@ C_MODE_END #include <asm/atomic.h> #endif #include <errno.h> /* Recommended by debian */ +/* We need the following to go around a problem with openssl on solaris */ +#if defined(HAVE_CRYPT_H) +#include <crypt.h> +#endif /* Go around some bugs in different OS and compilers */ #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H) @@ -306,9 +310,7 @@ C_MODE_END /* This has to be after include limits.h */ #define HAVE_ERRNO_AS_DEFINE #define HAVE_FCNTL_LOCK -#undef HAVE_SYS_UN_H #undef HAVE_FINITE -#undef HAVE_RINT #undef LONGLONG_MIN /* These get wrongly defined in QNX 6.2 */ #undef LONGLONG_MAX /* standard system library 'limits.h' */ #endif @@ -377,7 +379,7 @@ typedef unsigned short ushort; #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1)) #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0]))) #ifndef HAVE_RINT -#define rint(A) floor((A)+0.5) +#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5)) #endif /* Define some general constants */ diff --git a/include/my_pthread.h b/include/my_pthread.h index 58f89517679..bff82ef7320 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -248,6 +248,11 @@ extern int my_sigwait(const sigset_t *set,int *sig); #error Requires at least rev 2 of EMX pthreads library. #endif +#ifdef __NETWARE__ +void my_pthread_exit(void *status); +#define pthread_exit(A) my_pthread_exit(A) +#endif + extern int my_pthread_getprio(pthread_t thread_id); #define pthread_key(T,V) pthread_key_t V diff --git a/include/my_semaphore.h b/include/my_semaphore.h index 3431212ec82..7f182bea6bf 100644 --- a/include/my_semaphore.h +++ b/include/my_semaphore.h @@ -31,6 +31,8 @@ #ifndef _my_semaphore_h_ #define _my_semaphore_h_ +#ifdef THREAD + C_MODE_START #ifdef HAVE_SEMAPHORE_H #include <semaphore.h> @@ -56,4 +58,7 @@ int sem_getvalue(sem_t * sem, unsigned int * sval); #endif /* !__bsdi__ */ C_MODE_END + +#endif /* THREAD */ + #endif /* !_my_semaphore_h_ */ diff --git a/include/my_sys.h b/include/my_sys.h index 86ca6ec6a1f..b4fc20e8471 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -216,7 +216,6 @@ extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags); extern CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint cs_flags, myf my_flags); extern void free_charsets(void); -extern char *list_charsets(myf want_flags); /* my_free() this string... */ extern char *get_charsets_dir(char *buf); extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2); @@ -744,6 +743,7 @@ extern my_bool my_uncompress(byte *, ulong *, ulong *); extern byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen); extern ulong checksum(const byte *mem, uint count); extern uint my_bit_log2(ulong value); +uint my_count_bits(ulonglong v); extern void my_sleep(ulong m_seconds); #ifdef __WIN__ diff --git a/include/mysql.h b/include/mysql.h index 0952c1c62a8..91e4c6444ee 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -83,6 +83,7 @@ typedef struct st_mysql_field { char *table; /* Table of column if column was a field */ char *org_table; /* Org table name, if table was an alias */ char *db; /* Database for table */ + char *catalog; /* Catalog for table */ char *def; /* Default value (set by mysql_list_fields) */ unsigned long length; /* Width of column */ unsigned long max_length; /* Max width of selected set */ @@ -91,6 +92,7 @@ typedef struct st_mysql_field { unsigned int table_length; unsigned int org_table_length; unsigned int db_length; + unsigned int catalog_length; unsigned int def_length; unsigned int flags; /* Div flags */ unsigned int decimals; /* Number of decimals in field */ @@ -294,6 +296,10 @@ typedef struct st_mysql_res { #define MANAGER_CLIENT_ERR 450 #define MANAGER_INTERNAL_ERR 500 +#ifndef MYSQL_SERVER +#define MYSQL_CLIENT +#endif + typedef struct st_mysql_manager @@ -346,6 +352,7 @@ my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql); my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql); unsigned int STDCALL mysql_errno(MYSQL *mysql); const char * STDCALL mysql_error(MYSQL *mysql); +const char *STDCALL mysql_sqlstate(MYSQL *mysql); unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_info(MYSQL *mysql); unsigned long STDCALL mysql_thread_id(MYSQL *mysql); @@ -494,7 +501,7 @@ enum mysql_st_timestamp_type { MYSQL_TIMESTAMP_NONE, MYSQL_TIMESTAMP_DATE, typedef struct mysql_st_time { unsigned int year,month,day,hour,minute,second; - unsigned long second_part; + unsigned long second_part; my_bool neg; enum mysql_st_timestamp_type time_type; @@ -505,16 +512,19 @@ typedef struct mysql_st_time /* bind structure */ typedef struct st_mysql_bind { - unsigned long *length; /* output length pointer */ - my_bool *is_null; /* Pointer to null indicators */ - char *buffer; /* buffer to get/put data */ + unsigned long *length; /* output length pointer */ + my_bool *is_null; /* Pointer to null indicators */ + char *buffer; /* buffer to get/put data */ enum enum_field_types buffer_type; /* buffer type */ - /* Must be set for string/blob data */ - unsigned long buffer_length; /* buffer length */ - - /* The following are for internal use. Set by mysql_bind_param */ - unsigned int param_number; /* For null count and error messages */ - my_bool long_data_used; /* If used with mysql_send_long_data */ + unsigned long buffer_length; /* buffer length, must be set for str/binary */ + + /* Following are for internal use. Set by mysql_bind_param */ + unsigned char *inter_buffer; /* for the current data position */ + unsigned long offset; /* offset position for char/binary fetch */ + unsigned int param_number; /* For null count and error messages */ + my_bool long_data_used; /* If used with mysql_send_long_data */ + my_bool binary_data; /* data buffer is binary */ + my_bool null_field; /* NULL data cache flag */ void (*store_param_func)(NET *net, struct st_mysql_bind *param); void (*fetch_result)(struct st_mysql_bind *, unsigned char **row); } MYSQL_BIND; @@ -523,25 +533,29 @@ typedef struct st_mysql_bind /* statement handler */ typedef struct st_mysql_stmt { - MYSQL *mysql; /* connection handle */ - MYSQL_BIND *params; /* input parameters */ - MYSQL_RES *result; /* resultset */ - MYSQL_BIND *bind; /* row binding */ - MYSQL_FIELD *fields; /* prepare meta info */ - LIST list; /* list to keep track of all stmts */ - char *query; /* query buffer */ - MEM_ROOT mem_root; /* root allocations */ - unsigned long param_count; /* parameters count */ - unsigned long field_count; /* fields count */ - unsigned long stmt_id; /* Id for prepared statement */ - unsigned int last_errno; /* error code */ - enum PREP_STMT_STATE state; /* statement state */ - char last_error[MYSQL_ERRMSG_SIZE]; /* error message */ - my_bool long_alloced; /* flag to indicate long alloced */ - my_bool send_types_to_server; /* Types sent to server */ - my_bool param_buffers; /* param bound buffers */ - my_bool res_buffers; /* output bound buffers */ - my_bool result_buffered; /* Results buffered */ + MYSQL *mysql; /* connection handle */ + MYSQL_BIND *params; /* input parameters */ + MYSQL_RES *result; /* resultset */ + MYSQL_BIND *bind; /* row binding */ + MYSQL_FIELD *fields; /* prepare meta info */ + LIST list; /* list to keep track of all stmts */ + unsigned char *current_row; /* unbuffered row */ + unsigned char *last_fetched_buffer; /* last fetched column buffer */ + char *query; /* query buffer */ + MEM_ROOT mem_root; /* root allocations */ + my_ulonglong last_fetched_column; /* last fetched column */ + unsigned long param_count; /* parameters count */ + unsigned long field_count; /* fields count */ + unsigned long stmt_id; /* Id for prepared statement */ + unsigned int last_errno; /* error code */ + enum PREP_STMT_STATE state; /* statement state */ + char last_error[MYSQL_ERRMSG_SIZE]; /* error message */ + char sqlstate[SQLSTATE_LENGTH+1]; + my_bool long_alloced; /* flag to indicate long alloced */ + my_bool send_types_to_server; /* Types sent to server */ + my_bool param_buffers; /* param bound buffers */ + my_bool res_buffers; /* output bound buffers */ + my_bool result_buffered; /* Results buffered */ } MYSQL_STMT; @@ -554,10 +568,14 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt); +const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt); my_bool STDCALL mysql_commit(MYSQL * mysql); my_bool STDCALL mysql_rollback(MYSQL * mysql); my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode); int STDCALL mysql_fetch(MYSQL_STMT *stmt); +int STDCALL mysql_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, + my_ulonglong column, + unsigned long offset); my_bool STDCALL mysql_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, diff --git a/include/mysql_com.h b/include/mysql_com.h index bbfb869927b..e2fa30e3a18 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -25,6 +25,7 @@ #define HOSTNAME_LENGTH 60 #define USERNAME_LENGTH 16 #define SERVER_VERSION_LENGTH 60 +#define SQLSTATE_LENGTH 6 #define LOCAL_HOST "localhost" #define LOCAL_HOST_NAMEDPIPE "." @@ -100,20 +101,22 @@ enum enum_server_command #define CLIENT_ODBC 64 /* Odbc client */ #define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */ #define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */ +#define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */ #define CLIENT_INTERACTIVE 1024 /* This is an interactive client */ -#define CLIENT_SSL 2048 /* Switch to SSL after handshake */ -#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ +#define CLIENT_SSL 2048 /* Switch to SSL after handshake */ +#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ #define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */ -#define CLIENT_PROTOCOL_41 16384 /* New 4.1 protocol */ -#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */ -#define CLIENT_MULTI_QUERIES 65536 /* Enable/disable multi query support */ +#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */ +#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */ +#define CLIENT_MULTI_QUERIES 65536 /* Enable/disable multiquery support */ +#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */ #define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ #define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */ #define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */ -#define MYSQL_ERRMSG_SIZE 200 +#define MYSQL_ERRMSG_SIZE 512 #define NET_READ_TIMEOUT 30 /* Timeout on read */ #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ @@ -149,7 +152,7 @@ typedef struct st_net { queries in cache that have not stored its results yet */ #endif - char last_error[MYSQL_ERRMSG_SIZE]; + char last_error[MYSQL_ERRMSG_SIZE], sqlstate[SQLSTATE_LENGTH+1]; unsigned int last_errno; unsigned char error; gptr query_cache_query; diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in index 793bf36e9fe..91cf3ecc074 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -20,8 +20,5 @@ #define MYSQL_CONFIG_NAME "my" /* mysqld compile time options */ -#ifndef MYSQL_CHARSET -#define MYSQL_CHARSET "@default_charset@" -#endif /* MYSQL_CHARSET */ #endif /* _CUSTOMCONFIG_ */ #endif /* _mysql_version_h */ diff --git a/include/mysqld_error.h b/include/mysqld_error.h index ae31171553d..d2fc5bbc77f 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -275,6 +275,11 @@ #define ER_ZLIB_Z_BUF_ERROR 1256 #define ER_ZLIB_Z_DATA_ERROR 1257 #define ER_CUT_VALUE_GROUP_CONCAT 1258 -#define ER_WARN_USING_OTHER_HANDLER 1259 -#define ER_CANT_AGGREGATE_COLLATIONS 1260 -#define ER_ERROR_MESSAGES 260 +#define ER_WARN_TOO_FEW_RECORDS 1259 +#define ER_WARN_TOO_MANY_RECORDS 1260 +#define ER_WARN_NULL_TO_NOTNULL 1261 +#define ER_WARN_DATA_OUT_OF_RANGE 1262 +#define ER_WARN_DATA_TRUNCATED 1263 +#define ER_WARN_USING_OTHER_HANDLER 1264 +#define ER_CANT_AGGREGATE_COLLATIONS 1265 +#define ER_ERROR_MESSAGES 266 diff --git a/include/sql_common.h b/include/sql_common.h new file mode 100644 index 00000000000..3a668a8dd41 --- /dev/null +++ b/include/sql_common.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or + (at your option) any later version. + + 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 */ + + +extern const char *unknown_sqlstate; + +#ifdef __cplusplus +extern "C" { +#endif + +ulong STDCALL net_field_length(uchar **packet); +my_ulonglong net_field_length_ll(uchar **packet); + +MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, + my_bool default_value, uint server_capabilities); +my_bool advanced_command(MYSQL *mysql, enum enum_server_command command, + const char *header, ulong header_length, + const char *arg, ulong arg_length, my_bool skip_check); +void free_rows(MYSQL_DATA *cur); +MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields, + uint field_count); +my_bool mysql_autenticate(MYSQL *mysql, const char *passwd); +void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count); +void free_old_query(MYSQL *mysql); +void end_server(MYSQL *mysql); +my_bool mysql_reconnect(MYSQL *mysql); +#ifdef __cplusplus +} +#endif + +#ifdef MYSQL_SERVER +#define protocol_41(A) FALSE +#else +#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41) +#endif + diff --git a/include/violite.h b/include/violite.h index a5c063700b4..3b61fbf344e 100644 --- a/include/violite.h +++ b/include/violite.h @@ -165,7 +165,7 @@ my_bool vio_ssl_should_retry(Vio* vio); int vio_ssl_close(Vio* vio); /* Return last error number */ int vio_ssl_errno(Vio *vio); -my_bool vio_ssl_peer_addr(Vio* vio, char *buf); +my_bool vio_ssl_peer_addr(Vio* vio, char *buf, uint16 *port); void vio_ssl_in_addr(Vio *vio, struct in_addr *in); int vio_ssl_blocking(Vio * vio, my_bool set_blocking_mode, my_bool *old_mode); @@ -242,7 +242,7 @@ struct st_vio my_bool (*is_blocking)(Vio*); int (*viokeepalive)(Vio*, my_bool); int (*fastsend)(Vio*); - my_bool (*peer_addr)(Vio*, gptr, uint16*); + my_bool (*peer_addr)(Vio*, char *, uint16*); void (*in_addr)(Vio*, struct in_addr*); my_bool (*should_retry)(Vio*); int (*vioclose)(Vio*); diff --git a/innobase/btr/Makefile.am b/innobase/btr/Makefile.am index 6e3dd4fb007..ed61facb695 100644 --- a/innobase/btr/Makefile.am +++ b/innobase/btr/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libbtr.a +noinst_LIBRARIES = libbtr.a libbtr_a_SOURCES = btr0btr.c btr0cur.c btr0pcur.c btr0sea.c diff --git a/innobase/buf/Makefile.am b/innobase/buf/Makefile.am index b1463c2220e..3f56c8b02d7 100644 --- a/innobase/buf/Makefile.am +++ b/innobase/buf/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libbuf.a +noinst_LIBRARIES = libbuf.a libbuf_a_SOURCES = buf0buf.c buf0flu.c buf0lru.c buf0rea.c diff --git a/innobase/buf/buf0buf.c b/innobase/buf/buf0buf.c index 14d538a14bc..1cdddaf6cb4 100644 --- a/innobase/buf/buf0buf.c +++ b/innobase/buf/buf0buf.c @@ -597,8 +597,9 @@ buf_pool_init( /* Wipe contents of frame to eliminate a Purify warning */ +#ifdef HAVE_purify memset(block->frame, '\0', UNIV_PAGE_SIZE); - +#endif if (srv_use_awe) { /* Add to the list of blocks mapped to frames */ @@ -1837,7 +1838,7 @@ buf_pool_invalidate(void) freed = TRUE; while (freed) { - freed = buf_LRU_search_and_free_block(0); + freed = buf_LRU_search_and_free_block(100); } mutex_enter(&(buf_pool->mutex)); @@ -2057,6 +2058,29 @@ buf_get_n_pending_ios(void) } /************************************************************************* +Returns the ratio in percents of modified pages in the buffer pool / +database pages in the buffer pool. */ + +ulint +buf_get_modified_ratio_pct(void) +/*============================*/ +{ + ulint ratio; + + mutex_enter(&(buf_pool->mutex)); + + ratio = (100 * UT_LIST_GET_LEN(buf_pool->flush_list)) + / (1 + UT_LIST_GET_LEN(buf_pool->LRU) + + UT_LIST_GET_LEN(buf_pool->free)); + + /* 1 + is there to avoid division by zero */ + + mutex_exit(&(buf_pool->mutex)); + + return(ratio); +} + +/************************************************************************* Prints info of the buffer i/o. */ void @@ -2109,8 +2133,10 @@ buf_print_io( buf += sprintf(buf, "Pending writes: LRU %lu, flush list %lu, single page %lu\n", - buf_pool->n_flush[BUF_FLUSH_LRU], - buf_pool->n_flush[BUF_FLUSH_LIST], + buf_pool->n_flush[BUF_FLUSH_LRU] + + buf_pool->init_flush[BUF_FLUSH_LRU], + buf_pool->n_flush[BUF_FLUSH_LIST] + + buf_pool->init_flush[BUF_FLUSH_LIST], buf_pool->n_flush[BUF_FLUSH_SINGLE_PAGE]); current_time = time(NULL); @@ -2144,7 +2170,7 @@ buf_print_io( / (buf_pool->n_page_gets - buf_pool->n_page_gets_old))); } else { buf += sprintf(buf, - "No buffer pool activity since the last printout\n"); + "No buffer pool page gets since the last printout\n"); } buf_pool->n_page_gets_old = buf_pool->n_page_gets; diff --git a/innobase/buf/buf0flu.c b/innobase/buf/buf0flu.c index 02587487a92..47ac9c6b041 100644 --- a/innobase/buf/buf0flu.c +++ b/innobase/buf/buf0flu.c @@ -107,7 +107,7 @@ buf_flush_ready_for_replace( BUF_BLOCK_FILE_PAGE and in the LRU list */ { ut_ad(mutex_own(&(buf_pool->mutex))); - ut_ad(block->state == BUF_BLOCK_FILE_PAGE); + ut_a(block->state == BUF_BLOCK_FILE_PAGE); if ((ut_dulint_cmp(block->oldest_modification, ut_dulint_zero) > 0) || (block->buf_fix_count != 0) @@ -227,7 +227,9 @@ buf_flush_buffered_writes(void) } for (i = 0; i < trx_doublewrite->first_free; i++) { + block = trx_doublewrite->buf_block_arr[i]; + ut_a(block->state == BUF_BLOCK_FILE_PAGE); if (block->check_index_page_at_flush && !page_simple_validate(block->frame)) { @@ -236,10 +238,12 @@ buf_flush_buffered_writes(void) ut_print_timestamp(stderr); fprintf(stderr, - " InnoDB: Apparent corruption of an index page\n" + " InnoDB: Apparent corruption of an index page n:o %lu in space %lu\n" "InnoDB: to be written to data file. We intentionally crash server\n" "InnoDB: to prevent corrupt data from ending up in data\n" - "InnoDB: files.\n"); + "InnoDB: files.\n", + block->offset, block->space); + ut_a(0); } } @@ -394,7 +398,7 @@ buf_flush_write_block_low( "Warning: cannot force log to disk in the log debug version!\n"); #else /* Force the log to the disk before writing the modified block */ - log_flush_up_to(block->newest_modification, LOG_WAIT_ALL_GROUPS); + log_write_up_to(block->newest_modification, LOG_WAIT_ALL_GROUPS, TRUE); #endif buf_flush_init_for_writing(block->frame, block->newest_modification, block->space, block->offset); @@ -432,6 +436,8 @@ buf_flush_try_page( block = buf_page_hash_get(space, offset); + ut_a(block->state == BUF_BLOCK_FILE_PAGE); + if (flush_type == BUF_FLUSH_LIST && block && buf_flush_ready_for_flush(block, flush_type)) { @@ -567,7 +573,8 @@ buf_flush_try_page( rw_lock_s_lock_gen(&(block->lock), BUF_IO_WRITE); if (buf_debug_prints) { - printf("Flushing single page space %lu, page no %lu \n", + printf( + "Flushing single page space %lu, page no %lu \n", block->space, block->offset); } @@ -608,15 +615,7 @@ buf_flush_try_neighbors( low = offset; high = offset + 1; - } else if (flush_type == BUF_FLUSH_LIST) { - /* Since semaphore waits require us to flush the - doublewrite buffer to disk, it is best that the - search area is just the page itself, to minimize - chances for semaphore waits */ - - low = offset; - high = offset + 1; - } + } /* printf("Flush area: low %lu high %lu\n", low, high); */ @@ -633,13 +632,20 @@ buf_flush_try_neighbors( if (block && flush_type == BUF_FLUSH_LRU && i != offset && !block->old) { - /* We avoid flushing 'non-old' blocks in an LRU flush, - because the flushed blocks are soon freed */ + /* We avoid flushing 'non-old' blocks in an LRU flush, + because the flushed blocks are soon freed */ - continue; + continue; } - if (block && buf_flush_ready_for_flush(block, flush_type)) { + if (block && buf_flush_ready_for_flush(block, flush_type) + && (i == offset || block->buf_fix_count == 0)) { + /* We only try to flush those neighbors != offset + where the buf fix count is zero, as we then know that + we probably can latch the page without a semaphore + wait. Semaphore waits are expensive because we must + flush the doublewrite buffer before we start + waiting. */ mutex_exit(&(buf_pool->mutex)); @@ -758,7 +764,6 @@ buf_flush_batch( page_count += buf_flush_try_neighbors(space, offset, flush_type); - /* printf( "Flush type %lu, page no %lu, neighb %lu\n", flush_type, offset, @@ -884,11 +889,19 @@ buf_flush_free_margin(void) /*=======================*/ { ulint n_to_flush; + ulint n_flushed; n_to_flush = buf_flush_LRU_recommendation(); if (n_to_flush > 0) { - buf_flush_batch(BUF_FLUSH_LRU, n_to_flush, ut_dulint_zero); + n_flushed = buf_flush_batch(BUF_FLUSH_LRU, n_to_flush, + ut_dulint_zero); + if (n_flushed == ULINT_UNDEFINED) { + /* There was an LRU type flush batch already running; + let us wait for it to end */ + + buf_flush_wait_batch_end(BUF_FLUSH_LRU); + } } } diff --git a/innobase/buf/buf0lru.c b/innobase/buf/buf0lru.c index 051aa0191f6..40f49f1fddc 100644 --- a/innobase/buf/buf0lru.c +++ b/innobase/buf/buf0lru.c @@ -104,12 +104,15 @@ ibool buf_LRU_search_and_free_block( /*==========================*/ /* out: TRUE if freed */ - ulint n_iterations __attribute__((unused))) /* in: how many times - this has been called repeatedly without - result: a high value means that we should - search farther */ + ulint n_iterations) /* in: how many times this has been called + repeatedly without result: a high value means + that we should search farther; if value is + k < 10, then we only search k/10 * [number + of pages in the buffer pool] from the end + of the LRU list */ { buf_block_t* block; + ulint distance = 0; ibool freed; mutex_enter(&(buf_pool->mutex)); @@ -152,6 +155,18 @@ buf_LRU_search_and_free_block( } block = UT_LIST_GET_PREV(LRU, block); + distance++; + + if (!freed && n_iterations <= 10 + && distance > 100 + (n_iterations * buf_pool->curr_size) + / 10) { + + buf_pool->LRU_flush_ended = 0; + + mutex_exit(&(buf_pool->mutex)); + + return(FALSE); + } } if (buf_pool->LRU_flush_ended > 0) { @@ -186,7 +201,7 @@ buf_LRU_try_free_flushed_blocks(void) mutex_exit(&(buf_pool->mutex)); - buf_LRU_search_and_free_block(0); + buf_LRU_search_and_free_block(1); mutex_enter(&(buf_pool->mutex)); } @@ -208,7 +223,7 @@ buf_LRU_get_free_block(void) { buf_block_t* block = NULL; ibool freed; - ulint n_iterations = 0; + ulint n_iterations = 1; ibool mon_value_was = 0; /* remove bug */ ibool started_monitor = FALSE; loop: @@ -236,9 +251,12 @@ loop: fprintf(stderr, " InnoDB: WARNING: over 4 / 5 of the buffer pool is occupied by\n" "InnoDB: lock heaps or the adaptive hash index! Check that your\n" -"InnoDB: transactions do not set too many row locks. Starting InnoDB\n" -"InnoDB: Monitor to print diagnostics, including lock heap and hash index\n" -"InnoDB: sizes.\n"); +"InnoDB: transactions do not set too many row locks.\n" +"InnoDB: Your buffer pool size is %lu MB. Maybe you should make\n" +"InnoDB: the buffer pool bigger?\n" +"InnoDB: Starting the InnoDB Monitor to print diagnostics, including\n" +"InnoDB: lock heap and hash index sizes.\n", + buf_pool->curr_size / (1024 * 1024 / UNIV_PAGE_SIZE)); srv_print_innodb_monitor = TRUE; @@ -251,14 +269,6 @@ loop: srv_print_innodb_monitor = FALSE; } - - if (buf_pool->LRU_flush_ended > 0) { - mutex_exit(&(buf_pool->mutex)); - - buf_LRU_try_free_flushed_blocks(); - - mutex_enter(&(buf_pool->mutex)); - } /* If there is a block in the free list, take it */ if (UT_LIST_GET_LEN(buf_pool->free) > 0) { @@ -340,6 +350,20 @@ loop: os_aio_simulated_wake_handler_threads(); + mutex_enter(&(buf_pool->mutex)); + + if (buf_pool->LRU_flush_ended > 0) { + /* We have written pages in an LRU flush. To make the insert + buffer more efficient, we try to move these pages to the free + list. */ + + mutex_exit(&(buf_pool->mutex)); + + buf_LRU_try_free_flushed_blocks(); + } else { + mutex_exit(&(buf_pool->mutex)); + } + if (n_iterations > 10) { os_thread_sleep(500000); diff --git a/innobase/com/Makefile.am b/innobase/com/Makefile.am index 27ae396bc6e..a3d2f8a76c6 100644 --- a/innobase/com/Makefile.am +++ b/innobase/com/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libcom.a +noinst_LIBRARIES = libcom.a libcom_a_SOURCES = com0com.c com0shm.c diff --git a/innobase/data/Makefile.am b/innobase/data/Makefile.am index 0e502708e85..eeb6f129de0 100644 --- a/innobase/data/Makefile.am +++ b/innobase/data/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libdata.a +noinst_LIBRARIES = libdata.a libdata_a_SOURCES = data0data.c data0type.c diff --git a/innobase/dict/Makefile.am b/innobase/dict/Makefile.am index 693048b6784..0034d2f8f1e 100644 --- a/innobase/dict/Makefile.am +++ b/innobase/dict/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libdict.a +noinst_LIBRARIES = libdict.a libdict_a_SOURCES = dict0boot.c dict0crea.c dict0dict.c dict0load.c\ dict0mem.c diff --git a/innobase/dict/dict0crea.c b/innobase/dict/dict0crea.c index b0f84e5663a..3619ac02f4d 100644 --- a/innobase/dict/dict0crea.c +++ b/innobase/dict/dict0crea.c @@ -1173,6 +1173,7 @@ dict_create_add_foreigns_to_dictionary( if (NULL == dict_table_get_low((char *) "SYS_FOREIGN")) { fprintf(stderr, "InnoDB: table SYS_FOREIGN not found from internal data dictionary\n"); + return(DB_ERROR); } @@ -1259,6 +1260,13 @@ loop: "InnoDB: at http://www.innodb.com/ibman.html\n"); } + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Internal error in foreign key constraint creation for table %.500s.\n" +"See the MySQL .err log in the datadir for more information.\n", table->name); + mutex_exit(&dict_foreign_err_mutex); + return(error); } diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index 9be10fe70d8..c11a5f76d94 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -185,6 +185,14 @@ dict_foreign_free( /*==============*/ dict_foreign_t* foreign); /* in, own: foreign key struct */ +/* Buffers for storing detailed information about the latest foreign key +and unique key errors */ +char* dict_foreign_err_buf = NULL; +char* dict_unique_err_buf = NULL; +mutex_t dict_foreign_err_mutex; /* mutex protecting the foreign + and unique error buffers */ + + /************************************************************************ Checks if the database name in two table names is the same. */ static @@ -573,6 +581,13 @@ dict_init(void) rw_lock_create(&dict_operation_lock); rw_lock_set_level(&dict_operation_lock, SYNC_DICT_OPERATION); + + dict_foreign_err_buf = mem_alloc(DICT_FOREIGN_ERR_BUF_LEN); + dict_foreign_err_buf[0] = '\0'; + dict_unique_err_buf = mem_alloc(DICT_FOREIGN_ERR_BUF_LEN); + dict_unique_err_buf[0] = '\0'; + mutex_create(&dict_foreign_err_mutex); + mutex_set_level(&dict_foreign_err_mutex, SYNC_ANY_LATCH); } /************************************************************************** @@ -1818,6 +1833,7 @@ dict_foreign_add_to_cache( dict_foreign_t* for_in_cache = NULL; dict_index_t* index; ibool added_to_referenced_list = FALSE; + char* buf = dict_foreign_err_buf; ut_ad(mutex_own(&(dict_sys->mutex))); @@ -1850,9 +1866,29 @@ dict_foreign_add_to_cache( for_in_cache->foreign_index); if (index == NULL) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s:\n" +"there is no index in referenced table which would contain\n" +"the columns as the first columns, or the data types in the\n" +"referenced table do not match to the ones in table. Constraint:\n", + for_in_cache->foreign_table_name); + dict_print_info_on_foreign_key_in_create_format( + for_in_cache, buf + strlen(buf)); + if (for_in_cache->foreign_index) { + sprintf(buf + strlen(buf), +"\nThe index in the foreign key in table is %.500s\n" +"See http://www.innodb.com/ibman.html about correct foreign key definition.\n", + for_in_cache->foreign_index->name); + } + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + if (for_in_cache == foreign) { mem_heap_free(foreign->heap); } + return(DB_CANNOT_ADD_CONSTRAINT); } @@ -1871,6 +1907,25 @@ dict_foreign_add_to_cache( for_in_cache->referenced_index); if (index == NULL) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s:\n" +"there is no index in the table which would contain\n" +"the columns as the first columns, or the data types in the\n" +"table do not match to the ones in the referenced table. Constraint:\n", + for_in_cache->foreign_table_name); + dict_print_info_on_foreign_key_in_create_format( + for_in_cache, buf + strlen(buf)); + if (for_in_cache->foreign_index) { + sprintf(buf + strlen(buf), +"\nIndex of the foreign key in the referenced table is %.500s\n" +"See http://www.innodb.com/ibman.html about correct foreign key definition.\n", + for_in_cache->referenced_index->name); + } + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + if (for_in_cache == foreign) { if (added_to_referenced_list) { UT_LIST_REMOVE(referenced_list, @@ -2038,7 +2093,7 @@ dict_scan_col( if (*ptr == '`') { ptr++; } - + return(ptr); } @@ -2141,18 +2196,21 @@ dict_scan_table_name( } /************************************************************************* -Skips one 'word', like an id. For the lexical definition of 'word', see the -code below. */ +Scans an id. For the lexical definition of an 'id', see the code below. +Strips backquotes from around the id. */ static char* -dict_skip_word( -/*===========*/ +dict_scan_id( +/*=========*/ /* out: scanned to */ char* ptr, /* in: scanned to */ - ibool* success)/* out: TRUE if success, FALSE if just spaces left in - string */ + char** start, /* out: start of the id; NULL if no id was + scannable */ + ulint* len) /* out: length of the id */ { - *success = FALSE; + ibool scanned_backquote = FALSE; + + *start = NULL; while (isspace(*ptr)) { ptr++; @@ -2164,24 +2222,61 @@ dict_skip_word( } if (*ptr == '`') { + scanned_backquote = TRUE; ptr++; } - while (!isspace(*ptr) && *ptr != ',' && *ptr != '(' && *ptr != '`' - && *ptr != '\0') { + *start = ptr; + + while (!isspace(*ptr) && *ptr != ',' && *ptr != '(' && *ptr != ')' + && *ptr != '\0' && *ptr != '`') { ptr++; } - *success = TRUE; + *len = (ulint) (ptr - *start); + + if (scanned_backquote) { + if (*ptr == '`') { + ptr++; + } else { + /* Syntax error */ + *start = NULL; + } + } return(ptr); } /************************************************************************* +Skips one id. */ +static +char* +dict_skip_word( +/*===========*/ + /* out: scanned to */ + char* ptr, /* in: scanned to */ + ibool* success)/* out: TRUE if success, FALSE if just spaces left in + string or a syntax error */ +{ + char* start; + ulint len; + + *success = FALSE; + + ptr = dict_scan_id(ptr, &start, &len); + + if (start) { + *success = TRUE; + } + + return(ptr); +} + +#ifdef currentlynotused +/************************************************************************* Returns the number of opening brackets '(' subtracted by the number of closing brackets ')' between string and ptr. */ -#ifdef NOT_USED static int dict_bracket_count( @@ -2206,16 +2301,116 @@ dict_bracket_count( return(count); } #endif + +/************************************************************************* +Removes MySQL comments from an SQL string. A comment is either +(a) '#' to the end of the line, +(b) '--<space>' to the end of the line, or +(c) '<slash><asterisk>' till the next '<asterisk><slash>' (like the familiar +C comment syntax). */ +static +char* +dict_strip_comments( +/*================*/ + /* out, own: SQL string stripped from + comments; the caller must free this + with mem_free()! */ + char* sql_string) /* in: SQL string */ +{ + char* str; + char* sptr; + char* ptr; + + str = mem_alloc(strlen(sql_string) + 1); + + sptr = sql_string; + ptr = str; + + for (;;) { + if (*sptr == '\0') { + *ptr = '\0'; + + return(str); + } + + if (*sptr == '#' + || (strlen(sptr) >= 3 && 0 == memcmp("-- ", sptr, 3))) { + for (;;) { + /* In Unix a newline is 0x0D while in Windows + it is 0x0A followed by 0x0D */ + + if (*sptr == (char)0x0A + || *sptr == (char)0x0D + || *sptr == '\0') { + + break; + } + + sptr++; + } + } + + if (strlen(sptr) >= 2 && *sptr == '/' && *(sptr + 1) == '*') { + for (;;) { + if (strlen(sptr) >= 2 + && *sptr == '*' && *(sptr + 1) == '/') { + + sptr += 2; + + break; + } + + if (*sptr == '\0') { + + break; + } + + sptr++; + } + } + + *ptr = *sptr; + + ptr++; + sptr++; + } +} + +/************************************************************************* +Reports a simple foreign key create clause syntax error. */ +static +void +dict_foreign_report_syntax_err( +/*===========================*/ + char* name, /* in: table name */ + char* start_of_latest_foreign,/* in: start of the foreign key clause + in the SQL string */ + char* ptr) /* in: place of the syntax error */ +{ + char* buf = dict_foreign_err_buf; + + mutex_enter(&dict_foreign_err_mutex); + + ut_sprintf_timestamp(buf); + + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s,\n%.500s.\n" +"Syntax error close to:\n%.500s\n", name, start_of_latest_foreign, ptr); + + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); +} + /************************************************************************* Scans a table create SQL string and adds to the data dictionary the foreign key constraints declared in the string. This function should be called after the indexes for a table have been created. Each foreign key constraint must be accompanied with indexes in both participating tables. The indexes are allowed to contain more fields than mentioned in the constraint. */ - +static ulint -dict_create_foreign_constraints( -/*============================*/ +dict_create_foreign_constraints_low( +/*================================*/ /* out: error code or DB_SUCCESS */ trx_t* trx, /* in: transaction */ char* sql_string, /* in: table create or ALTER TABLE @@ -2231,7 +2426,9 @@ dict_create_foreign_constraints( dict_table_t* referenced_table; dict_index_t* index; dict_foreign_t* foreign; - char* ptr = sql_string; + char* ptr = sql_string; + char* start_of_latest_foreign = sql_string; + char* buf = dict_foreign_err_buf; ibool success; ulint error; ulint i; @@ -2249,6 +2446,15 @@ dict_create_foreign_constraints( table = dict_table_get_low(name); if (table == NULL) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s.\n" +"Cannot find the table from the internal data dictionary of InnoDB.\n" +"Create table statement:\n%.2000\n", name, sql_string); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_ERROR); } loop: @@ -2264,6 +2470,8 @@ loop: return(error); } + start_of_latest_foreign = ptr; + ptr = dict_accept(ptr, (char *) "FOREIGN", &success); if (!isspace(*ptr)) { @@ -2284,13 +2492,19 @@ loop: ptr = dict_skip_word(ptr, &success); if (!success) { + dict_foreign_report_syntax_err(name, + start_of_latest_foreign, ptr); + return(DB_CANNOT_ADD_CONSTRAINT); } ptr = dict_accept(ptr, (char *) "(", &success); if (!success) { - return(DB_CANNOT_ADD_CONSTRAINT); + /* We do not flag a syntax error here because in an + ALTER TABLE we may also have DROP FOREIGN KEY abc */ + + goto loop; } } @@ -2301,6 +2515,15 @@ col_loop1: ptr = dict_scan_col(ptr, &success, table, columns + i, column_names + i, column_name_lens + i); if (!success) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s,\n%.500s.\n" +"Cannot resolve column name close to:\n%.500s\n", name, + start_of_latest_foreign, ptr); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2315,6 +2538,8 @@ col_loop1: ptr = dict_accept(ptr, (char *) ")", &success); if (!success) { + dict_foreign_report_syntax_err(name, start_of_latest_foreign, + ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2324,12 +2549,24 @@ col_loop1: index = dict_foreign_find_index(table, column_names, i, NULL); if (!index) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s:\n" +"There is no index in the table %.500s where the columns appear\n" +"as the first columns. Constraint:\n%.500s\n" +"See http://www.innodb.com/ibman.html for correct foreign key definition.\n", + name, name, start_of_latest_foreign); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } - ptr = dict_accept(ptr, (char *) "REFERENCES", &success); if (!success || !isspace(*ptr)) { + dict_foreign_report_syntax_err(name, start_of_latest_foreign, + ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2359,6 +2596,15 @@ col_loop1: if (!success || (!referenced_table && trx->check_foreigns)) { dict_foreign_free(foreign); + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s,\n%.500s.\n" +"Cannot resolve table name close to:\n" +"%.500s\n", name, start_of_latest_foreign, ptr); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2366,7 +2612,8 @@ col_loop1: if (!success) { dict_foreign_free(foreign); - + dict_foreign_report_syntax_err(name, start_of_latest_foreign, + ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2381,6 +2628,15 @@ col_loop2: if (!success) { dict_foreign_free(foreign); + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s,\n%.500s\n" +"Cannot resolve column name close to:\n" +"%.500s\n", name, start_of_latest_foreign, ptr); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2395,6 +2651,8 @@ col_loop2: if (!success || foreign->n_fields != i) { dict_foreign_free(foreign); + dict_foreign_report_syntax_err(name, start_of_latest_foreign, + ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2417,9 +2675,10 @@ scan_on_conditions: ptr = dict_accept(ptr, "UPDATE", &success); if (!success) { - dict_foreign_free(foreign); + dict_foreign_report_syntax_err(name, + start_of_latest_foreign, ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2455,6 +2714,8 @@ scan_on_conditions: if (!success) { dict_foreign_free(foreign); + dict_foreign_report_syntax_err(name, + start_of_latest_foreign, ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2472,7 +2733,8 @@ scan_on_conditions: if (!success) { dict_foreign_free(foreign); - + dict_foreign_report_syntax_err(name, start_of_latest_foreign, + ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2480,7 +2742,8 @@ scan_on_conditions: if (!success) { dict_foreign_free(foreign); - + dict_foreign_report_syntax_err(name, start_of_latest_foreign, + ptr); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2494,6 +2757,15 @@ scan_on_conditions: dict_foreign_free(foreign); + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s,\n%.500s.\n" +"You have defined a SET NULL condition though some of the\n" +"columns is defined as NOT NULL.\n", name, start_of_latest_foreign); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } } @@ -2512,6 +2784,15 @@ try_find_index: dict_foreign_free(foreign); + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s,\n%.500s.\n" +"You have twice an ON DELETE clause or twice an ON UPDATE clause.\n", + name, start_of_latest_foreign); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } @@ -2525,6 +2806,18 @@ try_find_index: foreign->foreign_index); if (!index) { dict_foreign_free(foreign); + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in foreign key constraint of table %.500s:\n" +"Cannot find an index in the referenced table where the\n" +"referenced columns appear as the first columns, or column types\n" +"in the table and the referenced table do not match for constraint:\n%.500s\n" +"See http://www.innodb.com/ibman.html for correct foreign key definition.\n", + name, start_of_latest_foreign); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_CANNOT_ADD_CONSTRAINT); } } else { @@ -2565,6 +2858,165 @@ try_find_index: goto loop; } +/************************************************************************* +Scans a table create SQL string and adds to the data dictionary the foreign +key constraints declared in the string. This function should be called after +the indexes for a table have been created. Each foreign key constraint must +be accompanied with indexes in both participating tables. The indexes are +allowed to contain more fields than mentioned in the constraint. */ + +ulint +dict_create_foreign_constraints( +/*============================*/ + /* out: error code or DB_SUCCESS */ + trx_t* trx, /* in: transaction */ + char* sql_string, /* in: table create or ALTER TABLE + statement where foreign keys are declared like: + FOREIGN KEY (a, b) REFERENCES table2(c, d), + table2 can be written also with the database + name before it: test.table2; the default + database id the database of parameter name */ + char* name) /* in: table full name in the normalized form + database_name/table_name */ +{ + char* str; + ulint err; + + str = dict_strip_comments(sql_string); + + err = dict_create_foreign_constraints_low(trx, str, name); + + mem_free(str); + + return(err); +} + +/************************************************************************** +Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. */ + +ulint +dict_foreign_parse_drop_constraints( +/*================================*/ + /* out: DB_SUCCESS or + DB_CANNOT_DROP_CONSTRAINT if + syntax error or the constraint + id does not match */ + mem_heap_t* heap, /* in: heap from which we can + allocate memory */ + trx_t* trx, /* in: transaction */ + dict_table_t* table, /* in: table */ + ulint* n, /* out: number of constraints + to drop */ + char*** constraints_to_drop) /* out: id's of the + constraints to drop */ +{ + dict_foreign_t* foreign; + ibool success; + char* str; + char* ptr; + char* buf = dict_foreign_err_buf; + char* start; + char* id; + ulint len; + + *n = 0; + + *constraints_to_drop = mem_heap_alloc(heap, 1000 * sizeof(char*)); + + str = dict_strip_comments(*(trx->mysql_query_str)); + ptr = str; + + ut_ad(mutex_own(&(dict_sys->mutex))); +loop: + ptr = dict_scan_to(ptr, (char *) "DROP"); + + if (*ptr == '\0') { + ut_a(*n < 1000); + + mem_free(str); + + return(DB_SUCCESS); + } + + ptr = dict_accept(ptr, (char *) "DROP", &success); + + if (!isspace(*ptr)) { + + goto loop; + } + + ptr = dict_accept(ptr, (char *) "FOREIGN", &success); + + if (!success) { + + goto loop; + } + + ptr = dict_accept(ptr, (char *) "KEY", &success); + + if (!success) { + + goto syntax_error; + } + + ptr = dict_scan_id(ptr, &start, &len); + + if (start == NULL) { + + goto syntax_error; + } + + id = mem_heap_alloc(heap, len + 1); + ut_memcpy(id, start, len); + id[len] = '\0'; + (*constraints_to_drop)[*n] = id; + (*n)++; + + /* Look for the given constraint id */ + + foreign = UT_LIST_GET_FIRST(table->foreign_list); + + while (foreign != NULL) { + if (0 == ut_strcmp(foreign->id, id)) { + + /* Found */ + break; + } + + foreign = UT_LIST_GET_NEXT(foreign_list, foreign); + } + + if (foreign == NULL) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Error in dropping of a foreign key constraint of table %.500s,\n" +"just before:\n%s\n in SQL command\n%s\nCannot find a constraint with the\n" +"given id %s.\n", table->name, ptr, str, id); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + + mem_free(str); + + return(DB_CANNOT_DROP_CONSTRAINT); + } + + goto loop; + +syntax_error: + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), +" Syntax error in dropping of a foreign key constraint of table %.500s,\n" +"close to:\n%s\n in SQL command\n%s\n", table->name, ptr, str); + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + + mem_free(str); + + return(DB_CANNOT_DROP_CONSTRAINT); +} + /*==================== END OF FOREIGN KEY PROCESSING ====================*/ /************************************************************************** @@ -3286,7 +3738,6 @@ dict_index_print_low( n_vals = index->stat_n_diff_key_vals[1]; } - printf( " INDEX: name %s, table name %s, id %lu %lu, fields %lu/%lu, type %lu\n", index->name, index->table_name, @@ -3328,6 +3779,99 @@ dict_field_print_low( } /************************************************************************** +Sprintfs to a string info on a foreign key of a table in a format suitable +for CREATE TABLE. */ + +char* +dict_print_info_on_foreign_key_in_create_format( +/*============================================*/ + /* out: how far in buf we printed */ + dict_foreign_t* foreign,/* in: foreign key constraint */ + char* buf) /* in: buffer of at least 5000 bytes */ +{ + char* buf2 = buf; + ulint i; + + buf2 += sprintf(buf2, ",\n CONSTRAINT `%s` FOREIGN KEY (", + foreign->id); + for (i = 0; i < foreign->n_fields; i++) { + if ((ulint)(buf2 - buf) >= 4000) { + + goto no_space; + } + buf2 += sprintf(buf2, "`%.250s`", + foreign->foreign_col_names[i]); + + if (i + 1 < foreign->n_fields) { + buf2 += sprintf(buf2, ", "); + } + } + + if (dict_tables_have_same_db(foreign->foreign_table_name, + foreign->referenced_table_name)) { + /* Do not print the database name of the referenced + table */ + buf2 += sprintf(buf2, ") REFERENCES `%.500s` (", + dict_remove_db_name( + foreign->referenced_table_name)); + } else { + buf2 += sprintf(buf2, ") REFERENCES `%.500s` (", + foreign->referenced_table_name); + /* Change the '/' in the table name to '.' */ + + for (i = ut_strlen(buf); i > 0; i--) { + if (buf[i] == '/') { + + buf[i] = '.'; + + break; + } + } + } + + for (i = 0; i < foreign->n_fields; i++) { + if ((ulint)(buf2 - buf) >= 4000) { + + goto no_space; + } + buf2 += sprintf(buf2, "`%.250s`", + foreign->referenced_col_names[i]); + if (i + 1 < foreign->n_fields) { + buf2 += sprintf(buf2, ", "); + } + } + + buf2 += sprintf(buf2, ")"); + + if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) { + buf2 += sprintf(buf2, " ON DELETE CASCADE"); + } + + if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) { + buf2 += sprintf(buf2, " ON DELETE SET NULL"); + } + + if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) { + buf2 += sprintf(buf2, " ON DELETE NO ACTION"); + } + + if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) { + buf2 += sprintf(buf2, " ON UPDATE CASCADE"); + } + + if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) { + buf2 += sprintf(buf2, " ON UPDATE SET NULL"); + } + + if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) { + buf2 += sprintf(buf2, " ON UPDATE NO ACTION"); + } + +no_space: + return(buf2); +} + +/************************************************************************** Sprintfs to a string info on foreign keys of a table in a format suitable for CREATE TABLE. */ static @@ -3336,13 +3880,12 @@ dict_print_info_on_foreign_keys_in_create_format( /*=============================================*/ char* buf, /* in: auxiliary buffer */ char* str, /* in/out: pointer to a string */ - ulint len, /* in: str has to be a buffer at least - len + 5000 bytes */ + ulint len, /* in: buf has to be a buffer of at least + len + 5000 bytes; str must have at least + len + 1 bytes */ dict_table_t* table) /* in: table */ { - dict_foreign_t* foreign; - ulint i; char* buf2; buf2 = buf; @@ -3358,78 +3901,12 @@ dict_print_info_on_foreign_keys_in_create_format( } while (foreign != NULL) { - buf2 += sprintf(buf2, ",\n FOREIGN KEY ("); - - for (i = 0; i < foreign->n_fields; i++) { - if ((ulint)(buf2 - buf) >= len) { - goto no_space; - } - buf2 += sprintf(buf2, "`%s`", - foreign->foreign_col_names[i]); - - if (i + 1 < foreign->n_fields) { - buf2 += sprintf(buf2, ", "); - } - } - - if (dict_tables_have_same_db(table->name, - foreign->referenced_table_name)) { - /* Do not print the database name of the referenced - table */ - buf2 += sprintf(buf2, ") REFERENCES `%s` (", - dict_remove_db_name( - foreign->referenced_table_name)); - } else { - buf2 += sprintf(buf2, ") REFERENCES `%s` (", - foreign->referenced_table_name); - /* Change the '/' in the table name to '.' */ - - for (i = ut_strlen(buf); i > 0; i--) { - if (buf[i] == '/') { + if ((ulint)(buf2 - buf) >= len) { + goto no_space; + } - buf[i] = '.'; - - break; - } - } - } - - for (i = 0; i < foreign->n_fields; i++) { - if ((ulint)(buf2 - buf) >= len) { - goto no_space; - } - buf2 += sprintf(buf2, "`%s`", - foreign->referenced_col_names[i]); - if (i + 1 < foreign->n_fields) { - buf2 += sprintf(buf2, ", "); - } - } - - buf2 += sprintf(buf2, ")"); - - if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) { - buf2 += sprintf(buf2, " ON DELETE CASCADE"); - } - - if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) { - buf2 += sprintf(buf2, " ON DELETE SET NULL"); - } - - if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) { - buf2 += sprintf(buf2, " ON DELETE NO ACTION"); - } - - if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) { - buf2 += sprintf(buf2, " ON UPDATE CASCADE"); - } - - if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) { - buf2 += sprintf(buf2, " ON UPDATE SET NULL"); - } - - if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) { - buf2 += sprintf(buf2, " ON UPDATE NO ACTION"); - } + buf2 = dict_print_info_on_foreign_key_in_create_format( + foreign, buf2); foreign = UT_LIST_GET_NEXT(foreign_list, foreign); } @@ -3490,7 +3967,7 @@ dict_print_info_on_foreign_keys( goto no_space; } - buf2 += sprintf(buf2, "%s", + buf2 += sprintf(buf2, "%.500s", foreign->foreign_col_names[i]); if (i + 1 < foreign->n_fields) { @@ -3498,14 +3975,14 @@ dict_print_info_on_foreign_keys( } } - buf2 += sprintf(buf2, ") REFER %s(", + buf2 += sprintf(buf2, ") REFER %.500s(", foreign->referenced_table_name); for (i = 0; i < foreign->n_fields; i++) { if ((ulint)(buf2 - buf) >= len) { goto no_space; } - buf2 += sprintf(buf2, "%s", + buf2 += sprintf(buf2, "%.500s", foreign->referenced_col_names[i]); if (i + 1 < foreign->n_fields) { buf2 += sprintf(buf2, " "); diff --git a/innobase/dict/dict0load.c b/innobase/dict/dict0load.c index 1070a8f5426..999eb55bb20 100644 --- a/innobase/dict/dict0load.c +++ b/innobase/dict/dict0load.c @@ -456,7 +456,7 @@ dict_load_indexes( ut_ad(len == 8); id = mach_read_from_8(field); - ut_a(0 == ut_strcmp((void*) "NAME", + ut_a(0 == ut_strcmp((char*) "NAME", dict_field_get_col( dict_index_get_nth_field( dict_table_get_first_index(sys_indexes), 4))->name)); @@ -515,7 +515,7 @@ dict_load_indexes( && ((type & DICT_CLUSTERED) || ((table == dict_sys->sys_tables) && (name_len == ut_strlen("ID_IND")) - && (0 == ut_memcmp(name_buf, (void*) "ID_IND", + && (0 == ut_memcmp(name_buf, (char*) "ID_IND", name_len))))) { /* The index was created in memory already in @@ -566,6 +566,7 @@ dict_load_table( char* buf; ulint space; ulint n_cols; + ulint err; mtr_t mtr; ut_ad(mutex_own(&(dict_sys->mutex))); @@ -674,8 +675,25 @@ dict_load_table( dict_load_indexes(table, heap); - ut_a(DB_SUCCESS == dict_load_foreigns(table->name)); + err = dict_load_foreigns(table->name); +/* + if (err != DB_SUCCESS) { + + mutex_enter(&dict_foreign_err_mutex); + ut_print_timestamp(stderr); + + fprintf(stderr, +" InnoDB: Error: could not make a foreign key definition to match\n" +"InnoDB: the foreign key table or the referenced table!\n" +"InnoDB: The data dictionary of InnoDB is corrupt. You may need to drop\n" +"InnoDB: and recreate the foreign key table or the referenced table.\n" +"InnoDB: Send a detailed bug report to mysql@lists.mysql.com\n" +"InnoDB: Latest foreign key error printout:\n%s\n", dict_foreign_err_buf); + + mutex_exit(&dict_foreign_err_mutex); + } +*/ mem_heap_free(heap); return(table); @@ -978,8 +996,8 @@ dict_load_foreign( field = rec_get_nth_field(rec, 4, &len); - foreign->referenced_table_name = mem_heap_alloc(foreign->heap, 1 + len); - + foreign->referenced_table_name = mem_heap_alloc(foreign->heap, + 1 + len); ut_memcpy(foreign->referenced_table_name, field, len); foreign->referenced_table_name[len] = '\0'; @@ -988,10 +1006,19 @@ dict_load_foreign( dict_load_foreign_cols(id, foreign); + /* If the foreign table is not yet in the dictionary cache, we + have to load it so that we are able to make type comparisons + in the next function call. */ + + dict_table_get_low(foreign->foreign_table_name); + /* Note that there may already be a foreign constraint object in the dictionary cache for this constraint: then the following call only sets the pointers in it to point to the appropriate table - and index objects and frees the newly created object foreign. */ + and index objects and frees the newly created object foreign. + Adding to the cache should always succeed since we are not creating + a new foreign key constraint but loading one from the data + dictionary. */ err = dict_foreign_add_to_cache(foreign); diff --git a/innobase/dyn/Makefile.am b/innobase/dyn/Makefile.am index 79c0000868c..ec33a3c18a9 100644 --- a/innobase/dyn/Makefile.am +++ b/innobase/dyn/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libdyn.a +noinst_LIBRARIES = libdyn.a libdyn_a_SOURCES = dyn0dyn.c diff --git a/innobase/eval/Makefile.am b/innobase/eval/Makefile.am index 5dd0eab4c9b..aebffb91be3 100644 --- a/innobase/eval/Makefile.am +++ b/innobase/eval/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libeval.a +noinst_LIBRARIES = libeval.a libeval_a_SOURCES = eval0eval.c eval0proc.c diff --git a/innobase/fil/Makefile.am b/innobase/fil/Makefile.am index a9473fdb762..dc0baff7d1a 100644 --- a/innobase/fil/Makefile.am +++ b/innobase/fil/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libfil.a +noinst_LIBRARIES = libfil.a libfil_a_SOURCES = fil0fil.c diff --git a/innobase/fsp/Makefile.am b/innobase/fsp/Makefile.am index b3e9ab44d9b..edf06bda0d6 100644 --- a/innobase/fsp/Makefile.am +++ b/innobase/fsp/Makefile.am @@ -18,7 +18,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libfsp.a +noinst_LIBRARIES = libfsp.a libfsp_a_SOURCES = fsp0fsp.c diff --git a/innobase/fut/Makefile.am b/innobase/fut/Makefile.am index a4b1e30e03c..839fdb1580e 100644 --- a/innobase/fut/Makefile.am +++ b/innobase/fut/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libfut.a +noinst_LIBRARIES = libfut.a libfut_a_SOURCES = fut0fut.c fut0lst.c diff --git a/innobase/ha/Makefile.am b/innobase/ha/Makefile.am index ce846d37622..121bafe167d 100644 --- a/innobase/ha/Makefile.am +++ b/innobase/ha/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libha.a +noinst_LIBRARIES = libha.a libha_a_SOURCES = ha0ha.c hash0hash.c diff --git a/innobase/ibuf/Makefile.am b/innobase/ibuf/Makefile.am index 1c1d196c40c..fb813d38ee5 100644 --- a/innobase/ibuf/Makefile.am +++ b/innobase/ibuf/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libibuf.a +noinst_LIBRARIES = libibuf.a libibuf_a_SOURCES = ibuf0ibuf.c diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c index 5cd066afc27..187afa17047 100644 --- a/innobase/ibuf/ibuf0ibuf.c +++ b/innobase/ibuf/ibuf0ibuf.c @@ -2391,7 +2391,7 @@ ibuf_delete_rec( ut_ad(ibuf_inside()); - success = btr_cur_optimistic_delete(btr_pcur_get_btr_cur(pcur), mtr); + success = btr_cur_optimistic_delete(btr_pcur_get_btr_cur(pcur), mtr); if (success) { #ifdef UNIV_IBUF_DEBUG @@ -2401,7 +2401,7 @@ ibuf_delete_rec( return(FALSE); } - /* We have to resort to a pessimistic delete from ibuf */ + /* We have to resort to a pessimistic delete from ibuf */ btr_pcur_store_position(pcur, mtr); btr_pcur_commit_specify_mtr(pcur, mtr); @@ -2420,17 +2420,22 @@ ibuf_delete_rec( fprintf(stderr, "InnoDB: ibuf cursor restoration fails!\n"); fprintf(stderr, "InnoDB: ibuf record inserted to page %lu\n", page_no); + fflush(stderr); + rec_print(btr_pcur_get_rec(pcur)); rec_print(pcur->old_rec); dtuple_print(search_tuple); rec_print(page_rec_get_next(btr_pcur_get_rec(pcur))); + fflush(stdout); mtr_commit(mtr); fprintf(stderr, "InnoDB: Validating insert buffer tree:\n"); - ut_a(btr_validate_tree(ibuf_data->index->tree)); - fprintf(stderr, "InnoDB: Ibuf tree ok\n"); + ut_a(btr_validate_tree(ibuf_data->index->tree)); + + fprintf(stderr, "InnoDB: ibuf tree ok\n"); + fflush(stderr); } ut_a(success); diff --git a/innobase/include/Makefile.i b/innobase/include/Makefile.i index 985ec525950..f3e3fbe989e 100644 --- a/innobase/include/Makefile.i +++ b/innobase/include/Makefile.i @@ -1,7 +1,5 @@ # Makefile included in Makefile.am in every subdirectory -libsdir = ../libs - INCLUDES = -I$(srcdir)/../include -I$(srcdir)/../../include -I../../include # Don't update the files from bitkeeper diff --git a/innobase/include/buf0buf.h b/innobase/include/buf0buf.h index 81eeb7fced8..b613d60ebf7 100644 --- a/innobase/include/buf0buf.h +++ b/innobase/include/buf0buf.h @@ -496,6 +496,13 @@ buf_print_io( /*=========*/ char* buf, /* in/out: buffer where to print */ char* buf_end);/* in: buffer end */ +/************************************************************************* +Returns the ratio in percents of modified pages in the buffer pool / +database pages in the buffer pool. */ + +ulint +buf_get_modified_ratio_pct(void); +/*============================*/ /************************************************************************** Refreshes the statistics used to print per-second averages. */ diff --git a/innobase/include/buf0lru.h b/innobase/include/buf0lru.h index 6a3c948507d..5c995b259bf 100644 --- a/innobase/include/buf0lru.h +++ b/innobase/include/buf0lru.h @@ -46,6 +46,20 @@ buf_LRU_get_recent_limit(void); /*==========================*/ /* out: the limit; zero if could not determine it */ /********************************************************************** +Look for a replaceable block from the end of the LRU list and put it to +the free list if found. */ + +ibool +buf_LRU_search_and_free_block( +/*==========================*/ + /* out: TRUE if freed */ + ulint n_iterations); /* in: how many times this has been called + repeatedly without result: a high value means + that we should search farther; if value is + k < 10, then we only search k/10 * number + of pages in the buffer pool from the end + of the LRU list */ +/********************************************************************** Returns a free block from the buf_pool. The block is taken off the free list. If it is empty, blocks are moved from the end of the LRU list to the free list. */ @@ -88,17 +102,6 @@ void buf_LRU_make_block_old( /*===================*/ buf_block_t* block); /* in: control block */ -/********************************************************************** -Look for a replaceable block from the end of the LRU list and put it to -the free list if found. */ - -ibool -buf_LRU_search_and_free_block( -/*==========================*/ - /* out: TRUE if freed */ - ulint n_iterations); /* in: how many times this has been called - repeatedly without result: a high value - means that we should search farther */ /************************************************************************** Validates the LRU list. */ diff --git a/innobase/include/db0err.h b/innobase/include/db0err.h index c67c09bad27..ab7d0caa35c 100644 --- a/innobase/include/db0err.h +++ b/innobase/include/db0err.h @@ -44,6 +44,8 @@ Created 5/24/1996 Heikki Tuuri #define DB_CORRUPTION 39 /* data structure corruption noticed */ #define DB_COL_APPEARS_TWICE_IN_INDEX 40 /* InnoDB cannot handle an index where same column appears twice */ +#define DB_CANNOT_DROP_CONSTRAINT 40 /* dropping a foreign key constraint + from a table failed */ /* The following are partial failure codes */ #define DB_FAIL 1000 diff --git a/innobase/include/dict0dict.h b/innobase/include/dict0dict.h index b5e6e04a1de..97486a7c2f6 100644 --- a/innobase/include/dict0dict.h +++ b/innobase/include/dict0dict.h @@ -219,6 +219,24 @@ dict_create_foreign_constraints( char* name); /* in: table full name in the normalized form database_name/table_name */ /************************************************************************** +Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. */ + +ulint +dict_foreign_parse_drop_constraints( +/*================================*/ + /* out: DB_SUCCESS or + DB_CANNOT_DROP_CONSTRAINT if + syntax error or the constraint + id does not match */ + mem_heap_t* heap, /* in: heap from which we can + allocate memory */ + trx_t* trx, /* in: transaction */ + dict_table_t* table, /* in: table */ + ulint* n, /* out: number of constraints + to drop */ + char*** constraints_to_drop); /* out: id's of the + constraints to drop */ +/************************************************************************** Returns a table object and memoryfixes it. NOTE! This is a high-level function to be used mainly from outside the 'dict' directory. Inside this directory dict_table_get_low is usually the appropriate function. */ @@ -333,6 +351,16 @@ dict_print_info_on_foreign_keys( char* str, /* in/out: pointer to a string */ ulint len, /* in: space in str available for info */ dict_table_t* table); /* in: table */ +/************************************************************************** +Sprintfs to a string info on a foreign key of a table in a format suitable +for CREATE TABLE. */ + +char* +dict_print_info_on_foreign_key_in_create_format( +/*============================================*/ + /* out: how far in buf we printed */ + dict_foreign_t* foreign,/* in: foreign key constraint */ + char* buf); /* in: buffer of at least 5000 bytes */ /************************************************************************ Gets the first index on the table (the clustered index). */ UNIV_INLINE @@ -808,6 +836,14 @@ void dict_mutex_exit_for_mysql(void); /*===========================*/ +/* The following len must be at least 10000 bytes! */ +#define DICT_FOREIGN_ERR_BUF_LEN 10000 + +/* Buffers for storing detailed information about the latest foreign key +and unique key errors */ +extern char* dict_foreign_err_buf; +extern char* dict_unique_err_buf; +extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */ extern dict_sys_t* dict_sys; /* the dictionary system */ extern rw_lock_t dict_operation_lock; diff --git a/innobase/include/log0log.h b/innobase/include/log0log.h index f200371de9d..4e1404b15fe 100644 --- a/innobase/include/log0log.h +++ b/innobase/include/log0log.h @@ -20,7 +20,7 @@ typedef struct log_group_struct log_group_t; extern ibool log_do_write; extern ibool log_debug_writes; -/* Wait modes for log_flush_up_to */ +/* Wait modes for log_write_up_to */ #define LOG_NO_WAIT 91 #define LOG_WAIT_ONE_GROUP 92 #define LOG_WAIT_ALL_GROUPS 93 @@ -157,26 +157,21 @@ log_io_complete( /*============*/ log_group_t* group); /* in: log group */ /********************************************************** -Flushes the log files to the disk, using, for example, the Unix fsync. -This function does the flush even if the user has set -srv_flush_log_at_trx_commit = FALSE. */ - -void -log_flush_to_disk(void); -/*===================*/ -/********************************************************** This function is called, e.g., when a transaction wants to commit. It checks -that the log has been flushed to disk up to the last log entry written by the -transaction. If there is a flush running, it waits and checks if the flush -flushed enough. If not, starts a new flush. */ +that the log has been written to the log file up to the last log entry written +by the transaction. If there is a flush running, it waits and checks if the +flush flushed enough. If not, starts a new flush. */ void -log_flush_up_to( +log_write_up_to( /*============*/ dulint lsn, /* in: log sequence number up to which the log should - be flushed, ut_dulint_max if not specified */ - ulint wait); /* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, + be written, ut_dulint_max if not specified */ + ulint wait, /* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, or LOG_WAIT_ALL_GROUPS */ + ibool flush_to_disk); + /* in: TRUE if we want the written log also to be + flushed to disk */ /******************************************************************** Advances the smallest lsn for which there are unflushed dirty blocks in the buffer pool and also may make a new checkpoint. NOTE: this function may only @@ -741,27 +736,37 @@ struct log_struct{ be advanced, it is enough that the write i/o has been completed for all log groups */ - dulint flush_lsn; /* end lsn for the current flush */ - ulint flush_end_offset;/* the data in buffer has been flushed + dulint write_lsn; /* end lsn for the current running + write */ + ulint write_end_offset;/* the data in buffer has been written up to this offset when the current - flush ends: this field will then + write ends: this field will then be copied to buf_next_to_write */ - ulint n_pending_writes;/* number of currently pending flush - writes */ + dulint current_flush_lsn;/* end lsn for the current running + write + flush operation */ + dulint flushed_to_disk_lsn; + /* how far we have written the log + AND flushed to disk */ + ulint n_pending_writes;/* number of currently pending flushes + or writes */ + /* NOTE on the 'flush' in names of the fields below: starting from + 4.0.14, we separate the write of the log file and the actual fsync() + or other method to flush it to disk. The names below shhould really + be 'flush_or_write'! */ os_event_t no_flush_event; /* this event is in the reset state - when a flush is running; a thread - should wait for this without owning - the log mutex, but NOTE that to set or - reset this event, the thread MUST own - the log mutex! */ + when a flush or a write is running; + a thread should wait for this without + owning the log mutex, but NOTE that + to set or reset this event, the + thread MUST own the log mutex! */ ibool one_flushed; /* during a flush, this is first FALSE and becomes TRUE when one log group - has been flushed */ + has been written or flushed */ os_event_t one_flushed_event;/* this event is reset when the - flush has not yet completed for any - log group; e.g., this means that a - transaction has been committed when - this is set; a thread should wait + flush or write has not yet completed + for any log group; e.g., this means + that a transaction has been committed + when this is set; a thread should wait for this without owning the log mutex, but NOTE that to set or reset this event, the thread MUST own the log diff --git a/innobase/include/row0ins.h b/innobase/include/row0ins.h index cc3b9fa7e9a..a5b4b74e7fc 100644 --- a/innobase/include/row0ins.h +++ b/innobase/include/row0ins.h @@ -35,7 +35,6 @@ row_ins_check_foreign_constraint( dictionary cache if they exist at all */ dict_table_t* table, /* in: if check_ref is TRUE, then the foreign table, else the referenced table */ - dict_index_t* index, /* in: index in table */ dtuple_t* entry, /* in: index entry for index */ que_thr_t* thr); /* in: query thread */ /************************************************************************* diff --git a/innobase/include/row0mysql.h b/innobase/include/row0mysql.h index 972fabc74cf..1964f53dabb 100644 --- a/innobase/include/row0mysql.h +++ b/innobase/include/row0mysql.h @@ -427,13 +427,21 @@ struct row_prebuilt_struct { index where the ordering column is the row id: in this case this flag is set to TRUE */ - dict_index_t* index; /* current index for a search, if any */ + dict_index_t* index; /* current index for a search, if + any */ ulint read_just_key; /* set to 1 when MySQL calls ha_innobase::extra with the argument HA_EXTRA_KEYREAD; it is enough to read just columns defined in the index (i.e., no read of the clustered index record necessary) */ + ibool used_in_HANDLER;/* TRUE if we have been using this + handle in a MySQL HANDLER low level + index cursor command: then we must + store the pcur position even in a + unique search from a clustered index, + because HANDLER allows NEXT and PREV + in such a situation */ ulint template_type; /* ROW_MYSQL_WHOLE_ROW, ROW_MYSQL_REC_FIELDS, ROW_MYSQL_DUMMY_TEMPLATE, or diff --git a/innobase/include/srv0srv.h b/innobase/include/srv0srv.h index bc0960ae023..121e9c44a24 100644 --- a/innobase/include/srv0srv.h +++ b/innobase/include/srv0srv.h @@ -75,6 +75,9 @@ extern ulint srv_lock_wait_timeout; extern char* srv_file_flush_method_str; extern ulint srv_unix_file_flush_method; extern ulint srv_win_file_flush_method; + +extern ulint srv_max_dirty_pages_pct; + extern ulint srv_force_recovery; extern ulint srv_thread_concurrency; diff --git a/innobase/include/trx0trx.h b/innobase/include/trx0trx.h index 34f820f03e7..39229923375 100644 --- a/innobase/include/trx0trx.h +++ b/innobase/include/trx0trx.h @@ -157,6 +157,15 @@ trx_commit_for_mysql( /* out: 0 or error number */ trx_t* trx); /* in: trx handle */ /************************************************************************** +If required, flushes the log to disk if we called trx_commit_for_mysql() +with trx->flush_log_later == TRUE. */ + +ulint +trx_commit_complete_for_mysql( +/*==========================*/ + /* out: 0 or error number */ + trx_t* trx); /* in: trx handle */ +/************************************************************************** Marks the latest SQL statement ended. */ void @@ -343,6 +352,11 @@ struct trx_struct{ dulint no; /* transaction serialization number == max trx id when the transaction is moved to COMMITTED_IN_MEMORY state */ + ibool flush_log_later;/* when we commit the transaction + in MySQL's binlog write, we will + flush the log to disk later in + a separate call */ + dulint commit_lsn; /* lsn at the time of the commit */ ibool dict_operation; /* TRUE if the trx is used to create a table, create an index, or drop a table */ @@ -418,10 +432,6 @@ struct trx_struct{ lock_t* auto_inc_lock; /* possible auto-inc lock reserved by the transaction; note that it is also in the lock list trx_locks */ - ibool ignore_duplicates_in_insert; - /* in an insert roll back only insert - of the latest row in case - of a duplicate key error */ UT_LIST_NODE_T(trx_t) trx_list; /* list of transactions */ UT_LIST_NODE_T(trx_t) diff --git a/innobase/include/univ.i b/innobase/include/univ.i index bf606efcf64..e29f3ec92e1 100644 --- a/innobase/include/univ.i +++ b/innobase/include/univ.i @@ -100,6 +100,15 @@ memory is read outside the allocated blocks. */ #define YYDEBUG 1 +#ifdef HAVE_purify +/* The following sets all new allocated memory to zero before use: +this can be used to eliminate unnecessary Purify warnings, but note that +it also masks many bugs Purify could detect. For detailed Purify analysis it +is best to remove the define below and look through the warnings one +by one. */ +#define UNIV_SET_MEM_TO_ZERO +#endif + /* #define UNIV_SQL_DEBUG #define UNIV_LOG_DEBUG diff --git a/innobase/include/ut0dbg.h b/innobase/include/ut0dbg.h index 3407483696c..e99dc8c09d6 100644 --- a/innobase/include/ut0dbg.h +++ b/innobase/include/ut0dbg.h @@ -20,7 +20,6 @@ extern ibool ut_dbg_stop_threads; extern ulint* ut_dbg_null_ptr; - #define ut_a(EXPR)\ {\ ulint dbg_i;\ @@ -31,8 +30,10 @@ extern ulint* ut_dbg_null_ptr; " InnoDB: Assertion failure in thread %lu in file %s line %lu\n",\ os_thread_pf(os_thread_get_curr_id()), IB__FILE__,\ (ulint)__LINE__);\ + fprintf(stderr,\ + "InnoDB: Failing assertion: " #EXPR);\ fprintf(stderr,\ - "InnoDB: We intentionally generate a memory trap.\n");\ + "\nInnoDB: We intentionally generate a memory trap.\n");\ fprintf(stderr,\ "InnoDB: Send a detailed bug report to mysql@lists.mysql.com\n");\ ut_dbg_stop_threads = TRUE;\ diff --git a/innobase/lock/Makefile.am b/innobase/lock/Makefile.am index f9e1b227f3c..549eb2604e3 100644 --- a/innobase/lock/Makefile.am +++ b/innobase/lock/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = liblock.a +noinst_LIBRARIES = liblock.a liblock_a_SOURCES = lock0lock.c diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c index d4329c4873c..74dc4aea515 100644 --- a/innobase/lock/lock0lock.c +++ b/innobase/lock/lock0lock.c @@ -3092,8 +3092,7 @@ lock_deadlock_recursive( err_buf += strlen(err_buf); err_buf += sprintf(err_buf, - " LATEST DETECTED DEADLOCK:\n" - "*** (1) TRANSACTION:\n"); + "\n*** (1) TRANSACTION:\n"); trx_print(err_buf, wait_lock->trx); err_buf += strlen(err_buf); @@ -3935,24 +3934,15 @@ lock_print_info( return; } - - buf += sprintf(buf, "Trx id counter %lu %lu\n", - ut_dulint_get_high(trx_sys->max_trx_id), - ut_dulint_get_low(trx_sys->max_trx_id)); - - buf += sprintf(buf, - "Purge done for trx's n:o < %lu %lu undo n:o < %lu %lu\n", - ut_dulint_get_high(purge_sys->purge_trx_no), - ut_dulint_get_low(purge_sys->purge_trx_no), - ut_dulint_get_high(purge_sys->purge_undo_no), - ut_dulint_get_low(purge_sys->purge_undo_no)); lock_mutex_enter_kernel(); - buf += sprintf(buf, - "Total number of lock structs in row lock hash table %lu\n", - lock_get_n_rec_locks()); if (lock_deadlock_found) { + + buf += sprintf(buf, +"------------------------\n" +"LATEST DETECTED DEADLOCK\n" +"------------------------\n"); if ((ulint)(buf_end - buf) < 100 + strlen(lock_latest_err_buf)) { @@ -3973,6 +3963,26 @@ lock_print_info( return; } + buf += sprintf(buf, +"------------\n" +"TRANSACTIONS\n" +"------------\n"); + + buf += sprintf(buf, "Trx id counter %lu %lu\n", + ut_dulint_get_high(trx_sys->max_trx_id), + ut_dulint_get_low(trx_sys->max_trx_id)); + + buf += sprintf(buf, + "Purge done for trx's n:o < %lu %lu undo n:o < %lu %lu\n", + ut_dulint_get_high(purge_sys->purge_trx_no), + ut_dulint_get_low(purge_sys->purge_trx_no), + ut_dulint_get_high(purge_sys->purge_undo_no), + ut_dulint_get_low(purge_sys->purge_undo_no)); + + buf += sprintf(buf, + "Total number of lock structs in row lock hash table %lu\n", + lock_get_n_rec_locks()); + buf += sprintf(buf, "LIST OF TRANSACTIONS FOR EACH SESSION:\n"); /* First print info on non-active transactions */ diff --git a/innobase/log/Makefile.am b/innobase/log/Makefile.am index 3910a25ab1a..2dbaf93e6d9 100644 --- a/innobase/log/Makefile.am +++ b/innobase/log/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = liblog.a +noinst_LIBRARIES = liblog.a liblog_a_SOURCES = log0log.c log0recv.c diff --git a/innobase/log/log0log.c b/innobase/log/log0log.c index bdfce783a43..e717d897e41 100644 --- a/innobase/log/log0log.c +++ b/innobase/log/log0log.c @@ -178,7 +178,7 @@ loop: /* Not enough free space, do a syncronous flush of the log buffer */ - log_flush_up_to(ut_dulint_max, LOG_WAIT_ALL_GROUPS); + log_write_up_to(ut_dulint_max, LOG_WAIT_ALL_GROUPS, TRUE); count++; @@ -675,7 +675,9 @@ log_init(void) log_sys->buf_next_to_write = 0; - log_sys->flush_lsn = ut_dulint_zero; + log_sys->write_lsn = ut_dulint_zero; + log_sys->current_flush_lsn = ut_dulint_zero; + log_sys->flushed_to_disk_lsn = ut_dulint_zero; log_sys->written_to_some_lsn = log_sys->lsn; log_sys->written_to_all_lsn = log_sys->lsn; @@ -867,7 +869,7 @@ log_group_check_flush_completion( printf("Log flushed first to group %lu\n", group->id); } - log_sys->written_to_some_lsn = log_sys->flush_lsn; + log_sys->written_to_some_lsn = log_sys->write_lsn; log_sys->one_flushed = TRUE; return(LOG_UNLOCK_NONE_FLUSHED_LOCK); @@ -896,15 +898,15 @@ log_sys_check_flush_completion(void) if (log_sys->n_pending_writes == 0) { - log_sys->written_to_all_lsn = log_sys->flush_lsn; - log_sys->buf_next_to_write = log_sys->flush_end_offset; + log_sys->written_to_all_lsn = log_sys->write_lsn; + log_sys->buf_next_to_write = log_sys->write_end_offset; - if (log_sys->flush_end_offset > log_sys->max_buf_free / 2) { + if (log_sys->write_end_offset > log_sys->max_buf_free / 2) { /* Move the log buffer content to the start of the buffer */ move_start = ut_calc_align_down( - log_sys->flush_end_offset, + log_sys->write_end_offset, OS_FILE_LOG_BLOCK_SIZE); move_end = ut_calc_align(log_sys->buf_free, OS_FILE_LOG_BLOCK_SIZE); @@ -982,57 +984,6 @@ log_io_complete( } /********************************************************** -Flushes the log files to the disk, using, for example, the Unix fsync. -This function does the flush even if the user has set -srv_flush_log_at_trx_commit = FALSE. */ - -void -log_flush_to_disk(void) -/*===================*/ -{ - log_group_t* group; -loop: - mutex_enter(&(log_sys->mutex)); - - if (log_sys->n_pending_writes > 0) { - /* A log file write is running */ - - mutex_exit(&(log_sys->mutex)); - - /* Wait for the log file write to complete and try again */ - - os_event_wait(log_sys->no_flush_event); - - goto loop; - } - - group = UT_LIST_GET_FIRST(log_sys->log_groups); - - log_sys->n_pending_writes++; - group->n_pending_writes++; - - os_event_reset(log_sys->no_flush_event); - os_event_reset(log_sys->one_flushed_event); - - mutex_exit(&(log_sys->mutex)); - - fil_flush(group->space_id); - - mutex_enter(&(log_sys->mutex)); - - ut_a(group->n_pending_writes == 1); - ut_a(log_sys->n_pending_writes == 1); - - group->n_pending_writes--; - log_sys->n_pending_writes--; - - os_event_set(log_sys->no_flush_event); - os_event_set(log_sys->one_flushed_event); - - mutex_exit(&(log_sys->mutex)); -} - -/********************************************************** Writes a log file header to a log file space. */ static void @@ -1205,12 +1156,15 @@ by the transaction. If there is a flush running, it waits and checks if the flush flushed enough. If not, starts a new flush. */ void -log_flush_up_to( +log_write_up_to( /*============*/ dulint lsn, /* in: log sequence number up to which the log should be written, ut_dulint_max if not specified */ - ulint wait) /* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, + ulint wait, /* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, or LOG_WAIT_ALL_GROUPS */ + ibool flush_to_disk) + /* in: TRUE if we want the written log also to be + flushed to disk */ { log_group_t* group; ulint start_offset; @@ -1239,9 +1193,18 @@ loop: mutex_enter(&(log_sys->mutex)); - if ((ut_dulint_cmp(log_sys->written_to_all_lsn, lsn) >= 0) - || ((ut_dulint_cmp(log_sys->written_to_some_lsn, lsn) >= 0) - && (wait != LOG_WAIT_ALL_GROUPS))) { + if (flush_to_disk + && ut_dulint_cmp(log_sys->flushed_to_disk_lsn, lsn) >= 0) { + + mutex_exit(&(log_sys->mutex)); + + return; + } + + if (!flush_to_disk + && (ut_dulint_cmp(log_sys->written_to_all_lsn, lsn) >= 0 + || (ut_dulint_cmp(log_sys->written_to_some_lsn, lsn) >= 0 + && wait != LOG_WAIT_ALL_GROUPS))) { mutex_exit(&(log_sys->mutex)); @@ -1249,10 +1212,19 @@ loop: } if (log_sys->n_pending_writes > 0) { - /* A flush is running */ + /* A write (+ possibly flush to disk) is running */ + + if (flush_to_disk + && ut_dulint_cmp(log_sys->current_flush_lsn, lsn) >= 0) { + /* The write + flush will write enough: wait for it to + complete */ + + goto do_waits; + } - if (ut_dulint_cmp(log_sys->flush_lsn, lsn) >= 0) { - /* The flush will flush enough: wait for it to + if (!flush_to_disk + && ut_dulint_cmp(log_sys->write_lsn, lsn) >= 0) { + /* The write will write enough: wait for it to complete */ goto do_waits; @@ -1260,16 +1232,17 @@ loop: mutex_exit(&(log_sys->mutex)); - /* Wait for the flush to complete and try to start a new - flush */ + /* Wait for the write to complete and try to start a new + write */ os_event_wait(log_sys->no_flush_event); goto loop; } - if (log_sys->buf_free == log_sys->buf_next_to_write) { - /* Nothing to flush */ + if (!flush_to_disk + && log_sys->buf_free == log_sys->buf_next_to_write) { + /* Nothing to write and no flush to disk requested */ mutex_exit(&(log_sys->mutex)); @@ -1277,7 +1250,7 @@ loop: } if (log_debug_writes) { - printf("Flushing log from %lu %lu up to lsn %lu %lu\n", + printf("Writing log from %lu %lu up to lsn %lu %lu\n", ut_dulint_get_high(log_sys->written_to_all_lsn), ut_dulint_get_low(log_sys->written_to_all_lsn), ut_dulint_get_high(log_sys->lsn), @@ -1301,7 +1274,12 @@ loop: ut_ad(area_end - area_start > 0); - log_sys->flush_lsn = log_sys->lsn; + log_sys->write_lsn = log_sys->lsn; + + if (flush_to_disk) { + log_sys->current_flush_lsn = log_sys->lsn; + } + log_sys->one_flushed = FALSE; log_block_set_flush_bit(log_sys->buf + area_start, TRUE); @@ -1318,10 +1296,12 @@ loop: OS_FILE_LOG_BLOCK_SIZE); log_sys->buf_free += OS_FILE_LOG_BLOCK_SIZE; - log_sys->flush_end_offset = log_sys->buf_free; + log_sys->write_end_offset = log_sys->buf_free; group = UT_LIST_GET_FIRST(log_sys->log_groups); + /* Do the write to the log files */ + while (group) { log_group_write_buf(LOG_FLUSH, group, log_sys->buf + area_start, @@ -1330,20 +1310,25 @@ loop: OS_FILE_LOG_BLOCK_SIZE), start_offset - area_start); - log_group_set_fields(group, log_sys->flush_lsn); + log_group_set_fields(group, log_sys->write_lsn); group = UT_LIST_GET_NEXT(log_groups, group); } mutex_exit(&(log_sys->mutex)); - if (srv_unix_file_flush_method != SRV_UNIX_O_DSYNC - && srv_unix_file_flush_method != SRV_UNIX_NOSYNC - && srv_flush_log_at_trx_commit != 2) { + if (srv_unix_file_flush_method == SRV_UNIX_O_DSYNC) { + /* O_DSYNC means the OS did not buffer the log file at all: + so we have also flushed to disk what we have written */ + + log_sys->flushed_to_disk_lsn = log_sys->write_lsn; + + } else if (flush_to_disk) { group = UT_LIST_GET_FIRST(log_sys->log_groups); fil_flush(group->space_id); + log_sys->flushed_to_disk_lsn = log_sys->write_lsn; } mutex_enter(&(log_sys->mutex)); @@ -1403,7 +1388,7 @@ log_flush_margin(void) mutex_exit(&(log->mutex)); if (do_flush) { - log_flush_up_to(ut_dulint_max, LOG_NO_WAIT); + log_write_up_to(ut_dulint_max, LOG_NO_WAIT, FALSE); } } @@ -1555,7 +1540,8 @@ log_group_checkpoint( buf = group->checkpoint_buf; mach_write_to_8(buf + LOG_CHECKPOINT_NO, log_sys->next_checkpoint_no); - mach_write_to_8(buf + LOG_CHECKPOINT_LSN, log_sys->next_checkpoint_lsn); + mach_write_to_8(buf + LOG_CHECKPOINT_LSN, + log_sys->next_checkpoint_lsn); mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET, log_group_calc_lsn_offset( @@ -1664,8 +1650,10 @@ log_reset_first_header_and_checkpoint( lsn = ut_dulint_add(start, LOG_BLOCK_HDR_SIZE); /* Write the label of ibbackup --restore */ - sprintf((char*) hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, "ibbackup "); - ut_sprintf_timestamp((char*) hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP + sprintf((char*) hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, + "ibbackup "); + ut_sprintf_timestamp( + (char*) hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP + strlen("ibbackup ")); buf = hdr_buf + LOG_CHECKPOINT_1; @@ -1773,7 +1761,7 @@ log_checkpoint( write-ahead-logging algorithm ensures that the log has been flushed up to oldest_lsn. */ - log_flush_up_to(oldest_lsn, LOG_WAIT_ALL_GROUPS); + log_write_up_to(oldest_lsn, LOG_WAIT_ALL_GROUPS, TRUE); mutex_enter(&(log_sys->mutex)); @@ -2466,7 +2454,7 @@ loop: mutex_exit(&(log_sys->mutex)); - log_flush_up_to(limit_lsn, LOG_WAIT_ALL_GROUPS); + log_write_up_to(limit_lsn, LOG_WAIT_ALL_GROUPS, TRUE); calc_new_limit = FALSE; @@ -3104,8 +3092,8 @@ log_print( "Last checkpoint at %lu %lu\n", ut_dulint_get_high(log_sys->lsn), ut_dulint_get_low(log_sys->lsn), - ut_dulint_get_high(log_sys->written_to_some_lsn), - ut_dulint_get_low(log_sys->written_to_some_lsn), + ut_dulint_get_high(log_sys->flushed_to_disk_lsn), + ut_dulint_get_low(log_sys->flushed_to_disk_lsn), ut_dulint_get_high(log_sys->last_checkpoint_lsn), ut_dulint_get_low(log_sys->last_checkpoint_lsn)); diff --git a/innobase/log/log0recv.c b/innobase/log/log0recv.c index 3945b47933d..4efe4e7b23d 100644 --- a/innobase/log/log0recv.c +++ b/innobase/log/log0recv.c @@ -1833,7 +1833,12 @@ recv_report_corrupt_log( "InnoDB: WARNING: the log file may have been corrupt and it\n" "InnoDB: is possible that the log scan did not proceed\n" "InnoDB: far enough in recovery! Please run CHECK TABLE\n" - "InnoDB: on your InnoDB tables to check that they are ok!\n"); + "InnoDB: on your InnoDB tables to check that they are ok!\n" + "InnoDB: If mysqld crashes after this recovery, look at\n" + "InnoDB: section 6.1 of http://www.innodb.com/ibman.html\n" + "InnoDB: about forcing recovery.\n"); + + fflush(stderr); } /*********************************************************** @@ -2470,7 +2475,7 @@ recv_recovery_from_checkpoint_start( log_hdr_buf, max_cp_group); if (0 == ut_memcmp(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, - "ibbackup", ut_strlen("ibbackup"))) { + (byte*)"ibbackup", ut_strlen((char*)"ibbackup"))) { /* This log file was created by ibbackup --restore: print a note to the user about it */ @@ -2481,7 +2486,7 @@ recv_recovery_from_checkpoint_start( /* Wipe over the label now */ ut_memcpy(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, - " ", 4); + (char*)" ", 4); /* Write to the log file to wipe over the label */ fil_io(OS_FILE_WRITE | OS_FILE_LOG, TRUE, max_cp_group->space_id, diff --git a/innobase/mach/Makefile.am b/innobase/mach/Makefile.am index 8195831e92e..ce827c8033f 100644 --- a/innobase/mach/Makefile.am +++ b/innobase/mach/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libmach.a +noinst_LIBRARIES = libmach.a libmach_a_SOURCES = mach0data.c diff --git a/innobase/mem/Makefile.am b/innobase/mem/Makefile.am index 84f642e4469..10b7771b580 100644 --- a/innobase/mem/Makefile.am +++ b/innobase/mem/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libmem.a +noinst_LIBRARIES = libmem.a libmem_a_SOURCES = mem0mem.c mem0pool.c diff --git a/innobase/mtr/Makefile.am b/innobase/mtr/Makefile.am index 972dcaca80e..1e93a34ce23 100644 --- a/innobase/mtr/Makefile.am +++ b/innobase/mtr/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libmtr.a +noinst_LIBRARIES = libmtr.a libmtr_a_SOURCES = mtr0mtr.c mtr0log.c diff --git a/innobase/odbc/Makefile.am b/innobase/odbc/Makefile.am index d1a47bd8c18..f4282ba3907 100644 --- a/innobase/odbc/Makefile.am +++ b/innobase/odbc/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libodbc.a +noinst_LIBRARIES = libodbc.a libodbc_a_SOURCES = odbc0odbc.c diff --git a/innobase/os/Makefile.am b/innobase/os/Makefile.am index b06670bc703..132ce07c83b 100644 --- a/innobase/os/Makefile.am +++ b/innobase/os/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libos.a +noinst_LIBRARIES = libos.a libos_a_SOURCES = os0proc.c os0shm.c os0sync.c os0thread.c os0file.c diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 5ffcabf6fe6..53224eb59c5 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -214,9 +214,14 @@ os_file_get_last_error(void) "InnoDB: the directory. It may also be you have created a subdirectory\n" "InnoDB: of the same name as a data file.\n"); } else { - fprintf(stderr, - "InnoDB: Look from section 13.2 at http://www.innodb.com/ibman.html\n" - "InnoDB: what the error number means.\n"); + if (strerror((int)err) != NULL) { + fprintf(stderr, + "InnoDB: Error number %lu means '%s'.\n", err, strerror((int)err)); + } + + fprintf(stderr, + "InnoDB: See also section 13.2 at http://www.innodb.com/ibman.html\n" + "InnoDB: about operating system error numbers.\n"); } } @@ -252,9 +257,14 @@ os_file_get_last_error(void) "InnoDB: The error means mysqld does not have the access rights to\n" "InnoDB: the directory.\n"); } else { - fprintf(stderr, - "InnoDB: Look from section 13.2 at http://www.innodb.com/ibman.html\n" - "InnoDB: what the error number means or use the perror program of MySQL.\n"); + if (strerror((int)err) != NULL) { + fprintf(stderr, + "InnoDB: Error number %lu means '%s'.\n", err, strerror((int)err)); + } + + fprintf(stderr, + "InnoDB: See also section 13.2 at http://www.innodb.com/ibman.html\n" + "InnoDB: about operating system error numbers.\n"); } } @@ -511,10 +521,11 @@ try_again: } #endif #ifdef UNIV_NON_BUFFERED_IO - if (type == OS_LOG_FILE && srv_flush_log_at_trx_commit == 2) { + if (type == OS_LOG_FILE) { /* Do not use unbuffered i/o to log files because - value 2 denotes that we do not flush the log at every - commit, but only once per second */ + to allow group commit to work when MySQL binlogging + is used we must separate log file write and log + file flush to disk. */ } else { if (srv_win_file_flush_method == SRV_WIN_IO_UNBUFFERED) { @@ -741,7 +752,12 @@ os_file_set_size( offset = 0; low = (ib_longlong)size + (((ib_longlong)size_high) << 32); + + if (low >= (ib_longlong)(100 * 1024 * 1024)) { + fprintf(stderr, "InnoDB: Progress in MB:"); + } + while (offset < low) { if (low - offset < UNIV_PAGE_SIZE * 512) { n_bytes = (ulint)(low - offset); @@ -757,9 +773,24 @@ os_file_set_size( ut_free(buf2); goto error_handling; } + + /* Print about progress for each 100 MB written */ + if ((offset + n_bytes) / (ib_longlong)(100 * 1024 * 1024) + != offset / (ib_longlong)(100 * 1024 * 1024)) { + + fprintf(stderr, " %lu00", + (ulint)((offset + n_bytes) + / (ib_longlong)(100 * 1024 * 1024))); + } + offset += n_bytes; } + if (low >= (ib_longlong)(100 * 1024 * 1024)) { + + fprintf(stderr, "\n"); + } + ut_free(buf2); ret = os_file_flush(file); diff --git a/innobase/os/os0sync.c b/innobase/os/os0sync.c index a9127e6310a..407b280f805 100644 --- a/innobase/os/os0sync.c +++ b/innobase/os/os0sync.c @@ -68,9 +68,10 @@ os_event_create( os_fast_mutex_init(&(event->os_mutex)); #if defined(UNIV_HOTBACKUP) && defined(UNIV_HPUX10) - pthread_cond_init(&(event->cond_var), pthread_condattr_default); + ut_a(0 == pthread_cond_init(&(event->cond_var), + pthread_condattr_default)); #else - pthread_cond_init(&(event->cond_var), NULL); + ut_a(0 == pthread_cond_init(&(event->cond_var), NULL)); #endif event->is_set = FALSE; @@ -130,7 +131,7 @@ os_event_set( /* Do nothing */ } else { event->is_set = TRUE; - pthread_cond_broadcast(&(event->cond_var)); + ut_a(0 == pthread_cond_broadcast(&(event->cond_var))); } os_fast_mutex_unlock(&(event->os_mutex)); @@ -182,7 +183,7 @@ os_event_free( ut_a(event); os_fast_mutex_free(&(event->os_mutex)); - pthread_cond_destroy(&(event->cond_var)); + ut_a(0 == pthread_cond_destroy(&(event->cond_var))); ut_free(event); #endif @@ -446,9 +447,9 @@ os_fast_mutex_init( InitializeCriticalSection((LPCRITICAL_SECTION) fast_mutex); #else #if defined(UNIV_HOTBACKUP) && defined(UNIV_HPUX10) - pthread_mutex_init(fast_mutex, pthread_mutexattr_default); + ut_a(0 == pthread_mutex_init(fast_mutex, pthread_mutexattr_default)); #else - pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST); + ut_a(0 == pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST)); #endif #endif } @@ -495,10 +496,7 @@ os_fast_mutex_free( ut_a(fast_mutex); DeleteCriticalSection((LPCRITICAL_SECTION) fast_mutex); -#elif defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) - pthread_mutex_destroy(fast_mutex); #else - UT_NOT_USED(fast_mutex); - + ut_a(0 == pthread_mutex_destroy(fast_mutex)); #endif } diff --git a/innobase/page/Makefile.am b/innobase/page/Makefile.am index 85fe585a633..2e260787438 100644 --- a/innobase/page/Makefile.am +++ b/innobase/page/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libpage.a +noinst_LIBRARIES = libpage.a libpage_a_SOURCES = page0page.c page0cur.c diff --git a/innobase/pars/Makefile.am b/innobase/pars/Makefile.am index e5611f9dfc6..2356f330486 100644 --- a/innobase/pars/Makefile.am +++ b/innobase/pars/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libpars.a +noinst_LIBRARIES = libpars.a noinst_HEADERS = pars0grm.h diff --git a/innobase/que/Makefile.am b/innobase/que/Makefile.am index b74d4dbf6a0..d9c046b4f4c 100644 --- a/innobase/que/Makefile.am +++ b/innobase/que/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libque.a +noinst_LIBRARIES = libque.a libque_a_SOURCES = que0que.c diff --git a/innobase/read/Makefile.am b/innobase/read/Makefile.am index 16224f4f7f4..7edf2a5a2e1 100644 --- a/innobase/read/Makefile.am +++ b/innobase/read/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libread.a +noinst_LIBRARIES = libread.a libread_a_SOURCES = read0read.c diff --git a/innobase/rem/Makefile.am b/innobase/rem/Makefile.am index ef0cde9bd7a..e2b2fdaf669 100644 --- a/innobase/rem/Makefile.am +++ b/innobase/rem/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = librem.a +noinst_LIBRARIES = librem.a librem_a_SOURCES = rem0rec.c rem0cmp.c diff --git a/innobase/row/Makefile.am b/innobase/row/Makefile.am index e4fcbe8f715..bd09f9a237d 100644 --- a/innobase/row/Makefile.am +++ b/innobase/row/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = librow.a +noinst_LIBRARIES = librow.a librow_a_SOURCES = row0ins.c row0mysql.c row0purge.c row0row.c row0sel.c\ row0uins.c row0umod.c row0undo.c row0upd.c row0vers.c diff --git a/innobase/row/row0ins.c b/innobase/row/row0ins.c index 990ef99b2a4..3af9e1b752b 100644 --- a/innobase/row/row0ins.c +++ b/innobase/row/row0ins.c @@ -323,7 +323,7 @@ row_ins_clust_index_entry_by_modify( /************************************************************************* Returns TRUE if in a cascaded update/delete an ancestor node of node -updates table. */ +updates (not DELETE, but UPDATE) table. */ static ibool row_ins_cascade_ancestor_updates_table( @@ -341,7 +341,7 @@ row_ins_cascade_ancestor_updates_table( upd_node = parent; - if (upd_node->table == table) { + if (upd_node->table == table && upd_node->is_delete == FALSE) { return(TRUE); } @@ -438,6 +438,111 @@ row_ins_cascade_calc_update_vec( } /************************************************************************* +Reports a foreign key error associated with an update or a delete of a +parent table index entry. */ +static +void +row_ins_foreign_report_err( +/*=======================*/ + char* errstr, /* in: error string from the viewpoint + of the parent table */ + que_thr_t* thr, /* in: query thread whose run_node + is an update node */ + dict_foreign_t* foreign, /* in: foreign key constraint */ + rec_t* rec, /* in: a matching index record in the + child table */ + dtuple_t* entry) /* in: index entry in the parent + table */ +{ + char* buf = dict_foreign_err_buf; + + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), " Transaction:\n"); + trx_print(buf + strlen(buf), thr_get_trx(thr)); + + sprintf(buf + strlen(buf), +"Foreign key constraint fails for table %.500s:\n", + foreign->foreign_table_name); + dict_print_info_on_foreign_key_in_create_format( + foreign, buf + strlen(buf)); + sprintf(buf + strlen(buf), "\n%s", errstr); + sprintf(buf + strlen(buf), +" in parent table, in index %.500s tuple:\n", + foreign->referenced_index->name); + if (entry) { + dtuple_sprintf(buf + strlen(buf), 1000, entry); + } + sprintf(buf + strlen(buf), +"\nBut in child table %.500s, in index %.500s, there is a record:\n", + foreign->foreign_table_name, foreign->foreign_index->name); + if (rec) { + rec_sprintf(buf + strlen(buf), 1000, rec); + } + sprintf(buf + strlen(buf), "\n"); + + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + + mutex_exit(&dict_foreign_err_mutex); +} + +/************************************************************************* +Reports a foreign key error to dict_foreign_err_buf when we are trying +to add an index entry to a child table. Note that the adding may be the result +of an update, too. */ +static +void +row_ins_foreign_report_add_err( +/*===========================*/ + que_thr_t* thr, /* in: query thread whose run_node + is an insert node */ + dict_foreign_t* foreign, /* in: foreign key constraint */ + rec_t* rec, /* in: a record in the parent table: + it does not match entry because we + have an error! */ + dtuple_t* entry) /* in: index entry to insert in the + child table */ +{ + char* buf = dict_foreign_err_buf; + + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), " Transaction:\n"); + trx_print(buf + strlen(buf), thr_get_trx(thr)); + sprintf(buf + strlen(buf), +"Foreign key constraint fails for table %.500s:\n", + foreign->foreign_table_name); + dict_print_info_on_foreign_key_in_create_format( + foreign, buf + strlen(buf)); + sprintf(buf + strlen(buf), +"\nTrying to add in child table, in index %.500s tuple:\n", + foreign->foreign_index->name); + if (entry) { + dtuple_sprintf(buf + strlen(buf), 1000, entry); + } + sprintf(buf + strlen(buf), +"\nBut in parent table %.500s, in index %.500s,\n" +"the closest match we can find is record:\n", + foreign->referenced_table_name, + foreign->referenced_index->name); + if (rec && page_rec_is_supremum(rec)) { + /* If the cursor ended on a supremum record, it is better + to report the previous record in the error message, so that + the user gets a more descriptive error message. */ + rec = page_rec_get_prev(rec); + } + + if (rec) { + rec_sprintf(buf + strlen(buf), 1000, rec); + } + sprintf(buf + strlen(buf), "\n"); + + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + + mutex_exit(&dict_foreign_err_mutex); +} + +/************************************************************************* Perform referential actions or checks when a parent row is deleted or updated and the constraint had an ON DELETE or ON UPDATE condition which was not RESTRICT. */ @@ -453,6 +558,8 @@ row_ins_foreign_check_on_constraint( type is != 0 */ btr_pcur_t* pcur, /* in: cursor placed on a matching index record in the child table */ + dtuple_t* entry, /* in: index entry in the parent + table */ mtr_t* mtr) /* in: mtr holding the latch of pcur page */ { @@ -506,6 +613,10 @@ row_ins_foreign_check_on_constraint( return(DB_SUCCESS); } + row_ins_foreign_report_err((char*)"Trying to delete", + thr, foreign, + btr_pcur_get_rec(pcur), entry); + return(DB_ROW_IS_REFERENCED); } @@ -523,6 +634,10 @@ row_ins_foreign_check_on_constraint( return(DB_SUCCESS); } + row_ins_foreign_report_err((char*)"Trying to update", + thr, foreign, + btr_pcur_get_rec(pcur), entry); + return(DB_ROW_IS_REFERENCED); } @@ -563,14 +678,13 @@ row_ins_foreign_check_on_constraint( } } - /* We do not allow cyclic cascaded updating of the same - table. Check that we are not updating the same table which - is already being modified in this cascade chain. We have to - check this because the modification of the indexes of a - 'parent' table may still be incomplete, and we must avoid - seeing the indexes of the parent table in an inconsistent - state! In this way we also prevent possible infinite - update loops caused by cyclic cascaded updates. */ + /* We do not allow cyclic cascaded updating (DELETE is allowed, + but not UPDATE) of the same table, as this can lead to an infinite + cycle. Check that we are not updating the same table which is + already being modified in this cascade chain. We have to check + this also because the modification of the indexes of a 'parent' + table may still be incomplete, and we must avoid seeing the indexes + of the parent table in an inconsistent state! */ if (!cascade->is_delete && row_ins_cascade_ancestor_updates_table(cascade, table)) { @@ -580,6 +694,10 @@ row_ins_foreign_check_on_constraint( err = DB_ROW_IS_REFERENCED; + row_ins_foreign_report_err( +(char*)"Trying an update, possibly causing a cyclic cascaded update\n" +"in the child table,", thr, foreign, btr_pcur_get_rec(pcur), entry); + goto nonstandard_exit_func; } @@ -809,11 +927,10 @@ row_ins_check_foreign_constraint( dictionary cache if they exist at all */ dict_table_t* table, /* in: if check_ref is TRUE, then the foreign table, else the referenced table */ - dict_index_t* index __attribute__((unused)),/* in: index in table */ dtuple_t* entry, /* in: index entry for index */ que_thr_t* thr) /* in: query thread */ { - upd_node_t* upd_node; + upd_node_t* upd_node; dict_table_t* check_table; dict_index_t* check_index; ulint n_fields_cmp; @@ -824,6 +941,7 @@ row_ins_check_foreign_constraint( int cmp; ulint err; ulint i; + char* buf = dict_foreign_err_buf; mtr_t mtr; run_again: @@ -884,6 +1002,25 @@ run_again: if (check_table == NULL) { if (check_ref) { + mutex_enter(&dict_foreign_err_mutex); + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), " Transaction:\n"); + trx_print(buf + strlen(buf), thr_get_trx(thr)); + sprintf(buf + strlen(buf), +"Foreign key constraint fails for table %.500s:\n", + foreign->foreign_table_name); + dict_print_info_on_foreign_key_in_create_format( + foreign, buf + strlen(buf)); + sprintf(buf + strlen(buf), +"\nTrying to add to index %.500s tuple:\n", foreign->foreign_index->name); + dtuple_sprintf(buf + strlen(buf), 1000, entry); + sprintf(buf + strlen(buf), +"\nBut the parent table %.500s does not currently exist!\n", + foreign->referenced_table_name); + + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + mutex_exit(&dict_foreign_err_mutex); + return(DB_NO_REFERENCED_ROW); } @@ -949,7 +1086,8 @@ run_again: if (cmp == 0) { if (rec_get_deleted_flag(rec)) { - err = row_ins_set_shared_rec_lock(LOCK_ORDINARY, + err = row_ins_set_shared_rec_lock( + LOCK_ORDINARY, rec, check_index, thr); if (err != DB_SUCCESS) { @@ -989,13 +1127,17 @@ run_again: err = row_ins_foreign_check_on_constraint( - thr, foreign, &pcur, &mtr); - + thr, foreign, &pcur, entry, + &mtr); if (err != DB_SUCCESS) { break; } } else { + row_ins_foreign_report_err( + (char*)"Trying to delete or update", + thr, foreign, rec, entry); + err = DB_ROW_IS_REFERENCED; break; } @@ -1012,6 +1154,8 @@ run_again: if (check_ref) { err = DB_NO_REFERENCED_ROW; + row_ins_foreign_report_add_err( + thr, foreign, rec, entry); } else { err = DB_SUCCESS; } @@ -1025,6 +1169,9 @@ next_rec: if (!moved) { if (check_ref) { + rec = btr_pcur_get_rec(&pcur); + row_ins_foreign_report_add_err( + thr, foreign, rec, entry); err = DB_NO_REFERENCED_ROW; } else { err = DB_SUCCESS; @@ -1100,7 +1247,7 @@ row_ins_check_foreign_constraints( } err = row_ins_check_foreign_constraint(TRUE, foreign, - table, index, entry, thr); + table, entry, thr); if (got_s_lock) { row_mysql_unfreeze_data_dictionary(trx); } @@ -1116,6 +1263,48 @@ row_ins_check_foreign_constraints( return(DB_SUCCESS); } +/************************************************************************* +Reports a UNIQUE key error to dict_unique_err_buf so that SHOW INNODB +STATUS can print it. */ +static +void +row_ins_unique_report_err( +/*======================*/ + que_thr_t* thr, /* in: query thread */ + rec_t* rec, /* in: a record in the index */ + dtuple_t* entry, /* in: index entry to insert in the index */ + dict_index_t* index) /* in: index */ +{ + char* buf = dict_unique_err_buf; + + /* The foreign err mutex protects also dict_unique_err_buf */ + + mutex_enter(&dict_foreign_err_mutex); + + ut_sprintf_timestamp(buf); + sprintf(buf + strlen(buf), " Transaction:\n"); + trx_print(buf + strlen(buf), thr_get_trx(thr)); + + sprintf(buf + strlen(buf), +"Unique key constraint fails for table %.500s.\n", index->table_name); + sprintf(buf + strlen(buf), +"Trying to add in index %.500s (%lu fields unique) tuple:\n", index->name, + dict_index_get_n_unique(index)); + + dtuple_sprintf(buf + strlen(buf), 1000, entry); + + sprintf(buf + strlen(buf), +"\nBut there is already a record:\n"); + + rec_sprintf(buf + strlen(buf), 1000, rec); + + sprintf(buf + strlen(buf), "\n"); + + ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN); + + mutex_exit(&dict_foreign_err_mutex); +} + /******************************************************************* Checks if a unique key violation to rec would occur at the index entry insert. */ @@ -1246,10 +1435,8 @@ row_ins_scan_sec_index_for_duplicate( if (cmp == 0) { if (row_ins_dupl_error_with_rec(rec, entry, index)) { - /* printf("Duplicate key in index %s\n", - index->name); - dtuple_print(entry); */ - + row_ins_unique_report_err(thr, rec, entry, + index); err = DB_DUPLICATE_KEY; thr_get_trx(thr)->error_info = index; @@ -1344,7 +1531,8 @@ row_ins_duplicate_error_in_clust( if (row_ins_dupl_error_with_rec(rec, entry, cursor->index)) { trx->error_info = cursor->index; - + row_ins_unique_report_err(thr, rec, entry, + cursor->index); return(DB_DUPLICATE_KEY); } } @@ -1368,6 +1556,8 @@ row_ins_duplicate_error_in_clust( cursor->index)) { trx->error_info = cursor->index; + row_ins_unique_report_err(thr, rec, entry, + cursor->index); return(DB_DUPLICATE_KEY); } } diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index 1bb33551da8..6d1f6f6e40e 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -6,7 +6,7 @@ Contains also create table and other data dictionary operations. Created 9/17/2000 Heikki Tuuri *******************************************************/ - + #include "row0mysql.h" #ifdef UNIV_NONINL @@ -289,6 +289,17 @@ handle_new_error: "InnoDB: my.cnf and restart the database.\n"); exit(1); + } else if (err == DB_CORRUPTION) { + + fprintf(stderr, + "InnoDB: We detected index corruption in an InnoDB type table.\n" + "InnoDB: You have to dump + drop + reimport the table or, in\n" + "InnoDB: a case of widespread corruption, dump all InnoDB\n" + "InnoDB: tables and recreate the whole InnoDB tablespace.\n" + "InnoDB: If the mysqld server crashes after the startup or when\n" + "InnoDB: you dump the tables, look at section 6.1 of\n" + "InnoDB: http://www.innodb.com/ibman.html for help.\n"); + } else { fprintf(stderr, "InnoDB: unknown error code %lu\n", err); ut_a(0); @@ -337,6 +348,9 @@ row_create_prebuilt( prebuilt->mysql_has_locked = FALSE; prebuilt->index = NULL; + + prebuilt->used_in_HANDLER = FALSE; + prebuilt->n_template = 0; prebuilt->mysql_template = NULL; @@ -1169,7 +1183,7 @@ row_mysql_recover_tmp_table( return(DB_ERROR); } - if (0 == ut_memcmp(ptr, "/rsql", 5)) { + if (0 == ut_memcmp(ptr, (char*)"/rsql", 5)) { ptr++; *ptr = '#'; @@ -1293,10 +1307,10 @@ row_create_table_for_mysql( } trx->op_info = (char *) "creating table"; - - if (0 == ut_strcmp(table->name, "mysql/host") - || 0 == ut_strcmp(table->name, "mysql/user") - || 0 == ut_strcmp(table->name, "mysql/db")) { + + if (0 == ut_strcmp(table->name, (char*)"mysql/host") + || 0 == ut_strcmp(table->name, (char*)"mysql/user") + || 0 == ut_strcmp(table->name, (char*)"mysql/db")) { fprintf(stderr, "InnoDB: Error: trying to create a MySQL system table %s of type InnoDB.\n" @@ -1316,7 +1330,7 @@ row_create_table_for_mysql( if (namelen >= keywordlen && 0 == ut_memcmp(table->name + namelen - keywordlen, - "_recover_innodb_tmp_table", keywordlen)) { + (char*)"_recover_innodb_tmp_table", keywordlen)) { /* MySQL prevents accessing of tables whose name begins with #sql, that is temporary tables. If mysqld crashes in @@ -1384,7 +1398,7 @@ row_create_table_for_mysql( if (namelen >= keywordlen && 0 == ut_memcmp(table->name + namelen - keywordlen, - "innodb_mem_validate", keywordlen)) { + (char*)"innodb_mem_validate", keywordlen)) { /* We define here a debugging feature intended for developers */ @@ -1494,7 +1508,7 @@ row_create_index_for_mysql( if (namelen >= keywordlen && 0 == ut_memcmp( index->table_name + namelen - keywordlen, - "_recover_innodb_tmp_table", keywordlen)) { + (char*)"_recover_innodb_tmp_table", keywordlen)) { return(DB_SUCCESS); } @@ -1599,7 +1613,7 @@ row_table_add_foreign_constraints( if (namelen >= keywordlen && 0 == ut_memcmp( name + namelen - keywordlen, - "_recover_innodb_tmp_table", keywordlen)) { + (char*)"_recover_innodb_tmp_table", keywordlen)) { return(DB_SUCCESS); } @@ -1663,7 +1677,7 @@ row_drop_table_for_mysql_in_background( the InnoDB data dictionary get out-of-sync if the user runs with innodb_flush_log_at_trx_commit = 0 */ - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); trx_commit_for_mysql(trx); @@ -1821,7 +1835,6 @@ row_drop_table_for_mysql( ulint len; ulint namelen; ulint keywordlen; - ulint rounds = 0; ibool locked_dictionary = FALSE; char buf[10000]; @@ -2168,7 +2181,7 @@ row_is_mysql_tmp_table_name( ulint i; for (i = 0; i <= ut_strlen(name) - 5; i++) { - if (ut_memcmp(name + i, "/#sql", 5) == 0) { + if (ut_memcmp(name + i, (char*)"/#sql", 5) == 0) { return(TRUE); } @@ -2190,12 +2203,16 @@ row_rename_table_for_mysql( { dict_table_t* table; que_thr_t* thr; - que_t* graph; + que_t* graph = NULL; ulint err; char* str1; char* str2; char* str3; + mem_heap_t* heap = NULL; + char** constraints_to_drop = NULL; + ulint n_constraints_to_drop = 0; ulint len; + ulint i; char buf[10000]; ut_ad(trx->mysql_thread_id == os_thread_get_curr_id()); @@ -2213,10 +2230,10 @@ row_rename_table_for_mysql( trx_commit_for_mysql(trx); return(DB_ERROR); } - - if (0 == ut_strcmp(new_name, "mysql/host") - || 0 == ut_strcmp(new_name, "mysql/user") - || 0 == ut_strcmp(new_name, "mysql/db")) { + + if (0 == ut_strcmp(new_name, (char*)"mysql/host") + || 0 == ut_strcmp(new_name, (char*)"mysql/user") + || 0 == ut_strcmp(new_name, (char*)"mysql/db")) { fprintf(stderr, "InnoDB: Error: trying to create a MySQL system table %s of type InnoDB.\n" @@ -2230,6 +2247,19 @@ row_rename_table_for_mysql( trx->op_info = (char *) "renaming table"; trx_start_if_not_started(trx); + /* Serialize data dictionary operations with dictionary mutex: + no deadlocks can occur then in these operations */ + + row_mysql_lock_data_dictionary(trx); + + table = dict_table_get_low(old_name); + + if (!table) { + err = DB_TABLE_NOT_FOUND; + + goto funct_exit; + } + str1 = (char *) "PROCEDURE RENAME_TABLE_PROC () IS\n" "new_table_name CHAR;\n" @@ -2242,14 +2272,43 @@ row_rename_table_for_mysql( if (row_is_mysql_tmp_table_name(new_name)) { - /* We want to preserve the original foreign key - constraint definitions despite the name change */ + /* MySQL is doing an ALTER TABLE command and it renames the + original table to a temporary table name. We want to preserve + the original foreign key constraint definitions despite the + name change. An exception is those constraints for which + the ALTER TABLE contained DROP FOREIGN KEY <foreign key id>.*/ - str3 = (char*) - "';\n" - "UPDATE SYS_TABLES SET NAME = new_table_name\n" - "WHERE NAME = old_table_name;\n" - "END;\n"; + heap = mem_heap_create(100); + + err = dict_foreign_parse_drop_constraints(heap, trx, + table, + &n_constraints_to_drop, + &constraints_to_drop); + if (err != DB_SUCCESS) { + + goto funct_exit; + } + + str3 = mem_heap_alloc(heap, + 1000 + 500 * n_constraints_to_drop); + *str3 = '\0'; + sprintf(str3, + "';\n" + "UPDATE SYS_TABLES SET NAME = new_table_name\n" + "WHERE NAME = old_table_name;\n"); + + for (i = 0; i < n_constraints_to_drop; i++) { + sprintf(str3 + strlen(str3), + "DELETE FROM SYS_FOREIGN_COLS WHERE ID = '%s';\n" + "DELETE FROM SYS_FOREIGN WHERE ID = '%s';\n", + constraints_to_drop[i], + constraints_to_drop[i]); + } + + sprintf(str3 + strlen(str3), + "END;\n"); + + ut_a(strlen(str3) < 1000 + 500 * n_constraints_to_drop); } else { str3 = (char*) "';\n" @@ -2280,13 +2339,6 @@ row_rename_table_for_mysql( ut_memcpy(buf + len, str3, ut_strlen(str3) + 1); - /* Serialize data dictionary operations with dictionary mutex: - no deadlocks can occur then in these operations */ - - row_mysql_lock_data_dictionary(trx); - - table = dict_table_get_low(old_name); - graph = pars_sql(buf); ut_a(graph); @@ -2296,12 +2348,6 @@ row_rename_table_for_mysql( graph->fork_type = QUE_FORK_MYSQL_INTERFACE; - if (!table) { - err = DB_TABLE_NOT_FOUND; - - goto funct_exit; - } - ut_a(thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0)); que_run_threads(thr); @@ -2342,6 +2388,13 @@ row_rename_table_for_mysql( if (row_is_mysql_tmp_table_name(old_name)) { + /* MySQL is doing an ALTER TABLE command and it + renames the created temporary table to the name + of the original table. In the ALTER TABLE we maybe + created some FOREIGN KEY constraints for the temporary + table. But we want to load also the foreign key + constraint definitions for the original table name. */ + err = dict_load_foreigns(new_name); if (err != DB_SUCCESS) { @@ -2367,7 +2420,13 @@ row_rename_table_for_mysql( funct_exit: row_mysql_unlock_data_dictionary(trx); - que_graph_free(graph); + if (graph) { + que_graph_free(graph); + } + + if (heap) { + mem_heap_free(heap); + } trx_commit_for_mysql(trx); diff --git a/innobase/row/row0sel.c b/innobase/row/row0sel.c index fb508e7b1da..97a69f76eaa 100644 --- a/innobase/row/row0sel.c +++ b/innobase/row/row0sel.c @@ -2620,6 +2620,24 @@ row_search_for_mysql( printf("N tables locked %lu\n", trx->mysql_n_tables_locked); */ /*-------------------------------------------------------------*/ + /* PHASE 0: Release a possible s-latch we are holding on the + adaptive hash index latch if there is someone waiting behind */ + + if (trx->has_search_latch + && btr_search_latch.writer != RW_LOCK_NOT_LOCKED) { + + /* There is an x-latch request on the adaptive hash index: + release the s-latch to reduce starvation and wait for + BTR_SEA_TIMEOUT rounds before trying to keep it again over + calls from MySQL */ + + rw_lock_s_unlock(&btr_search_latch); + trx->has_search_latch = FALSE; + + trx->search_latch_timeout = BTR_SEA_TIMEOUT; + } + + /*-------------------------------------------------------------*/ /* PHASE 1: Try to pop the row from the prefetch cache */ if (direction == 0) { @@ -2685,16 +2703,31 @@ row_search_for_mysql( mode = pcur->search_mode; } + if ((direction == ROW_SEL_NEXT || direction == ROW_SEL_PREV) + && pcur->old_stored != BTR_PCUR_OLD_STORED) { + + /* MySQL sometimes seems to do fetch next or fetch prev even + if the search condition is unique; this can, for example, + happen with the HANDLER commands; we do not always store the + pcur position in this case, so we cannot restore cursor + position, and must return immediately */ + + /* printf("%s record not found 1\n", index->name); */ + + trx->op_info = (char *) ""; + return(DB_RECORD_NOT_FOUND); + } + mtr_start(&mtr); /* In a search where at most one record in the index may match, we - can use a LOCK_REC_NOT_GAP type record lock when locking a non-delete + can use a LOCK_REC_NOT_GAP type record lock when locking a non-delete- marked matching record. - Note that in a unique secondary index there may be different delete + Note that in a unique secondary index there may be different delete- marked versions of a record where only the primary key values differ: thus in a secondary index we must use next-key locks when locking - delete marked records. */ + delete-marked records. */ if (match_mode == ROW_SEL_EXACT && index->type & DICT_UNIQUE @@ -2715,25 +2748,9 @@ row_search_for_mysql( if (unique_search && index->type & DICT_CLUSTERED && !prebuilt->templ_contains_blob + && !prebuilt->used_in_HANDLER && (prebuilt->mysql_row_len < UNIV_PAGE_SIZE / 8)) { - if (direction == ROW_SEL_NEXT) { - /* MySQL sometimes seems to do fetch next even - if the search condition is unique; we do not store - pcur position in this case, so we cannot - restore cursor position, and must return - immediately */ - - mtr_commit(&mtr); - - /* printf("%s record not found 1\n", index->name); */ - - trx->op_info = (char *) ""; - return(DB_RECORD_NOT_FOUND); - } - - ut_a(direction == 0); /* We cannot do fetch prev, as we have - not stored the cursor position */ mode = PAGE_CUR_GE; unique_search_from_clust_index = TRUE; @@ -2754,23 +2771,7 @@ row_search_for_mysql( NOT prepared to inserts interleaved with the SELECT, and if we try that, we can deadlock on the adaptive hash index semaphore! */ - - if (btr_search_latch.writer != RW_LOCK_NOT_LOCKED) { - /* There is an x-latch request: release - a possible s-latch to reduce starvation - and wait for BTR_SEA_TIMEOUT rounds before - trying to keep it again over calls from - MySQL */ - - if (trx->has_search_latch) { - rw_lock_s_unlock(&btr_search_latch); - trx->has_search_latch = FALSE; - } - trx->search_latch_timeout = BTR_SEA_TIMEOUT; - - goto no_shortcut; - } #ifndef UNIV_SEARCH_DEBUG if (!trx->has_search_latch) { rw_lock_s_lock(&btr_search_latch); @@ -2806,6 +2807,10 @@ row_search_for_mysql( } trx->op_info = (char *) ""; + + /* NOTE that we do NOT store the cursor + position */ + return(DB_SUCCESS); } else if (shortcut == SEL_EXHAUSTED) { @@ -2825,6 +2830,10 @@ row_search_for_mysql( } trx->op_info = (char *) ""; + + /* NOTE that we do NOT store the cursor + position */ + return(DB_RECORD_NOT_FOUND); } @@ -2833,7 +2842,6 @@ row_search_for_mysql( } } -no_shortcut: /*-------------------------------------------------------------*/ /* PHASE 3: Open or restore index cursor position */ @@ -3206,6 +3214,7 @@ rec_loop: && prebuilt->select_lock_type == LOCK_NONE && !prebuilt->templ_contains_blob && !prebuilt->clust_index_was_generated + && !prebuilt->used_in_HANDLER && prebuilt->template_type != ROW_MYSQL_DUMMY_TEMPLATE) { @@ -3214,7 +3223,9 @@ rec_loop: update, that is why we require ...lock_type == LOCK_NONE. Since we keep space in prebuilt only for the BLOBs of a single row, we cannot cache rows in the case there - are BLOBs in the fields to be fetched. */ + are BLOBs in the fields to be fetched. In HANDLER we do + not cache rows because there the cursor is a scrollable + cursor. */ row_sel_push_cache_row_for_mysql(prebuilt, rec); @@ -3243,11 +3254,16 @@ rec_loop: } } got_row: - /* TODO: should we in every case store the cursor position, even - if this is just a join, for example? */ + /* We have an optimization to save CPU time: if this is a consistent + read on a unique condition on the clustered index, then we do not + store the pcur position, because any fetch next or prev will anyway + return 'end of file'. An exception is the MySQL HANDLER command + where the user can move the cursor with PREV or NEXT even after + a unique search. */ if (!unique_search_from_clust_index - || prebuilt->select_lock_type == LOCK_X) { + || prebuilt->select_lock_type == LOCK_X + || prebuilt->used_in_HANDLER) { /* Inside an update always store the cursor position */ diff --git a/innobase/row/row0upd.c b/innobase/row/row0upd.c index 64569bf3f96..5fce1c1861b 100644 --- a/innobase/row/row0upd.c +++ b/innobase/row/row0upd.c @@ -218,7 +218,7 @@ row_upd_check_references_constraints( being dropped while the check is running. */ err = row_ins_check_foreign_constraint(FALSE, foreign, - table, index, entry, thr); + table, entry, thr); if (foreign->foreign_table) { mutex_enter(&(dict_sys->mutex)); diff --git a/innobase/srv/Makefile.am b/innobase/srv/Makefile.am index b4bdeb7c03b..752683b82b8 100644 --- a/innobase/srv/Makefile.am +++ b/innobase/srv/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libsrv.a +noinst_LIBRARIES = libsrv.a libsrv_a_SOURCES = srv0srv.c srv0que.c srv0start.c diff --git a/innobase/srv/srv0srv.c b/innobase/srv/srv0srv.c index af11516e9f0..7cd831fe239 100644 --- a/innobase/srv/srv0srv.c +++ b/innobase/srv/srv0srv.c @@ -162,6 +162,13 @@ char* srv_file_flush_method_str = NULL; ulint srv_unix_file_flush_method = SRV_UNIX_FDATASYNC; ulint srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; +/* The InnoDB main thread tries to keep the ratio of modified pages +in the buffer pool to all database pages in the buffer pool smaller than +the following number. But it is not guaranteed that the value stays below +that during a time of heavy update/insert activity. */ + +ulint srv_max_buf_pool_modified_pct = 90; + /* If the following is != 0 we do not allow inserts etc. This protects the user from forgetting the innodb_force_recovery keyword to my.cnf */ @@ -1881,11 +1888,11 @@ retry: /* Go to wait for the event; when a thread leaves InnoDB it will release this thread */ - trx->op_info = "waiting in InnoDB queue"; + trx->op_info = (char*)"waiting in InnoDB queue"; os_event_wait(slot->event); - trx->op_info = ""; + trx->op_info = (char*)""; os_fast_mutex_lock(&srv_conc_mutex); @@ -2368,12 +2375,35 @@ srv_sprintf_innodb_monitor( buf = buf + strlen(buf); ut_a(buf < buf_end + 1500); - buf += sprintf(buf, "------------\n" - "TRANSACTIONS\n" - "------------\n"); + if (*dict_foreign_err_buf != '\0') { + buf += sprintf(buf, + "------------------------\n" + "LATEST FOREIGN KEY ERROR\n" + "------------------------\n"); + + if (buf_end - buf > 6000) { + buf+= sprintf(buf, "%.4000s", dict_foreign_err_buf); + } + } + + ut_a(buf < buf_end + 1500); + + if (*dict_unique_err_buf != '\0') { + buf += sprintf(buf, +"---------------------------------------------------------------\n" +"LATEST UNIQUE KEY ERROR (is masked in REPLACE or INSERT IGNORE)\n" +"---------------------------------------------------------------\n"); + + if (buf_end - buf > 6000) { + buf+= sprintf(buf, "%.4000s", dict_unique_err_buf); + } + } + + ut_a(buf < buf_end + 1500); + lock_print_info(buf, buf_end); buf = buf + strlen(buf); - + buf += sprintf(buf, "--------\n" "FILE I/O\n" "--------\n"); @@ -2777,6 +2807,7 @@ srv_master_thread( ulint n_ios_old; ulint n_ios_very_old; ulint n_pend_ios; + ibool skip_sleep = FALSE; ulint i; UT_NOT_USED(arg); @@ -2794,24 +2825,42 @@ srv_master_thread( os_event_set(srv_sys->operational); loop: + /*****************************************************************/ + /* ---- When there is database activity by users, we cycle in this + loop */ + srv_main_thread_op_info = (char*) "reserving kernel mutex"; n_ios_very_old = log_sys->n_log_ios + buf_pool->n_pages_read + buf_pool->n_pages_written; mutex_enter(&kernel_mutex); + /* Store the user activity counter at the start of this loop */ old_activity_count = srv_activity_count; mutex_exit(&kernel_mutex); - /* We run purge and a batch of ibuf_contract every 10 seconds, even - if the server were active: */ + if (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND) { + + goto suspend_thread; + } + + /* ---- We run the following loop approximately once per second + when there is database activity */ + + skip_sleep = FALSE; for (i = 0; i < 10; i++) { n_ios_old = log_sys->n_log_ios + buf_pool->n_pages_read + buf_pool->n_pages_written; srv_main_thread_op_info = (char*)"sleeping"; - os_thread_sleep(1000000); + + if (!skip_sleep) { + + os_thread_sleep(1000000); + } + + skip_sleep = FALSE; /* ALTER TABLE in MySQL requires on Unix that the table handler can drop tables lazily after there no longer are SELECT @@ -2824,9 +2873,9 @@ loop: srv_main_thread_op_info = (char*)""; - if (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND) { + if (srv_fast_shutdown && srv_shutdown_state > 0) { - goto suspend_thread; + goto background_loop; } /* We flush the log once in a second even if no commit @@ -2834,10 +2883,9 @@ loop: at transaction commit */ srv_main_thread_op_info = (char*)"flushing log"; - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); - log_flush_to_disk(); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); - /* If there were less than 10 i/os during the + /* If there were less than 5 i/os during the one second sleep, we assume that there is free disk i/o capacity available, and it makes sense to do an insert buffer merge. */ @@ -2846,35 +2894,45 @@ loop: + log_sys->n_pending_writes; n_ios = log_sys->n_log_ios + buf_pool->n_pages_read + buf_pool->n_pages_written; - if (n_pend_ios < 3 && (n_ios - n_ios_old < 10)) { + if (n_pend_ios < 3 && (n_ios - n_ios_old < 5)) { srv_main_thread_op_info = (char*)"doing insert buffer merge"; ibuf_contract_for_n_pages(TRUE, 5); srv_main_thread_op_info = (char*)"flushing log"; - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); - log_flush_to_disk(); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, + TRUE); } - - if (srv_fast_shutdown && srv_shutdown_state > 0) { - goto background_loop; + if (buf_get_modified_ratio_pct() > + srv_max_buf_pool_modified_pct) { + + /* Try to keep the number of modified pages in the + buffer pool under the limit wished by the user */ + + n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100, + ut_dulint_max); + + /* If we had to do the flush, it may have taken + even more than 1 second, and also, there may be more + to flush. Do not sleep 1 second during the next + iteration of this loop. */ + + skip_sleep = TRUE; } if (srv_activity_count == old_activity_count) { - if (srv_print_thread_releases) { - printf("Master thread wakes up!\n"); - } + /* There is no user activity at the moment, go to + the background loop */ goto background_loop; } } - if (srv_print_thread_releases) { - printf("Master thread wakes up!\n"); - } + /* ---- We perform the following code approximately once per + 10 seconds when there is database activity */ #ifdef MEM_PERIODIC_CHECK /* Check magic numbers of every allocated mem block once in 10 @@ -2883,7 +2941,7 @@ loop: #endif /* If there were less than 200 i/os during the 10 second period, we assume that there is free disk i/o capacity available, and it - makes sense to do a buffer pool flush. */ + makes sense to flush 100 pages. */ n_pend_ios = buf_get_n_pending_ios() + log_sys->n_pending_writes; n_ios = log_sys->n_log_ios + buf_pool->n_pages_read @@ -2891,11 +2949,10 @@ loop: if (n_pend_ios < 3 && (n_ios - n_ios_very_old < 200)) { srv_main_thread_op_info = (char*) "flushing buffer pool pages"; - buf_flush_batch(BUF_FLUSH_LIST, 50, ut_dulint_max); + buf_flush_batch(BUF_FLUSH_LIST, 100, ut_dulint_max); srv_main_thread_op_info = (char*) "flushing log"; - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); - log_flush_to_disk(); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); } /* We run a batch of insert buffer merge every 10 seconds, @@ -2905,8 +2962,7 @@ loop: ibuf_contract_for_n_pages(TRUE, 5); srv_main_thread_op_info = (char*)"flushing log"; - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); - log_flush_to_disk(); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); /* We run a full purge every 10 seconds, even if the server were active */ @@ -2930,27 +2986,32 @@ loop: if (difftime(current_time, last_flush_time) > 1) { srv_main_thread_op_info = (char*) "flushing log"; - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); - log_flush_to_disk(); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, + TRUE); last_flush_time = current_time; } } + + srv_main_thread_op_info = (char*)"flushing buffer pool pages"; -background_loop: - /* In this loop we run background operations when the server - is quiet and we also come here about once in 10 seconds */ + /* Flush a few oldest pages to make a new checkpoint younger */ - srv_main_thread_op_info = (char*)"doing background drop tables"; + if (buf_get_modified_ratio_pct() > 70) { - n_tables_to_drop = row_drop_tables_for_mysql_in_background(); + /* If there are lots of modified pages in the buffer pool + (> 70 %), we assume we can afford reserving the disk(s) for + the time it requires to flush 100 pages */ - srv_main_thread_op_info = (char*)""; - - srv_main_thread_op_info = (char*)"flushing buffer pool pages"; - - /* Flush a few oldest pages to make the checkpoint younger */ + n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100, + ut_dulint_max); + } else { + /* Otherwise, we only flush a small number of pages so that + we do not unnecessarily use much disk i/o capacity from + other work */ - n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 10, ut_dulint_max); + n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 10, + ut_dulint_max); + } srv_main_thread_op_info = (char*)"making checkpoint"; @@ -2961,16 +3022,31 @@ background_loop: srv_main_thread_op_info = (char*)"reserving kernel mutex"; mutex_enter(&kernel_mutex); + + /* ---- When there is database activity, we jump from here back to + the start of loop */ + if (srv_activity_count != old_activity_count) { mutex_exit(&kernel_mutex); goto loop; } - old_activity_count = srv_activity_count; + mutex_exit(&kernel_mutex); + /* If the database is quiet, we enter the background loop */ + + /*****************************************************************/ +background_loop: + /* ---- In this loop we run background operations when the server + is quiet from user activity */ + /* The server has been quiet for a while: start running background operations */ + srv_main_thread_op_info = (char*)"doing background drop tables"; + + n_tables_to_drop = row_drop_tables_for_mysql_in_background(); + srv_main_thread_op_info = (char*)"purging"; if (srv_fast_shutdown && srv_shutdown_state > 0) { @@ -3005,6 +3081,7 @@ background_loop: } mutex_exit(&kernel_mutex); +flush_loop: srv_main_thread_op_info = (char*)"flushing buffer pool pages"; n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100, ut_dulint_max); @@ -3017,13 +3094,22 @@ background_loop: } mutex_exit(&kernel_mutex); - srv_main_thread_op_info = (char*) "waiting for buffer pool flush to end"; + srv_main_thread_op_info = + (char*) "waiting for buffer pool flush to end"; buf_flush_wait_batch_end(BUF_FLUSH_LIST); srv_main_thread_op_info = (char*)"making checkpoint"; log_checkpoint(TRUE, FALSE); + if (buf_get_modified_ratio_pct() > srv_max_buf_pool_modified_pct) { + + /* Try to keep the number of modified pages in the + buffer pool under the limit wished by the user */ + + goto flush_loop; + } + srv_main_thread_op_info = (char*)"reserving kernel mutex"; mutex_enter(&kernel_mutex); @@ -3038,15 +3124,24 @@ background_loop: log_archive_do(FALSE, &n_bytes_archived); + /* Keep looping in the background loop if still work to do */ + if (srv_fast_shutdown && srv_shutdown_state > 0) { if (n_tables_to_drop + n_pages_flushed + n_bytes_archived != 0) { + /* If we are doing a fast shutdown (= the default) + we do not do purge or insert buffer merge. But we + flush the buffer pool completely to disk. */ + goto background_loop; } } else if (n_tables_to_drop + - n_pages_purged + n_bytes_merged + n_pages_flushed + n_pages_purged + n_bytes_merged + n_pages_flushed + n_bytes_archived != 0) { + /* In a 'slow' shutdown we run purge and the insert buffer + merge to completion */ + goto background_loop; } @@ -3078,6 +3173,9 @@ suspend_thread: os_event_wait(event); + /* When there is user activity, InnoDB will set the event and the main + thread goes back to loop: */ + goto loop; #ifndef __WIN__ diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c index 33d4a30e227..536aa5b67e4 100644 --- a/innobase/srv/srv0start.c +++ b/innobase/srv/srv0start.c @@ -161,13 +161,13 @@ srv_parse_data_file_paths_and_sizes( } if (strlen(str) >= ut_strlen(":autoextend") - && 0 == ut_memcmp(str, ":autoextend", + && 0 == ut_memcmp(str, (char*)":autoextend", ut_strlen(":autoextend"))) { str += ut_strlen(":autoextend"); if (strlen(str) >= ut_strlen(":max:") - && 0 == ut_memcmp(str, ":max:", + && 0 == ut_memcmp(str, (char*)":max:", ut_strlen(":max:"))) { str += ut_strlen(":max:"); @@ -265,7 +265,7 @@ srv_parse_data_file_paths_and_sizes( (*data_file_sizes)[i] = size; if (strlen(str) >= ut_strlen(":autoextend") - && 0 == ut_memcmp(str, ":autoextend", + && 0 == ut_memcmp(str, (char*)":autoextend", ut_strlen(":autoextend"))) { *is_auto_extending = TRUE; @@ -273,7 +273,7 @@ srv_parse_data_file_paths_and_sizes( str += ut_strlen(":autoextend"); if (strlen(str) >= ut_strlen(":max:") - && 0 == ut_memcmp(str, ":max:", + && 0 == ut_memcmp(str, (char*)":max:", ut_strlen(":max:"))) { str += ut_strlen(":max:"); @@ -864,6 +864,7 @@ open_or_create_data_files( return(DB_SUCCESS); } +#ifdef notdefined /********************************************************************* This thread is used to measure contention of latches. */ static @@ -935,6 +936,7 @@ test_measure_cont( return(0); } +#endif /******************************************************************** Starts InnoDB and creates a new database if database files @@ -1053,20 +1055,24 @@ innobase_start_or_create_for_mysql(void) srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; #ifndef __WIN__ - } else if (0 == ut_strcmp(srv_file_flush_method_str, "fdatasync")) { + } else if (0 == ut_strcmp(srv_file_flush_method_str, + (char*)"fdatasync")) { srv_unix_file_flush_method = SRV_UNIX_FDATASYNC; - } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) { + } else if (0 == ut_strcmp(srv_file_flush_method_str, + (char*)"O_DSYNC")) { srv_unix_file_flush_method = SRV_UNIX_O_DSYNC; } else if (0 == ut_strcmp(srv_file_flush_method_str, - "littlesync")) { + (char*)"littlesync")) { srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC; - } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) { + } else if (0 == ut_strcmp(srv_file_flush_method_str, + (char*)"nosync")) { srv_unix_file_flush_method = SRV_UNIX_NOSYNC; #else - } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) { + } else if (0 == ut_strcmp(srv_file_flush_method_str, + (char*)"normal")) { srv_win_file_flush_method = SRV_WIN_IO_NORMAL; os_aio_use_native_aio = FALSE; @@ -1196,7 +1202,14 @@ innobase_start_or_create_for_mysql(void) &max_flushed_lsn, &max_arch_log_no, &sum_of_new_sizes); if (err != DB_SUCCESS) { - fprintf(stderr, "InnoDB: Could not open data files\n"); + fprintf(stderr, +"InnoDB: Could not open or create data files.\n" +"InnoDB: If you tried to add new data files, and it failed here,\n" +"InnoDB: you should now edit innodb_data_file_path in my.cnf back\n" +"InnoDB: to what it was, and remove the new ibdata files InnoDB created\n" +"InnoDB: in this failed attempt. InnoDB only wrote those files full of\n" +"InnoDB: zeros, but did not yet use them in any way. But be careful: do not\n" +"InnoDB: remove old data files which contain your precious data!\n"); return((int) err); } @@ -1207,7 +1220,10 @@ innobase_start_or_create_for_mysql(void) and restore them from the doublewrite buffer if possible */ - trx_sys_doublewrite_restore_corrupt_pages(); + if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) { + + trx_sys_doublewrite_restore_corrupt_pages(); + } } srv_normalize_path_for_win(srv_arch_dir); @@ -1478,7 +1494,9 @@ innobase_start_or_create_for_mysql(void) fprintf(stderr, "InnoDB: !!! innodb_force_recovery is set to %lu !!!\n", srv_force_recovery); - } + } + + fflush(stderr); return((int) DB_SUCCESS); } diff --git a/innobase/sync/Makefile.am b/innobase/sync/Makefile.am index 7504525bf84..4acd4516e35 100644 --- a/innobase/sync/Makefile.am +++ b/innobase/sync/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libsync.a +noinst_LIBRARIES = libsync.a libsync_a_SOURCES = sync0arr.c sync0ipm.c sync0rw.c sync0sync.c diff --git a/innobase/thr/Makefile.am b/innobase/thr/Makefile.am index 5f42138e734..62c39492c07 100644 --- a/innobase/thr/Makefile.am +++ b/innobase/thr/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libthr.a +noinst_LIBRARIES = libthr.a libthr_a_SOURCES = thr0loc.c diff --git a/innobase/trx/Makefile.am b/innobase/trx/Makefile.am index 63b2c52da33..9e2b3c398e3 100644 --- a/innobase/trx/Makefile.am +++ b/innobase/trx/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libtrx.a +noinst_LIBRARIES = libtrx.a libtrx_a_SOURCES = trx0purge.c trx0rec.c trx0roll.c trx0rseg.c\ trx0sys.c trx0trx.c trx0undo.c diff --git a/innobase/trx/trx0sys.c b/innobase/trx/trx0sys.c index 1ae9f00ae1f..b9e4a9fea4b 100644 --- a/innobase/trx/trx0sys.c +++ b/innobase/trx/trx0sys.c @@ -340,7 +340,6 @@ trx_sys_doublewrite_restore_corrupt_pages(void) /* It is an unwritten doublewrite buffer page: do nothing */ - } else { /* Read in the actual page from the data files */ @@ -357,9 +356,19 @@ trx_sys_doublewrite_restore_corrupt_pages(void) "InnoDB: Trying to recover it from the doublewrite buffer.\n"); if (buf_page_is_corrupted(page)) { + fprintf(stderr, + "InnoDB: Dump of the page:\n"); + buf_page_print(read_buf); + fprintf(stderr, + "InnoDB: Dump of corresponding page in doublewrite buffer:\n"); + buf_page_print(page); + fprintf(stderr, "InnoDB: Also the page in the doublewrite buffer is corrupt.\n" - "InnoDB: Cannot continue operation.\n"); + "InnoDB: Cannot continue operation.\n" + "InnoDB: You can try to recover the database with the my.cnf\n" + "InnoDB: option:\n" + "InnoDB: set-variable=innodb_force_recovery=6\n"); exit(1); } diff --git a/innobase/trx/trx0trx.c b/innobase/trx/trx0trx.c index 5ac49397c90..5753b5b338e 100644 --- a/innobase/trx/trx0trx.c +++ b/innobase/trx/trx0trx.c @@ -89,6 +89,8 @@ trx_create( trx->check_foreigns = TRUE; trx->check_unique_secondary = TRUE; + trx->flush_log_later = FALSE; + trx->dict_operation = FALSE; trx->mysql_thd = NULL; @@ -102,8 +104,6 @@ trx_create( trx->mysql_master_log_file_name = ""; trx->mysql_master_log_pos = 0; - trx->ignore_duplicates_in_insert = FALSE; - mutex_create(&(trx->undo_mutex)); mutex_set_level(&(trx->undo_mutex), SYNC_TRX_UNDO); @@ -782,13 +782,26 @@ trx_commit_off_kernel( /*-------------------------------------*/ - /* Most MySQL users run with srv_flush_.. set to FALSE: */ + /* Most MySQL users run with srv_flush_.. set to 0: */ - if (srv_flush_log_at_trx_commit) { - - log_flush_up_to(lsn, LOG_WAIT_ONE_GROUP); + if (srv_flush_log_at_trx_commit != 0) { + if (srv_unix_file_flush_method != SRV_UNIX_NOSYNC + && srv_flush_log_at_trx_commit != 2 + && !trx->flush_log_later) { + + /* Write the log to the log files AND flush + them to disk */ + + log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, TRUE); + } else { + /* Write the log but do not flush it to disk */ + + log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, FALSE); + } } + trx->commit_lsn = lsn; + /*-------------------------------------*/ mutex_enter(&kernel_mutex); @@ -1470,6 +1483,33 @@ trx_commit_for_mysql( } /************************************************************************** +If required, flushes the log to disk if we called trx_commit_for_mysql() +with trx->flush_log_later == TRUE. */ + +ulint +trx_commit_complete_for_mysql( +/*==========================*/ + /* out: 0 or error number */ + trx_t* trx) /* in: trx handle */ +{ + ut_a(trx); + + if (srv_flush_log_at_trx_commit == 1 + && srv_unix_file_flush_method != SRV_UNIX_NOSYNC) { + + trx->op_info = (char *) "flushing log"; + + /* Flush the log files to disk */ + + log_write_up_to(trx->commit_lsn, LOG_WAIT_ONE_GROUP, TRUE); + + trx->op_info = (char *) ""; + } + + return(0); +} + +/************************************************************************** Marks the latest SQL statement ended. */ void diff --git a/innobase/usr/Makefile.am b/innobase/usr/Makefile.am index a71d0d41ac0..bdcc832a76e 100644 --- a/innobase/usr/Makefile.am +++ b/innobase/usr/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libusr.a +noinst_LIBRARIES = libusr.a libusr_a_SOURCES = usr0sess.c diff --git a/innobase/ut/Makefile.am b/innobase/ut/Makefile.am index de3cf41b767..2fdbb99e0f3 100644 --- a/innobase/ut/Makefile.am +++ b/innobase/ut/Makefile.am @@ -17,7 +17,7 @@ include ../include/Makefile.i -libs_LIBRARIES = libut.a +noinst_LIBRARIES = libut.a libut_a_SOURCES = ut0byte.c ut0dbg.c ut0mem.c ut0rnd.c ut0ut.c diff --git a/innobase/ut/ut0ut.c b/innobase/ut/ut0ut.c index 31a137b5fac..c503cda54b9 100644 --- a/innobase/ut/ut0ut.c +++ b/innobase/ut/ut0ut.c @@ -206,7 +206,7 @@ ut_get_year_month_day( cal_tm_ptr = localtime(&tm); - *year = (ulint)cal_tm_ptr->tm_year; + *year = (ulint)cal_tm_ptr->tm_year + 1900; *month = (ulint)cal_tm_ptr->tm_mon + 1; *day = (ulint)cal_tm_ptr->tm_mday; #endif diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am index 2e0a18d4677..128f1c03967 100644 --- a/libmysql/Makefile.am +++ b/libmysql/Makefile.am @@ -18,7 +18,7 @@ # This file is public domain and comes with NO WARRANTY of any kind target = libmysqlclient.la -target_defs = -DUNDEF_THREADS_HACK -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@ -DMYSQL_CLIENT +target_defs = -DUNDEF_THREADS_HACK -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@ LIBS = @CLIENT_LIBS@ INCLUDES = -I$(top_srcdir)/include $(openssl_includes) @@ -79,7 +79,8 @@ nh = my_global.h config-win32.h dbug.h errmsg.h \ m_ctype.h m_string.h \ my_alarm.h my_config.h my_dir.h my_list.h my_net.h my_sys.h \ mysql.h mysql_com.h mysql_version.h mysqld_error.h \ - mysys_err.h my_pthread.h thr_alarm.h violite.h hash.h + mysys_err.h my_pthread.h thr_alarm.h violite.h hash.h \ + sql_common.h ../libmysql/client_settings.h # Get a list of the needed objects lobjs = $(mysysobjects1) $(dbugobjects) $(mystringsobjects) $(sqlobjects) diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index 1067bc2bd41..9a5869c47ff 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -41,7 +41,7 @@ mystringsobjects = strmov.lo strxmov.lo strxnmov.lo strnmov.lo \ ctype.lo ctype-simple.lo ctype-bin.lo ctype-mb.lo \ ctype-big5.lo ctype-czech.lo ctype-euc_kr.lo \ ctype-win1250ch.lo ctype-utf8.lo ctype-extra.lo \ - ctype-gb2312.lo ctype-gbk.lo \ + ctype-ucs2.lo ctype-gb2312.lo ctype-gbk.lo \ ctype-sjis.lo ctype-tis620.lo ctype-ujis.lo xml.lo mystringsextra= strto.c @@ -63,7 +63,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ my_pread.lo mf_cache.lo md5.lo sha1.lo\ my_getopt.lo my_gethostbyname.lo my_port.lo sqlobjects = net.lo -sql_cmn_objects = pack.lo +sql_cmn_objects = pack.lo client.lo # Not needed in the minimum library mysysobjects2 = my_lib.lo diff --git a/libmysql/client_settings.h b/libmysql/client_settings.h new file mode 100644 index 00000000000..47d5185b6ca --- /dev/null +++ b/libmysql/client_settings.h @@ -0,0 +1,58 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or + (at your option) any later version. + + 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 */ + + +static my_bool mysql_client_init=0; +extern uint mysql_port; +extern my_string mysql_unix_port; + +#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \ + | CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \ + | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION) + + +#ifdef __WIN__ +#define CONNECT_TIMEOUT 20 +#else +#define CONNECT_TIMEOUT 0 +#endif + +#ifdef HAVE_SMEM +char *shared_memory_base_name=0; +const char *def_shared_memory_base_name=default_shared_memory_base_name; +#endif + +static my_bool org_my_init_done=0; + +sig_handler pipe_sig_handler(int sig __attribute__((unused))); +my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list); +void read_user_name(char *name); +my_bool send_file_to_server(MYSQL *mysql, const char *filename); + +/* + Let the user specify that we don't want SIGPIPE; This doesn't however work + with threaded applications as we can have multiple read in progress. +*/ + +#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD) +#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0; +#define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler) +#define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler); +#else +#define init_sigpipe_variables +#define set_sigpipe(mysql) +#define reset_sigpipe(mysql) +#endif diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 2f64bb3bd44..44c5e3eecf4 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -57,7 +57,8 @@ #define INADDR_NONE -1 #endif -static my_bool mysql_client_init=0; +#include <sql_common.h> + uint mysql_port=0; my_string mysql_unix_port=0; ulong net_buffer_length=8192; @@ -98,23 +99,13 @@ TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"", be changed */ #define MAX_LONG_DATA_LENGTH 8192 -#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41) #define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG) -static MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields, - uint field_count); -static int read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, - ulong *lengths); -static void end_server(MYSQL *mysql); -static void read_user_name(char *name); static void append_wild(char *to,char *end,const char *wild); -static my_bool mysql_reconnect(MYSQL *mysql); -static my_bool send_file_to_server(MYSQL *mysql,const char *filename); -static sig_handler pipe_sig_handler(int sig); +sig_handler pipe_sig_handler(int sig); static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, const char *from, ulong length); -static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list); -static void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count); +my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list); static my_bool org_my_init_done=0; int STDCALL mysql_server_init(int argc __attribute__((unused)), @@ -170,192 +161,6 @@ static MYSQL* spawn_init(MYSQL* parent, const char* host, const char* user, const char* passwd); - -/**************************************************************************** - A modified version of connect(). my_connect() allows you to specify - a timeout value, in seconds, that we should wait until we - derermine we can't connect to a particular host. If timeout is 0, - my_connect() will behave exactly like connect(). - - Base version coded by Steve Bernacki, Jr. <steve@navinet.net> -*****************************************************************************/ - -my_bool my_connect(my_socket s, const struct sockaddr *name, - uint namelen, uint timeout) -{ -#if defined(__WIN__) || defined(OS2) || defined(__NETWARE__) - return connect(s, (struct sockaddr*) name, namelen) != 0; -#else - int flags, res, s_err; - SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint); - fd_set sfds; - struct timeval tv; - time_t start_time, now_time; - - /* - If they passed us a timeout of zero, we should behave - exactly like the normal connect() call does. - */ - - if (timeout == 0) - return connect(s, (struct sockaddr*) name, namelen) != 0; - - flags = fcntl(s, F_GETFL, 0); /* Set socket to not block */ -#ifdef O_NONBLOCK - fcntl(s, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ -#endif - - res = connect(s, (struct sockaddr*) name, namelen); - s_err = errno; /* Save the error... */ - fcntl(s, F_SETFL, flags); - if ((res != 0) && (s_err != EINPROGRESS)) - { - errno = s_err; /* Restore it */ - return(1); - } - if (res == 0) /* Connected quickly! */ - return(0); - - /* - Otherwise, our connection is "in progress." We can use - the select() call to wait up to a specified period of time - for the connection to succeed. If select() returns 0 - (after waiting howevermany seconds), our socket never became - writable (host is probably unreachable.) Otherwise, if - select() returns 1, then one of two conditions exist: - - 1. An error occured. We use getsockopt() to check for this. - 2. The connection was set up sucessfully: getsockopt() will - return 0 as an error. - - Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> - who posted this method of timing out a connect() in - comp.unix.programmer on August 15th, 1997. - */ - - FD_ZERO(&sfds); - FD_SET(s, &sfds); - /* - select could be interrupted by a signal, and if it is, - the timeout should be adjusted and the select restarted - to work around OSes that don't restart select and - implementations of select that don't adjust tv upon - failure to reflect the time remaining - */ - start_time = time(NULL); - for (;;) - { - tv.tv_sec = (long) timeout; - tv.tv_usec = 0; -#if defined(HPUX10) && defined(THREAD) - if ((res = select(s+1, NULL, (int*) &sfds, NULL, &tv)) > 0) - break; -#else - if ((res = select(s+1, NULL, &sfds, NULL, &tv)) > 0) - break; -#endif - if (res == 0) /* timeout */ - return -1; - now_time=time(NULL); - timeout-= (uint) (now_time - start_time); - if (errno != EINTR || (int) timeout <= 0) - return 1; - } - - /* - select() returned something more interesting than zero, let's - see if we have any errors. If the next two statements pass, - we've got an open socket! - */ - - s_err=0; - if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) - return(1); - - if (s_err) - { /* getsockopt could succeed */ - errno = s_err; - return(1); /* but return an error... */ - } - return (0); /* ok */ - -#endif -} - - -/* - Create a named pipe connection -*/ - -#ifdef __WIN__ - -HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, - char **arg_unix_socket) -{ - HANDLE hPipe=INVALID_HANDLE_VALUE; - char szPipeName [ 257 ]; - DWORD dwMode; - int i; - my_bool testing_named_pipes=0; - char *host= *arg_host, *unix_socket= *arg_unix_socket; - - if ( ! unix_socket || (unix_socket)[0] == 0x00) - unix_socket = mysql_unix_port; - if (!host || !strcmp(host,LOCAL_HOST)) - host=LOCAL_HOST_NAMEDPIPE; - - sprintf( szPipeName, "\\\\%s\\pipe\\%s", host, unix_socket); - DBUG_PRINT("info",("Server name: '%s'. Named Pipe: %s", - host, unix_socket)); - - for (i=0 ; i < 100 ; i++) /* Don't retry forever */ - { - if ((hPipe = CreateFile(szPipeName, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL )) != INVALID_HANDLE_VALUE) - break; - if (GetLastError() != ERROR_PIPE_BUSY) - { - net->last_errno=CR_NAMEDPIPEOPEN_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - /* wait for for an other instance */ - if (! WaitNamedPipe(szPipeName, connect_timeout*1000) ) - { - net->last_errno=CR_NAMEDPIPEWAIT_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - } - if (hPipe == INVALID_HANDLE_VALUE) - { - net->last_errno=CR_NAMEDPIPEOPEN_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - dwMode = PIPE_READMODE_BYTE | PIPE_WAIT; - if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) ) - { - CloseHandle( hPipe ); - net->last_errno=CR_NAMEDPIPESETSTATE_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - *arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */ - return (hPipe); -} -#endif - - /* Create new shared memory connection, return handler of connection @@ -549,6 +354,7 @@ err: if (error_allow) { net->last_errno=error_allow; + strmov(net->sqlstate, unknown_sqlstate); if (error_allow == CR_SHARED_MEMORY_EVENT_ERROR) sprintf(net->last_error,ER(net->last_errno),suffix_pos,error_code); else @@ -559,212 +365,6 @@ err: } #endif - -/***************************************************************************** - Read a packet from server. Give error message if socket was down - or packet is an error message -*****************************************************************************/ - -ulong -net_safe_read(MYSQL *mysql) -{ - NET *net= &mysql->net; - ulong len=0; - init_sigpipe_variables - - /* Don't give sigpipe errors if the client doesn't want them */ - set_sigpipe(mysql); - if (net->vio != 0) - len=my_net_read(net); - reset_sigpipe(mysql); - - if (len == packet_error || len == 0) - { - DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", - vio_description(net->vio),len)); - end_server(mysql); - net->last_errno=(net->last_errno == ER_NET_PACKET_TOO_LARGE ? - CR_NET_PACKET_TOO_LARGE: - CR_SERVER_LOST); - strmov(net->last_error,ER(net->last_errno)); - return (packet_error); - } - if (net->read_pos[0] == 255) - { - if (len > 3) - { - char *pos=(char*) net->read_pos+1; - net->last_errno=uint2korr(pos); - pos+=2; - len-=2; - (void) strmake(net->last_error,(char*) pos, - min((uint) len,(uint) sizeof(net->last_error)-1)); - } - else - { - net->last_errno=CR_UNKNOWN_ERROR; - (void) strmov(net->last_error,ER(net->last_errno)); - } - DBUG_PRINT("error",("Got error: %d (%s)", net->last_errno, - net->last_error)); - return(packet_error); - } - return len; -} - -static void free_rows(MYSQL_DATA *cur) -{ - if (cur) - { - free_root(&cur->alloc,MYF(0)); - my_free((gptr) cur,MYF(0)); - } -} - - -static my_bool -advanced_command(MYSQL *mysql, enum enum_server_command command, - const char *header, ulong header_length, - const char *arg, ulong arg_length, my_bool skip_check) -{ - NET *net= &mysql->net; - my_bool result= 1; - init_sigpipe_variables - - /* Don't give sigpipe errors if the client doesn't want them */ - set_sigpipe(mysql); - - if (mysql->net.vio == 0) - { /* Do reconnect if possible */ - if (mysql_reconnect(mysql)) - return 1; - } - if (mysql->status != MYSQL_STATUS_READY) - { - strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); - return 1; - } - - mysql->net.last_error[0]=0; - mysql->net.last_errno=0; - mysql->info=0; - mysql->affected_rows= ~(my_ulonglong) 0; - net_clear(&mysql->net); /* Clear receive buffer */ - - if (net_write_command(net,(uchar) command, header, header_length, - arg, arg_length)) - { - DBUG_PRINT("error",("Can't send command to server. Error: %d", - socket_errno)); - if (net->last_errno == ER_NET_PACKET_TOO_LARGE) - { - net->last_errno=CR_NET_PACKET_TOO_LARGE; - strmov(net->last_error,ER(net->last_errno)); - goto end; - } - end_server(mysql); - if (mysql_reconnect(mysql)) - goto end; - if (net_write_command(net,(uchar) command, header, header_length, - arg, arg_length)) - { - net->last_errno=CR_SERVER_GONE_ERROR; - strmov(net->last_error,ER(net->last_errno)); - goto end; - } - } - result=0; - if (!skip_check) - result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ? - 1 : 0); - end: - reset_sigpipe(mysql); - return result; -} - - -my_bool -simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, - ulong length, my_bool skip_check) -{ - return advanced_command(mysql, command, NullS, 0, arg, length, skip_check); -} - - -static void free_old_query(MYSQL *mysql) -{ - DBUG_ENTER("free_old_query"); - if (mysql->fields) - free_root(&mysql->field_alloc,MYF(0)); - init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ - mysql->fields=0; - mysql->field_count=0; /* For API */ - DBUG_VOID_RETURN; -} - - -#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) -struct passwd *getpwuid(uid_t); -char* getlogin(void); -#endif - - -#if defined(__NETWARE__) -/* default to "root" on NetWare */ -static void read_user_name(char *name) -{ - char *str=getenv("USER"); - strmake(name, str ? str : "UNKNOWN_USER", USERNAME_LENGTH); -} - -#elif !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) && !defined(OS2) - -static void read_user_name(char *name) -{ - DBUG_ENTER("read_user_name"); - if (geteuid() == 0) - (void) strmov(name,"root"); /* allow use of surun */ - else - { -#ifdef HAVE_GETPWUID - struct passwd *skr; - const char *str; - if ((str=getlogin()) == NULL) - { - if ((skr=getpwuid(geteuid())) != NULL) - str=skr->pw_name; - else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) && - !(str=getenv("LOGIN"))) - str="UNKNOWN_USER"; - } - (void) strmake(name,str,USERNAME_LENGTH); -#elif HAVE_CUSERID - (void) cuserid(name); -#else - strmov(name,"UNKNOWN_USER"); -#endif - } - DBUG_VOID_RETURN; -} - -#else /* If MSDOS || VMS */ - -static void read_user_name(char *name) -{ - char *str=getenv("USER"); /* ODBC will send user variable */ - strmake(name,str ? str : "ODBC", USERNAME_LENGTH); -} - -#endif - -#ifdef __WIN__ -static my_bool is_NT(void) -{ - char *os=getenv("OS"); - return (os && !strcmp(os, "Windows_NT")) ? 1 : 0; -} -#endif - /* Expand wildcard to a sql string */ @@ -832,7 +432,7 @@ mysql_debug(const char *debug __attribute__((unused))) ARGSUSED **************************************************************************/ -static sig_handler +sig_handler pipe_sig_handler(int sig __attribute__((unused))) { DBUG_PRINT("info",("Hit by signal %d",sig)); @@ -841,530 +441,6 @@ pipe_sig_handler(int sig __attribute__((unused))) #endif } - -/************************************************************************** - Shut down connection -**************************************************************************/ - -static void -end_server(MYSQL *mysql) -{ - DBUG_ENTER("end_server"); - if (mysql->net.vio != 0) - { - init_sigpipe_variables - DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio))); - set_sigpipe(mysql); - vio_delete(mysql->net.vio); - reset_sigpipe(mysql); - mysql->net.vio= 0; /* Marker */ - } - net_end(&mysql->net); - free_old_query(mysql); - DBUG_VOID_RETURN; -} - - -void STDCALL -mysql_free_result(MYSQL_RES *result) -{ - DBUG_ENTER("mysql_free_result"); - DBUG_PRINT("enter",("mysql_res: %lx",result)); - if (result) - { - if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) - { - DBUG_PRINT("warning",("Not all rows in set where read; Ignoring rows")); - for (;;) - { - ulong pkt_len; - if ((pkt_len=net_safe_read(result->handle)) == packet_error) - break; - if (pkt_len <= 8 && result->handle->net.read_pos[0] == 254) - break; /* End of data */ - } - result->handle->status=MYSQL_STATUS_READY; - } - free_rows(result->data); - if (result->fields) - free_root(&result->field_alloc,MYF(0)); - if (result->row) - my_free((gptr) result->row,MYF(0)); - my_free((gptr) result,MYF(0)); - } - DBUG_VOID_RETURN; -} - - -/**************************************************************************** - Get options from my.cnf -****************************************************************************/ - -static const char *default_options[]= -{ - "port","socket","compress","password","pipe", "timeout", "user", - "init-command", "host", "database", "debug", "return-found-rows", - "ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath", - "character-sets-dir", "default-character-set", "interactive-timeout", - "connect-timeout", "local-infile", "disable-local-infile", - "replication-probe", "enable-reads-from-master", "repl-parse-query", - "ssl-cipher", "max-allowed-packet", - "protocol", "shared-memory-base-name", - NullS -}; - -static TYPELIB option_types={array_elements(default_options)-1, - "options",default_options}; - -static int add_init_command(struct st_mysql_options *options, const char *cmd) -{ - char *tmp; - - if (!options->init_commands) - { - options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY), - MYF(MY_WME)); - init_dynamic_array(options->init_commands,sizeof(char*),0,5 CALLER_INFO); - } - - if (!(tmp= my_strdup(cmd,MYF(MY_WME))) || - insert_dynamic(options->init_commands, (gptr)&tmp)) - { - my_free(tmp, MYF(MY_ALLOW_ZERO_PTR)); - return 1; - } - - return 0; -} - -static void mysql_read_default_options(struct st_mysql_options *options, - const char *filename,const char *group) -{ - int argc; - char *argv_buff[1],**argv; - const char *groups[3]; - DBUG_ENTER("mysql_read_default_options"); - DBUG_PRINT("enter",("file: %s group: %s",filename,group ? group :"NULL")); - - argc=1; argv=argv_buff; argv_buff[0]= (char*) "client"; - groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0; - - load_defaults(filename, groups, &argc, &argv); - if (argc != 1) /* If some default option */ - { - char **option=argv; - while (*++option) - { - /* DBUG_PRINT("info",("option: %s",option[0])); */ - if (option[0][0] == '-' && option[0][1] == '-') - { - char *end=strcend(*option,'='); - char *opt_arg=0; - if (*end) - { - opt_arg=end+1; - *end=0; /* Remove '=' */ - } - /* Change all '_' in variable name to '-' */ - for (end= *option ; *(end= strcend(end,'_')) ; ) - *end= '-'; - switch (find_type(*option+2,&option_types,2)) { - case 1: /* port */ - if (opt_arg) - options->port=atoi(opt_arg); - break; - case 2: /* socket */ - if (opt_arg) - { - my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR)); - options->unix_socket=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case 3: /* compress */ - options->compress=1; - options->client_flag|= CLIENT_COMPRESS; - break; - case 4: /* password */ - if (opt_arg) - { - my_free(options->password,MYF(MY_ALLOW_ZERO_PTR)); - options->password=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case 5: - options->protocol = MYSQL_PROTOCOL_PIPE; - case 20: /* connect_timeout */ - case 6: /* timeout */ - if (opt_arg) - options->connect_timeout=atoi(opt_arg); - break; - case 7: /* user */ - if (opt_arg) - { - my_free(options->user,MYF(MY_ALLOW_ZERO_PTR)); - options->user=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case 8: /* init-command */ - add_init_command(options,opt_arg); - break; - case 9: /* host */ - if (opt_arg) - { - my_free(options->host,MYF(MY_ALLOW_ZERO_PTR)); - options->host=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case 10: /* database */ - if (opt_arg) - { - my_free(options->db,MYF(MY_ALLOW_ZERO_PTR)); - options->db=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case 11: /* debug */ - mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); - break; - case 12: /* return-found-rows */ - options->client_flag|=CLIENT_FOUND_ROWS; - break; -#ifdef HAVE_OPENSSL - case 13: /* ssl_key */ - my_free(options->ssl_key, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 14: /* ssl_cert */ - my_free(options->ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 15: /* ssl_ca */ - my_free(options->ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 16: /* ssl_capath */ - my_free(options->ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); - break; -#else - case 13: /* Ignore SSL options */ - case 14: - case 15: - case 16: - break; -#endif /* HAVE_OPENSSL */ - case 17: /* charset-lib */ - my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR)); - options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 18: - my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR)); - options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 19: /* Interactive-timeout */ - options->client_flag|= CLIENT_INTERACTIVE; - break; - case 21: - if (!opt_arg || atoi(opt_arg) != 0) - options->client_flag|= CLIENT_LOCAL_FILES; - else - options->client_flag&= ~CLIENT_LOCAL_FILES; - break; - case 22: - options->client_flag&= CLIENT_LOCAL_FILES; - break; - case 23: /* replication probe */ - options->rpl_probe= 1; - break; - case 24: /* enable-reads-from-master */ - options->no_master_reads= 0; - break; - case 25: /* repl-parse-query */ - options->rpl_parse= 1; - break; - case 27: - options->max_allowed_packet= atoi(opt_arg); - break; - case 28: /* protocol */ - if ((options->protocol = find_type(opt_arg, &sql_protocol_typelib,0)) == ~(ulong) 0) - { - fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg); - exit(1); - } - break; - case 29: /* shared_memory_base_name */ -#ifdef HAVE_SMEM - if (options->shared_memory_base_name != def_shared_memory_base_name) - my_free(options->shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); - options->shared_memory_base_name=my_strdup(opt_arg,MYF(MY_WME)); -#endif - break; - default: - DBUG_PRINT("warning",("unknown option: %s",option[0])); - } - } - } - } - free_defaults(argv); - DBUG_VOID_RETURN; -} - - -/*************************************************************************** - Change field rows to field structs -***************************************************************************/ - -static MYSQL_FIELD * -unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, - my_bool default_value, uint server_capabilities) -{ - MYSQL_ROWS *row; - MYSQL_FIELD *field,*result; - ulong lengths[8]; /* Max of fields */ - DBUG_ENTER("unpack_fields"); - - field=result=(MYSQL_FIELD*) alloc_root(alloc, - (uint) sizeof(MYSQL_FIELD)*fields); - if (!result) - { - free_rows(data); /* Free old data */ - DBUG_RETURN(0); - } - bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields); - if (server_capabilities & CLIENT_PROTOCOL_41) - { - /* server is 4.1, and returns the new field result format */ - for (row=data->data; row ; row = row->next,field++) - { - uchar *pos; - fetch_lengths(&lengths[0], row->data, default_value ? 7 : 6); - field->db = strdup_root(alloc,(char*) row->data[0]); - field->table = strdup_root(alloc,(char*) row->data[1]); - field->org_table= strdup_root(alloc,(char*) row->data[2]); - field->name = strdup_root(alloc,(char*) row->data[3]); - field->org_name = strdup_root(alloc,(char*) row->data[4]); - - field->db_length= lengths[0]; - field->table_length= lengths[1]; - field->org_table_length= lengths[2]; - field->name_length= lengths[3]; - field->org_name_length= lengths[4]; - - /* Unpack fixed length parts */ - pos= (uchar*) row->data[5]; - field->charsetnr= uint2korr(pos); - field->length= (uint) uint3korr(pos+2); - field->type= (enum enum_field_types) pos[5]; - field->flags= uint2korr(pos+6); - field->decimals= (uint) pos[8]; - - if (INTERNAL_NUM_FIELD(field)) - field->flags|= NUM_FLAG; - if (default_value && row->data[6]) - { - field->def=strdup_root(alloc,(char*) row->data[6]); - field->def_length= lengths[6]; - } - else - field->def=0; - field->max_length= 0; - } - } -#ifndef DELETE_SUPPORT_OF_4_0_PROTOCOL - else - { - /* old protocol, for backward compatibility */ - for (row=data->data; row ; row = row->next,field++) - { - fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5); - field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]); - field->name= strdup_root(alloc,(char*) row->data[1]); - field->length= (uint) uint3korr(row->data[2]); - field->type= (enum enum_field_types) (uchar) row->data[3][0]; - - field->org_table_length= field->table_length= lengths[0]; - field->name_length= lengths[1]; - - if (server_capabilities & CLIENT_LONG_FLAG) - { - field->flags= uint2korr(row->data[4]); - field->decimals=(uint) (uchar) row->data[4][2]; - } - else - { - field->flags= (uint) (uchar) row->data[4][0]; - field->decimals=(uint) (uchar) row->data[4][1]; - } - if (INTERNAL_NUM_FIELD(field)) - field->flags|= NUM_FLAG; - if (default_value && row->data[5]) - { - field->def=strdup_root(alloc,(char*) row->data[5]); - field->def_length= lengths[5]; - } - else - field->def=0; - field->max_length= 0; - } - } -#endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */ - free_rows(data); /* Free old data */ - DBUG_RETURN(result); -} - - -/* Read all rows (fields or data) from server */ - -static MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, - uint fields) -{ - uint field; - ulong pkt_len; - ulong len; - uchar *cp; - char *to, *end_to; - MYSQL_DATA *result; - MYSQL_ROWS **prev_ptr,*cur; - NET *net = &mysql->net; - DBUG_ENTER("read_rows"); - - if ((pkt_len= net_safe_read(mysql)) == packet_error) - DBUG_RETURN(0); - if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), - MYF(MY_WME | MY_ZEROFILL)))) - { - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); - DBUG_RETURN(0); - } - init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ - result->alloc.min_malloc=sizeof(MYSQL_ROWS); - prev_ptr= &result->data; - result->rows=0; - result->fields=fields; - - /* - The last EOF packet is either a single 254 character or (in MySQL 4.1) - 254 followed by 1-7 status bytes. - - This doesn't conflict with normal usage of 254 which stands for a - string where the length of the string is 8 bytes. (see net_field_length()) - */ - - while (*(cp=net->read_pos) != 254 || pkt_len >= 8) - { - result->rows++; - if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, - sizeof(MYSQL_ROWS))) || - !(cur->data= ((MYSQL_ROW) - alloc_root(&result->alloc, - (fields+1)*sizeof(char *)+pkt_len)))) - { - free_rows(result); - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); - DBUG_RETURN(0); - } - *prev_ptr=cur; - prev_ptr= &cur->next; - to= (char*) (cur->data+fields+1); - end_to=to+pkt_len-1; - for (field=0 ; field < fields ; field++) - { - if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH) - { /* null field */ - cur->data[field] = 0; - } - else - { - cur->data[field] = to; - if (len > (ulong) (end_to - to)) - { - free_rows(result); - net->last_errno=CR_MALFORMED_PACKET; - strmov(net->last_error,ER(net->last_errno)); - DBUG_RETURN(0); - } - memcpy(to,(char*) cp,len); to[len]=0; - to+=len+1; - cp+=len; - if (mysql_fields) - { - if (mysql_fields[field].max_length < len) - mysql_fields[field].max_length=len; - } - } - } - cur->data[field]=to; /* End of last field */ - if ((pkt_len=net_safe_read(mysql)) == packet_error) - { - free_rows(result); - DBUG_RETURN(0); - } - } - *prev_ptr=0; /* last pointer is null */ - if (pkt_len > 1) /* MySQL 4.1 protocol */ - { - mysql->warning_count= uint2korr(cp+1); - DBUG_PRINT("info",("warning_count: %ld", mysql->warning_count)); - } - DBUG_PRINT("exit",("Got %d rows",result->rows)); - DBUG_RETURN(result); -} - - -/* - Read one row. Uses packet buffer as storage for fields. - When next packet is read, the previous field values are destroyed -*/ - - -static int -read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) -{ - uint field; - ulong pkt_len,len; - uchar *pos, *end_pos; - uchar *prev_pos; - - if ((pkt_len=net_safe_read(mysql)) == packet_error) - return -1; - if (pkt_len <= 8 && mysql->net.read_pos[0] == 254) - { - if (pkt_len > 1) /* MySQL 4.1 protocol */ - mysql->warning_count= uint2korr(mysql->net.read_pos+1); - return 1; /* End of data */ - } - prev_pos= 0; /* allowed to write at packet[-1] */ - pos=mysql->net.read_pos; - end_pos=pos+pkt_len; - for (field=0 ; field < fields ; field++) - { - if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH) - { /* null field */ - row[field] = 0; - *lengths++=0; - } - else - { - if (len > (ulong) (end_pos - pos)) - { - mysql->net.last_errno=CR_UNKNOWN_ERROR; - strmov(mysql->net.last_error,ER(mysql->net.last_errno)); - return -1; - } - row[field] = (char*) pos; - pos+=len; - *lengths++=len; - } - if (prev_pos) - *prev_pos=0; /* Terminate prev field */ - prev_pos= pos; - } - row[field]=(char*) prev_pos+1; /* End of last field */ - *prev_pos=0; /* Terminate last field */ - return 0; -} - /* perform query on master */ my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q, unsigned long length) @@ -1660,108 +736,6 @@ STDCALL mysql_rpl_query_type(const char* q, int len) return MYSQL_RPL_MASTER; /* By default, send to master */ } - -/**************************************************************************** - Init MySQL structure or allocate one -****************************************************************************/ - -MYSQL * STDCALL -mysql_init(MYSQL *mysql) -{ - mysql_once_init(); - if (!mysql) - { - if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) - return 0; - mysql->free_me=1; - } - else - bzero((char*) (mysql),sizeof(*(mysql))); - mysql->options.connect_timeout=CONNECT_TIMEOUT; - mysql->last_used_con = mysql->next_slave = mysql->master = mysql; - - /* - By default, we are a replication pivot. The caller must reset it - after we return if this is not the case. - */ - mysql->rpl_pivot = 1; -#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) - if (!((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE)) - (void) signal(SIGPIPE,pipe_sig_handler); -#endif - -/* - Only enable LOAD DATA INFILE by default if configured with - --enable-local-infile -*/ -#ifdef ENABLED_LOCAL_INFILE - mysql->options.client_flag|= CLIENT_LOCAL_FILES; -#endif -#ifdef HAVE_SMEM - mysql->options.shared_memory_base_name=(char*)def_shared_memory_base_name; -#endif - return mysql; -} - - -/* - Initialize the MySQL library - - SYNOPSIS - mysql_once_init() - - NOTES - Can't be static on NetWare - This function is called by mysql_init() and indirectly called - by mysql_query(), so one should never have to call this from an - outside program. -*/ - -void mysql_once_init(void) -{ - if (!mysql_client_init) - { - mysql_client_init=1; - org_my_init_done=my_init_done; - my_init(); /* Will init threads */ - init_client_errs(); - if (!mysql_port) - { - mysql_port = MYSQL_PORT; -#ifndef MSDOS - { - struct servent *serv_ptr; - char *env; - if ((serv_ptr = getservbyname("mysql", "tcp"))) - mysql_port = (uint) ntohs((ushort) serv_ptr->s_port); - if ((env = getenv("MYSQL_TCP_PORT"))) - mysql_port =(uint) atoi(env); - } -#endif - } - if (!mysql_unix_port) - { - char *env; -#ifdef __WIN__ - mysql_unix_port = (char*) MYSQL_NAMEDPIPE; -#else - mysql_unix_port = (char*) MYSQL_UNIX_ADDR; -#endif - if ((env = getenv("MYSQL_UNIX_PORT"))) - mysql_unix_port = env; - } - mysql_debug(NullS); -#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__) - (void) signal(SIGPIPE,SIG_IGN); -#endif - } -#ifdef THREAD - else - my_thread_init(); /* Init if new thread */ -#endif -} - - /* Fill in SSL part of MYSQL structure and set 'use_ssl' flag. NB! Errors are not reported until you do mysql_real_connect. @@ -1787,101 +761,6 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , return 0; } - -/* - Free strings in the SSL structure and clear 'use_ssl' flag. - NB! Errors are not reported until you do mysql_real_connect. -*/ - -#ifdef HAVE_OPENSSL -static void -mysql_ssl_free(MYSQL *mysql __attribute__((unused))) -{ - my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.ssl_key = 0; - mysql->options.ssl_cert = 0; - mysql->options.ssl_ca = 0; - mysql->options.ssl_capath = 0; - mysql->options.ssl_cipher= 0; - mysql->options.use_ssl = FALSE; - mysql->connector_fd = 0; -} -#endif /* HAVE_OPENSSL */ - - -/* - Handle password authentication -*/ - -static my_bool mysql_autenticate(MYSQL *mysql, const char *passwd) -{ - ulong pkt_length; - NET *net= &mysql->net; - char buff[SCRAMBLE41_LENGTH]; - char password_hash[SCRAMBLE41_LENGTH]; /* Used for storage of stage1 hash */ - - /* We shall only query server if it expect us to do so */ - if ((pkt_length=net_safe_read(mysql)) == packet_error) - goto error; - - if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) - { - /* - This should always happen with new server unless empty password - OK/Error packets have zero as the first char - */ - if (pkt_length == 24 && net->read_pos[0]) - { - /* Old passwords will have '*' at the first byte of hash */ - if (net->read_pos[0] != '*') - { - /* Build full password hash as it is required to decode scramble */ - password_hash_stage1(buff, passwd); - /* Store copy as we'll need it later */ - memcpy(password_hash,buff,SCRAMBLE41_LENGTH); - /* Finally hash complete password using hash we got from server */ - password_hash_stage2(password_hash,(const char*) net->read_pos); - /* Decypt and store scramble 4 = hash for stage2 */ - password_crypt((const char*) net->read_pos+4,mysql->scramble_buff, - password_hash, SCRAMBLE41_LENGTH); - mysql->scramble_buff[SCRAMBLE41_LENGTH]=0; - /* Encode scramble with password. Recycle buffer */ - password_crypt(mysql->scramble_buff,buff,buff,SCRAMBLE41_LENGTH); - } - else - { - /* Create password to decode scramble */ - create_key_from_old_password(passwd,password_hash); - /* Decypt and store scramble 4 = hash for stage2 */ - password_crypt((const char*) net->read_pos+4,mysql->scramble_buff, - password_hash, SCRAMBLE41_LENGTH); - mysql->scramble_buff[SCRAMBLE41_LENGTH]=0; - /* Finally scramble decoded scramble with password */ - scramble(buff, mysql->scramble_buff, passwd,0); - } - /* Write second package of authentication */ - if (my_net_write(net,buff,SCRAMBLE41_LENGTH) || net_flush(net)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - /* Read what server thinks about out new auth message report */ - if (net_safe_read(mysql) == packet_error) - goto error; - } - } - return 0; - -error: - return 1; -} - /************************************************************************** Connect to sql server If host == 0 then use localhost @@ -1906,601 +785,6 @@ mysql_connect(MYSQL *mysql,const char *host, } #endif - -/* - Note that the mysql argument must be initialized with mysql_init() - before calling mysql_real_connect ! -*/ - -MYSQL * STDCALL -mysql_real_connect(MYSQL *mysql,const char *host, const char *user, - const char *passwd, const char *db, - uint port, const char *unix_socket,ulong client_flag) -{ - char buff[NAME_LEN+USERNAME_LENGTH+100],charset_name_buff[16]; - char *end,*host_info,*charset_name; - my_socket sock; - uint32 ip_addr; - struct sockaddr_in sock_addr; - ulong pkt_length; - NET *net= &mysql->net; -#ifdef __WIN__ - HANDLE hPipe=INVALID_HANDLE_VALUE; -#endif -#ifdef HAVE_SYS_UN_H - struct sockaddr_un UNIXaddr; -#endif - init_sigpipe_variables - DBUG_ENTER("mysql_real_connect"); - LINT_INIT(host_info); - - DBUG_PRINT("enter",("host: %s db: %s user: %s", - host ? host : "(Null)", - db ? db : "(Null)", - user ? user : "(Null)")); - - /* Don't give sigpipe errors if the client doesn't want them */ - set_sigpipe(mysql); - net->vio = 0; /* If something goes wrong */ - /* use default options */ - if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) - { - mysql_read_default_options(&mysql->options, - (mysql->options.my_cnf_file ? - mysql->options.my_cnf_file : "my"), - mysql->options.my_cnf_group); - my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; - } - - /* Some empty-string-tests are done because of ODBC */ - if (!host || !host[0]) - host=mysql->options.host; - if (!user || !user[0]) - user=mysql->options.user; - if (!passwd) - { - passwd=mysql->options.password; -#ifndef DONT_USE_MYSQL_PWD - if (!passwd) - passwd=getenv("MYSQL_PWD"); /* get it from environment */ -#endif - } - if (!db || !db[0]) - db=mysql->options.db; - if (!port) - port=mysql->options.port; - if (!unix_socket) - unix_socket=mysql->options.unix_socket; - - mysql->reconnect=1; /* Reconnect as default */ - mysql->server_status=SERVER_STATUS_AUTOCOMMIT; - - /* - Grab a socket and connect it to the server - */ -#if defined(HAVE_SMEM) - if ((!mysql->options.protocol || - mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) && - (!host || !strcmp(host,LOCAL_HOST))) - { - if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) == - INVALID_HANDLE_VALUE) - { - DBUG_PRINT("error", - ("host: '%s' socket: '%s' shared memory: %s have_tcpip: %d", - host ? host : "<null>", - unix_socket ? unix_socket : "<null>", - (int) mysql->options.shared_memory_base_name, - (int) have_tcpip)); - if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) - goto error; - /* Try also with PIPE or TCP/IP */ - } - else - { - mysql->options.protocol=MYSQL_PROTOCOL_MEMORY; - sock=0; - unix_socket = 0; - host=mysql->options.shared_memory_base_name; - host_info=(char*) ER(CR_SHARED_MEMORY_CONNECTION); - } - } else -#endif /* HAVE_SMEM */ -#if defined(HAVE_SYS_UN_H) - if ((!mysql->options.protocol || - mysql->options.protocol == MYSQL_PROTOCOL_SOCKET)&& - (!host || !strcmp(host,LOCAL_HOST)) && - (unix_socket || mysql_unix_port)) - { - host=LOCAL_HOST; - if (!unix_socket) - unix_socket=mysql_unix_port; - host_info=(char*) ER(CR_LOCALHOST_CONNECTION); - DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); - if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) - { - net->last_errno=CR_SOCKET_CREATE_ERROR; - sprintf(net->last_error,ER(net->last_errno),socket_errno); - goto error; - } - net->vio = vio_new(sock, VIO_TYPE_SOCKET, TRUE); - bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); - UNIXaddr.sun_family = AF_UNIX; - strmov(UNIXaddr.sun_path, unix_socket); - if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr), - mysql->options.connect_timeout)) - { - DBUG_PRINT("error",("Got error %d on connect to local server", - socket_errno)); - net->last_errno=CR_CONNECTION_ERROR; - sprintf(net->last_error,ER(net->last_errno),unix_socket,socket_errno); - goto error; - } - else - mysql->options.protocol=MYSQL_PROTOCOL_SOCKET; - } - else -#elif defined(__WIN__) - { - if ((!mysql->options.protocol || - mysql->options.protocol == MYSQL_PROTOCOL_PIPE)&& - ((unix_socket || !host && is_NT() || - host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) ||! have_tcpip))&& - (!net->vio)) - { - sock=0; - if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout, - (char**) &host, (char**) &unix_socket)) == - INVALID_HANDLE_VALUE) - { - DBUG_PRINT("error", - ("host: '%s' socket: '%s' have_tcpip: %d", - host ? host : "<null>", - unix_socket ? unix_socket : "<null>", - (int) have_tcpip)); - if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || - (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || - (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) - goto error; - /* Try also with TCP/IP */ - } - else - { - net->vio=vio_new_win32pipe(hPipe); - sprintf(host_info=buff, ER(CR_NAMEDPIPE_CONNECTION), host, - unix_socket); - } - } - } -#endif - if ((!mysql->options.protocol || - mysql->options.protocol == MYSQL_PROTOCOL_TCP)&&(!net->vio)) - { - unix_socket=0; /* This is not used */ - if (!port) - port=mysql_port; - if (!host) - host=LOCAL_HOST; - sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host); - DBUG_PRINT("info",("Server name: '%s'. TCP sock: %d", host,port)); - /* _WIN64 ; Assume that the (int) range is enough for socket() */ - if ((sock = (my_socket) socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR) - { - net->last_errno=CR_IPSOCK_ERROR; - sprintf(net->last_error,ER(net->last_errno),socket_errno); - goto error; - } - net->vio = vio_new(sock,VIO_TYPE_TCPIP,FALSE); - bzero((char*) &sock_addr,sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - - /* - The server name may be a host name or IP address - */ - - if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) - { - memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); - } - else - { - int tmp_errno; - struct hostent tmp_hostent,*hp; - char buff2[GETHOSTBYNAME_BUFF_SIZE]; - hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), - &tmp_errno); - if (!hp) - { - my_gethostbyname_r_free(); - net->last_errno=CR_UNKNOWN_HOST; - sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno); - goto error; - } - memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length); - my_gethostbyname_r_free(); - } - sock_addr.sin_port = (ushort) htons((ushort) port); - if (my_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr), - mysql->options.connect_timeout)) - { - DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno, - host)); - net->last_errno= CR_CONN_HOST_ERROR; - sprintf(net->last_error ,ER(CR_CONN_HOST_ERROR), host, socket_errno); - goto error; - } - } - else if (!net->vio) - { - DBUG_PRINT("error",("Unknow protocol %d ",mysql->options.protocol)); - net->last_errno= CR_CONN_UNKNOW_PROTOCOL; - sprintf(net->last_error ,ER(CR_CONN_UNKNOW_PROTOCOL)); - goto error; - } - - if (!net->vio || my_net_init(net, net->vio)) - { - vio_delete(net->vio); - net->vio = 0; - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - vio_keepalive(net->vio,TRUE); - - /* Get version info */ - mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ - if (mysql->options.connect_timeout && - vio_poll_read(net->vio, mysql->options.connect_timeout)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - if ((pkt_length=net_safe_read(mysql)) == packet_error) - goto error; - - /* Check if version of protocol matches current one */ - - mysql->protocol_version= net->read_pos[0]; - DBUG_DUMP("packet",(char*) net->read_pos,10); - DBUG_PRINT("info",("mysql protocol version %d, server=%d", - PROTOCOL_VERSION, mysql->protocol_version)); - if (mysql->protocol_version != PROTOCOL_VERSION) - { - net->last_errno= CR_VERSION_ERROR; - sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version, - PROTOCOL_VERSION); - goto error; - } - end=strend((char*) net->read_pos+1); - mysql->thread_id=uint4korr(end+1); - end+=5; - strmake(mysql->scramble_buff,end,8); - end+=9; - if (pkt_length >= (uint) (end+1 - (char*) net->read_pos)) - mysql->server_capabilities=uint2korr(end); - if (pkt_length >= (uint) (end+18 - (char*) net->read_pos)) - { - /* New protocol with 16 bytes to describe server characteristics */ - mysql->server_language=end[2]; - mysql->server_status=uint2korr(end+3); - } - - /* Set character set */ - if ((charset_name=mysql->options.charset_name)) - { - const char *save=charsets_dir; - if (mysql->options.charset_dir) - charsets_dir=mysql->options.charset_dir; - mysql->charset=get_charset_by_name(mysql->options.charset_name, - MYF(MY_WME)); - charsets_dir=save; - } - else if (mysql->server_language) - { - charset_name=charset_name_buff; - sprintf(charset_name,"%d",mysql->server_language); /* In case of errors */ - if (!(mysql->charset = - get_charset((uint8) mysql->server_language, MYF(0)))) - mysql->charset = default_charset_info; /* shouldn't be fatal */ - } - else - mysql->charset=default_charset_info; - - if (!mysql->charset) - { - net->last_errno=CR_CANT_READ_CHARSET; - if (mysql->options.charset_dir) - sprintf(net->last_error,ER(net->last_errno), - charset_name ? charset_name : "unknown", - mysql->options.charset_dir); - else - { - char cs_dir_name[FN_REFLEN]; - get_charsets_dir(cs_dir_name); - sprintf(net->last_error,ER(net->last_errno), - charset_name ? charset_name : "unknown", - cs_dir_name); - } - goto error; - } - - /* Save connection information */ - if (!user) user=""; - if (!passwd) passwd=""; - if (!my_multi_malloc(MYF(0), - &mysql->host_info, (uint) strlen(host_info)+1, - &mysql->host, (uint) strlen(host)+1, - &mysql->unix_socket,unix_socket ? - (uint) strlen(unix_socket)+1 : (uint) 1, - &mysql->server_version, - (uint) (end - (char*) net->read_pos), - NullS) || - !(mysql->user=my_strdup(user,MYF(0))) || - !(mysql->passwd=my_strdup(passwd,MYF(0)))) - { - strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY)); - goto error; - } - strmov(mysql->host_info,host_info); - strmov(mysql->host,host); - if (unix_socket) - strmov(mysql->unix_socket,unix_socket); - else - mysql->unix_socket=0; - strmov(mysql->server_version,(char*) net->read_pos+1); - mysql->port=port; - client_flag|=mysql->options.client_flag; - - /* Send client information for access check */ - client_flag|=CLIENT_CAPABILITIES; - -#ifdef HAVE_OPENSSL - if (mysql->options.ssl_key || mysql->options.ssl_cert || - mysql->options.ssl_ca || mysql->options.ssl_capath || - mysql->options.ssl_cipher) - mysql->options.use_ssl= 1; - if (mysql->options.use_ssl) - client_flag|=CLIENT_SSL; -#endif /* HAVE_OPENSSL */ - if (db) - client_flag|=CLIENT_CONNECT_WITH_DB; - /* Remove options that server doesn't support */ - client_flag= ((client_flag & - ~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41)) | - (client_flag & mysql->server_capabilities)); - -#ifndef HAVE_COMPRESS - client_flag&= ~CLIENT_COMPRESS; -#endif - - if (client_flag & CLIENT_PROTOCOL_41) - { - /* 4.1 server and 4.1 client has a 4 byte option flag */ - int4store(buff,client_flag); - int4store(buff+4,max_allowed_packet); - end= buff+8; - } - else - { - int2store(buff,client_flag); - int3store(buff+2,max_allowed_packet); - end= buff+5; - } - mysql->client_flag=client_flag; - -#ifdef HAVE_OPENSSL - /* - Oops.. are we careful enough to not send ANY information without - encryption? - */ - if (client_flag & CLIENT_SSL) - { - struct st_mysql_options *options= &mysql->options; - if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - /* Do the SSL layering. */ - if (!(mysql->connector_fd= - (gptr) new_VioSSLConnectorFd(options->ssl_key, - options->ssl_cert, - options->ssl_ca, - options->ssl_capath, - options->ssl_cipher))) - { - net->last_errno= CR_SSL_CONNECTION_ERROR; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - DBUG_PRINT("info", ("IO layer change in progress...")); - if (sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd), - mysql->net.vio, (long) (mysql->options.connect_timeout))) - { - net->last_errno= CR_SSL_CONNECTION_ERROR; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - DBUG_PRINT("info", ("IO layer change done!")); - } -#endif /* HAVE_OPENSSL */ - - DBUG_PRINT("info",("Server version = '%s' capabilites: %lu status: %u client_flag: %lu", - mysql->server_version,mysql->server_capabilities, - mysql->server_status, client_flag)); - /* This needs to be changed as it's not useful with big packets */ - if (user && user[0]) - strmake(end,user,32); /* Max user name */ - else - read_user_name((char*) end); - /* We have to handle different version of handshake here */ -#ifdef _CUSTOMCONFIG_ -#include "_cust_libmysql.h"; -#endif - DBUG_PRINT("info",("user: %s",end)); - /* - We always start with old type handshake the only difference is message sent - If server handles secure connection type we'll not send the real scramble - */ - if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) - { - if (passwd[0]) - { - /* Prepare false scramble */ - end=strend(end)+1; - bfill(end, SCRAMBLE_LENGTH, 'x'); - end+=SCRAMBLE_LENGTH; - *end=0; - } - else /* For empty password*/ - { - end=strend(end)+1; - *end=0; /* Store zero length scramble */ - } - } - else - { - /* - Real scramble is only sent to old servers. This can be blocked - by calling mysql_options(MYSQL *, MYSQL_SECURE_CONNECT, (char*) &1); - */ - end=scramble(strend(end)+1, mysql->scramble_buff, passwd, - (my_bool) (mysql->protocol_version == 9)); - } - /* Add database if needed */ - if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) - { - end=strmake(end+1,db,NAME_LEN); - mysql->db=my_strdup(db,MYF(MY_WME)); - db=0; - } - /* Write authentication package */ - if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - - if (mysql_autenticate(mysql, passwd)) - goto error; - - if (client_flag & CLIENT_COMPRESS) /* We will use compression */ - net->compress=1; - if (mysql->options.max_allowed_packet) - net->max_packet_size= mysql->options.max_allowed_packet; - if (db && mysql_select_db(mysql,db)) - goto error; - - if (mysql->options.init_commands) - { - DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; - char **ptr= (char**)init_commands->buffer; - char **end= ptr + init_commands->elements; - - my_bool reconnect=mysql->reconnect; - mysql->reconnect=0; - - for (; ptr<end; ptr++) - { - MYSQL_RES *res; - if (mysql_query(mysql,*ptr)) - goto error; - if (mysql->fields) - { - if (!(res= mysql_use_result(mysql))) - goto error; - mysql_free_result(res); - } - } - - mysql->reconnect=reconnect; - } - - if (mysql->options.rpl_probe && mysql_rpl_probe(mysql)) - goto error; - - DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); - reset_sigpipe(mysql); - DBUG_RETURN(mysql); - -error: - reset_sigpipe(mysql); - DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error)); - { - /* Free alloced memory */ - my_bool free_me=mysql->free_me; - end_server(mysql); - mysql->free_me=0; - mysql_close(mysql); - mysql->free_me=free_me; - } - DBUG_RETURN(0); -} - - -/* needed when we move MYSQL structure to a different address */ - -static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql) -{ - MYSQL *tmp, *tmp_prev; - if (mysql->master == old_mysql) - mysql->master = mysql; - if (mysql->last_used_con == old_mysql) - mysql->last_used_con = mysql; - if (mysql->last_used_slave == old_mysql) - mysql->last_used_slave = mysql; - for (tmp_prev = mysql, tmp = mysql->next_slave; - tmp != old_mysql;tmp = tmp->next_slave) - { - tmp_prev = tmp; - } - tmp_prev->next_slave = mysql; -} - - -static my_bool mysql_reconnect(MYSQL *mysql) -{ - MYSQL tmp_mysql; - DBUG_ENTER("mysql_reconnect"); - - if (!mysql->reconnect || - (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info) - { - /* Allow reconnect next time */ - mysql->server_status&= ~SERVER_STATUS_IN_TRANS; - mysql->net.last_errno=CR_SERVER_GONE_ERROR; - strmov(mysql->net.last_error,ER(mysql->net.last_errno)); - DBUG_RETURN(1); - } - mysql_init(&tmp_mysql); - tmp_mysql.options=mysql->options; - bzero((char*) &mysql->options,sizeof(mysql->options)); - tmp_mysql.rpl_pivot = mysql->rpl_pivot; - if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, - mysql->db, mysql->port, mysql->unix_socket, - mysql->client_flag)) - { - mysql->net.last_errno= tmp_mysql.net.last_errno; - strmov(mysql->net.last_error, tmp_mysql.net.last_error); - DBUG_RETURN(1); - } - tmp_mysql.free_me=mysql->free_me; - mysql->free_me=0; - mysql_close(mysql); - *mysql=tmp_mysql; - mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */ - net_clear(&mysql->net); - mysql->affected_rows= ~(my_ulonglong) 0; - DBUG_RETURN(0); -} - - /************************************************************************** Change user and database **************************************************************************/ @@ -2569,108 +853,121 @@ error: DBUG_RETURN(1); } +#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) +struct passwd *getpwuid(uid_t); +char* getlogin(void); +#endif -/************************************************************************** - Set current database -**************************************************************************/ - -int STDCALL -mysql_select_db(MYSQL *mysql, const char *db) +#if defined(__NETWARE__) +/* default to "root" on NetWare */ +void read_user_name(char *name) { - int error; - DBUG_ENTER("mysql_select_db"); - DBUG_PRINT("enter",("db: '%s'",db)); - - if ((error=simple_command(mysql,COM_INIT_DB,db,(ulong) strlen(db),0))) - DBUG_RETURN(error); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); - mysql->db=my_strdup(db,MYF(MY_WME)); - DBUG_RETURN(0); + char *str=getenv("USER"); + strmake(name, str ? str : "UNKNOWN_USER", USERNAME_LENGTH); } +#elif !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) && !defined(OS2) -/************************************************************************* - Send a QUIT to the server and close the connection - If handle is alloced by mysql connect free it. -*************************************************************************/ - -void STDCALL -mysql_close(MYSQL *mysql) +void read_user_name(char *name) { - DBUG_ENTER("mysql_close"); - if (mysql) /* Some simple safety */ + DBUG_ENTER("read_user_name"); + if (geteuid() == 0) + (void) strmov(name,"root"); /* allow use of surun */ + else { - if (mysql->net.vio != 0) - { - free_old_query(mysql); - mysql->status=MYSQL_STATUS_READY; /* Force command */ - mysql->reconnect=0; - simple_command(mysql,COM_QUIT,NullS,0,1); - end_server(mysql); /* Sets mysql->net.vio= 0 */ - } - my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); - if (mysql->options.init_commands) - { - DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; - char **ptr= (char**)init_commands->buffer; - char **end= ptr + init_commands->elements; - for (; ptr<end; ptr++) - my_free(*ptr,MYF(MY_WME)); - delete_dynamic(init_commands); - my_free((char*)init_commands,MYF(MY_WME)); - } -#ifdef HAVE_OPENSSL - mysql_ssl_free(mysql); -#endif /* HAVE_OPENSSL */ -#ifdef HAVE_SMEM - if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) - my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); -#endif /* HAVE_SMEM */ - /* Clear pointers for better safety */ - mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; - bzero((char*) &mysql->options,sizeof(mysql->options)); - - /* free/close slave list */ - if (mysql->rpl_pivot) +#ifdef HAVE_GETPWUID + struct passwd *skr; + const char *str; + if ((str=getlogin()) == NULL) { - MYSQL* tmp; - for (tmp = mysql->next_slave; tmp != mysql; ) - { - /* trick to avoid following freed pointer */ - MYSQL* tmp1 = tmp->next_slave; - mysql_close(tmp); - tmp = tmp1; - } - mysql->rpl_pivot=0; + if ((skr=getpwuid(geteuid())) != NULL) + str=skr->pw_name; + else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) && + !(str=getenv("LOGIN"))) + str="UNKNOWN_USER"; } - if (mysql->stmts) + (void) strmake(name,str,USERNAME_LENGTH); +#elif HAVE_CUSERID + (void) cuserid(name); +#else + strmov(name,"UNKNOWN_USER"); +#endif + } + DBUG_VOID_RETURN; +} + +#else /* If MSDOS || VMS */ + +void read_user_name(char *name) +{ + char *str=getenv("USER"); /* ODBC will send user variable */ + strmake(name,str ? str : "ODBC", USERNAME_LENGTH); +} + +#endif + +my_bool send_file_to_server(MYSQL *mysql, const char *filename) +{ + int fd, readcount; + my_bool result= 1; + uint packet_length=MY_ALIGN(mysql->net.max_packet-16,IO_SIZE); + char *buf, tmp_name[FN_REFLEN]; + NET *net= &mysql->net; + DBUG_ENTER("send_file_to_server"); + + if (!(buf=my_malloc(packet_length,MYF(0)))) + { + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY)); + DBUG_RETURN(1); + } + + fn_format(tmp_name,filename,"","",4); /* Convert to client format */ + if ((fd = my_open(tmp_name,O_RDONLY, MYF(0))) < 0) + { + my_net_write(net,"",0); /* Server needs one packet */ + net_flush(net); + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno=EE_FILENOTFOUND; + my_snprintf(net->last_error,sizeof(net->last_error)-1, + EE(net->last_errno),tmp_name, errno); + goto err; + } + + while ((readcount = (int) my_read(fd,(byte*) buf,packet_length,MYF(0))) > 0) + { + if (my_net_write(net,buf,readcount)) { - /* Free any open prepared statements */ - LIST *element, *next_element; - for (element= mysql->stmts; element; element= next_element) - { - next_element= element->next; - stmt_close((MYSQL_STMT *)element->data, 0); - } + DBUG_PRINT("error",("Lost connection to MySQL server during LOAD DATA of local file")); + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno=CR_SERVER_LOST; + strmov(net->last_error,ER(net->last_errno)); + goto err; } - if (mysql != mysql->master) - mysql_close(mysql->master); - if (mysql->free_me) - my_free((gptr) mysql,MYF(0)); } - DBUG_VOID_RETURN; + /* Send empty packet to mark end of file */ + if (my_net_write(net,"",0) || net_flush(net)) + { + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno=CR_SERVER_LOST; + sprintf(net->last_error,ER(net->last_errno),errno); + goto err; + } + if (readcount < 0) + { + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno=EE_READ; /* the errmsg for not entire file read */ + my_snprintf(net->last_error,sizeof(net->last_error)-1, + tmp_name,errno); + goto err; + } + result=0; /* Ok */ + +err: + if (fd >= 0) + (void) my_close(fd,MYF(0)); + my_free(buf,MYF(0)); + DBUG_RETURN(result); } @@ -2746,225 +1043,6 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host, return 0; } - -/* - Send the query and return so we can do something else. - Needs to be followed by mysql_read_query_result() when we want to - finish processing it. -*/ - -int STDCALL -mysql_send_query(MYSQL* mysql, const char* query, ulong length) -{ - DBUG_ENTER("mysql_send_query"); - DBUG_PRINT("enter",("rpl_parse: %d rpl_pivot: %d", - mysql->options.rpl_parse, mysql->rpl_pivot)); - - if (mysql->options.rpl_parse && mysql->rpl_pivot) - { - switch (mysql_rpl_query_type(query, length)) { - case MYSQL_RPL_MASTER: - DBUG_RETURN(mysql_master_send_query(mysql, query, length)); - case MYSQL_RPL_SLAVE: - DBUG_RETURN(mysql_slave_send_query(mysql, query, length)); - case MYSQL_RPL_ADMIN: - break; /* fall through */ - } - } - - mysql->last_used_con = mysql; - DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1)); -} - - -my_bool STDCALL mysql_read_query_result(MYSQL *mysql) -{ - uchar *pos; - ulong field_count; - MYSQL_DATA *fields; - ulong length; - DBUG_ENTER("mysql_read_query_result"); - - /* - Read from the connection which we actually used, which - could differ from the original connection if we have slaves - */ - mysql = mysql->last_used_con; - - if ((length = net_safe_read(mysql)) == packet_error) - DBUG_RETURN(1); - free_old_query(mysql); /* Free old result */ -get_info: - pos=(uchar*) mysql->net.read_pos; - if ((field_count= net_field_length(&pos)) == 0) - { - mysql->affected_rows= net_field_length_ll(&pos); - mysql->insert_id= net_field_length_ll(&pos); - if (protocol_41(mysql)) - { - mysql->server_status=uint2korr(pos); pos+=2; - mysql->warning_count=uint2korr(pos); pos+=2; - } - else if (mysql->server_capabilities & CLIENT_TRANSACTIONS) - { - mysql->server_status=uint2korr(pos); pos+=2; - mysql->warning_count= 0; - } - DBUG_PRINT("info",("status: %ld warning_count: %ld", - mysql->server_status, mysql->warning_count)); - if (pos < mysql->net.read_pos+length && net_field_length(&pos)) - mysql->info=(char*) pos; - DBUG_RETURN(0); - } - if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ - { - int error=send_file_to_server(mysql,(char*) pos); - if ((length=net_safe_read(mysql)) == packet_error || error) - DBUG_RETURN(1); - goto get_info; /* Get info packet */ - } - if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) - mysql->server_status|= SERVER_STATUS_IN_TRANS; - - mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */ - - if (!(fields=read_rows(mysql,(MYSQL_FIELD*)0, protocol_41(mysql) ? 6 : 5))) - DBUG_RETURN(1); - if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc, - (uint) field_count,0, - mysql->server_capabilities))) - DBUG_RETURN(1); - mysql->status= MYSQL_STATUS_GET_RESULT; - mysql->field_count= (uint) field_count; - mysql->warning_count= 0; - DBUG_RETURN(0); -} - - -int STDCALL -mysql_real_query(MYSQL *mysql, const char *query, ulong length) -{ - DBUG_ENTER("mysql_real_query"); - DBUG_PRINT("enter",("handle: %lx",mysql)); - DBUG_PRINT("query",("Query = '%-.4096s'",query)); - - if (mysql_send_query(mysql,query,length)) - DBUG_RETURN(1); - DBUG_RETURN((int) mysql_read_query_result(mysql)); -} - - -static my_bool -send_file_to_server(MYSQL *mysql, const char *filename) -{ - int fd, readcount; - my_bool result= 1; - uint packet_length=MY_ALIGN(mysql->net.max_packet-16,IO_SIZE); - char *buf, tmp_name[FN_REFLEN]; - DBUG_ENTER("send_file_to_server"); - - if (!(buf=my_malloc(packet_length,MYF(0)))) - { - strmov(mysql->net.last_error, ER(mysql->net.last_errno=CR_OUT_OF_MEMORY)); - DBUG_RETURN(1); - } - - fn_format(tmp_name,filename,"","",4); /* Convert to client format */ - if ((fd = my_open(tmp_name,O_RDONLY, MYF(0))) < 0) - { - my_net_write(&mysql->net,"",0); /* Server needs one packet */ - net_flush(&mysql->net); - mysql->net.last_errno=EE_FILENOTFOUND; - my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1, - EE(mysql->net.last_errno),tmp_name, errno); - goto err; - } - - while ((readcount = (int) my_read(fd,(byte*) buf,packet_length,MYF(0))) > 0) - { - if (my_net_write(&mysql->net,buf,readcount)) - { - DBUG_PRINT("error",("Lost connection to MySQL server during LOAD DATA of local file")); - mysql->net.last_errno=CR_SERVER_LOST; - strmov(mysql->net.last_error,ER(mysql->net.last_errno)); - goto err; - } - } - /* Send empty packet to mark end of file */ - if (my_net_write(&mysql->net,"",0) || net_flush(&mysql->net)) - { - mysql->net.last_errno=CR_SERVER_LOST; - sprintf(mysql->net.last_error,ER(mysql->net.last_errno),errno); - goto err; - } - if (readcount < 0) - { - mysql->net.last_errno=EE_READ; /* the errmsg for not entire file read */ - my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1, - tmp_name,errno); - goto err; - } - result=0; /* Ok */ - -err: - if (fd >= 0) - (void) my_close(fd,MYF(0)); - my_free(buf,MYF(0)); - DBUG_RETURN(result); -} - - -/************************************************************************** - Alloc result struct for buffered results. All rows are read to buffer. - mysql_data_seek may be used. -**************************************************************************/ - -MYSQL_RES * STDCALL -mysql_store_result(MYSQL *mysql) -{ - MYSQL_RES *result; - DBUG_ENTER("mysql_store_result"); - - /* read from the actually used connection */ - mysql = mysql->last_used_con; - - if (!mysql->fields) - DBUG_RETURN(0); - if (mysql->status != MYSQL_STATUS_GET_RESULT) - { - strmov(mysql->net.last_error, - ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); - DBUG_RETURN(0); - } - mysql->status=MYSQL_STATUS_READY; /* server is ready */ - if (!(result=(MYSQL_RES*) my_malloc((uint) (sizeof(MYSQL_RES)+ - sizeof(ulong) * - mysql->field_count), - MYF(MY_WME | MY_ZEROFILL)))) - { - mysql->net.last_errno=CR_OUT_OF_MEMORY; - strmov(mysql->net.last_error, ER(mysql->net.last_errno)); - DBUG_RETURN(0); - } - result->eof=1; /* Marker for buffered */ - result->lengths=(ulong*) (result+1); - if (!(result->data=read_rows(mysql,mysql->fields,mysql->field_count))) - { - my_free((gptr) result,MYF(0)); - DBUG_RETURN(0); - } - mysql->affected_rows= result->row_count= result->data->rows; - result->data_cursor= result->data->data; - result->fields= mysql->fields; - result->field_alloc= mysql->field_alloc; - result->field_count= mysql->field_count; - result->current_field=0; - result->current_row=0; /* Must do a fetch first */ - mysql->fields=0; /* fields is now in result */ - DBUG_RETURN(result); /* Data fetched */ -} - - /************************************************************************** Alloc struct for use with unbuffered reads. Data is fetched by domand when calling to mysql_fetch_row. @@ -2987,6 +1065,7 @@ mysql_use_result(MYSQL *mysql) DBUG_RETURN(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { + strmov(mysql->net.sqlstate, unknown_sqlstate); strmov(mysql->net.last_error, ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); DBUG_RETURN(0); @@ -3027,76 +1106,6 @@ mysql_fetch_field(MYSQL_RES *result) return &result->fields[result->current_field++]; } - -/************************************************************************** - Return next row of the query results -**************************************************************************/ - -MYSQL_ROW STDCALL -mysql_fetch_row(MYSQL_RES *res) -{ - DBUG_ENTER("mysql_fetch_row"); - if (!res->data) - { /* Unbufferred fetch */ - if (!res->eof) - { - if (!(read_one_row(res->handle,res->field_count,res->row, res->lengths))) - { - res->row_count++; - DBUG_RETURN(res->current_row=res->row); - } - else - { - DBUG_PRINT("info",("end of data")); - res->eof=1; - res->handle->status=MYSQL_STATUS_READY; - /* Don't clear handle in mysql_free_results */ - res->handle=0; - } - } - DBUG_RETURN((MYSQL_ROW) NULL); - } - { - MYSQL_ROW tmp; - if (!res->data_cursor) - { - DBUG_PRINT("info",("end of data")); - DBUG_RETURN(res->current_row=(MYSQL_ROW) NULL); - } - tmp = res->data_cursor->data; - res->data_cursor = res->data_cursor->next; - DBUG_RETURN(res->current_row=tmp); - } -} - -/************************************************************************** - Get column lengths of the current row - If one uses mysql_use_result, res->lengths contains the length information, - else the lengths are calculated from the offset between pointers. -**************************************************************************/ - -static void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count) -{ - ulong *prev_length; - byte *start=0; - MYSQL_ROW end; - - prev_length=0; /* Keep gcc happy */ - for (end=column + field_count + 1 ; column != end ; column++, to++) - { - if (!*column) - { - *to= 0; /* Null */ - continue; - } - if (start) /* Found end of prev string */ - *prev_length= (ulong) (*column-start-1); - start= *column; - prev_length= to; - } -} - - ulong * STDCALL mysql_fetch_lengths(MYSQL_RES *res) { @@ -3109,21 +1118,6 @@ mysql_fetch_lengths(MYSQL_RES *res) return res->lengths; } -/************************************************************************** - Move to a specific row and column -**************************************************************************/ - -void STDCALL -mysql_data_seek(MYSQL_RES *result, my_ulonglong row) -{ - MYSQL_ROWS *tmp=0; - DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row)); - if (result->data) - for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; - result->current_row=0; - result->data_cursor = tmp; -} - /************************************************************************* put the row or field cursor one a position one got from mysql_row_tell() This doesn't restore any data. The next mysql_fetch_row or @@ -3182,7 +1176,6 @@ mysql_list_tables(MYSQL *mysql, const char *wild) DBUG_RETURN (mysql_store_result(mysql)); } - /************************************************************************** List all fields in a table If wild is given then only the fields matching wild is returned @@ -3224,7 +1217,6 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) DBUG_RETURN(result); } - /* List all running processes (threads) in server */ MYSQL_RES * STDCALL @@ -3252,7 +1244,6 @@ mysql_list_processes(MYSQL *mysql) DBUG_RETURN(mysql_store_result(mysql)); } - #ifdef USE_OLD_FUNCTIONS int STDCALL mysql_create_db(MYSQL *mysql, const char *db) @@ -3316,6 +1307,7 @@ mysql_stat(MYSQL *mysql) mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ if (!mysql->net.read_pos[0]) { + strmov(mysql->net.sqlstate, unknown_sqlstate); mysql->net.last_errno=CR_WRONG_HOST_INFO; strmov(mysql->net.last_error, ER(mysql->net.last_errno)); return mysql->net.last_error; @@ -3387,80 +1379,6 @@ mysql_get_client_info(void) return (char*) MYSQL_SERVER_VERSION; } - -int STDCALL -mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) -{ - DBUG_ENTER("mysql_option"); - DBUG_PRINT("enter",("option: %d",(int) option)); - switch (option) { - case MYSQL_OPT_CONNECT_TIMEOUT: - mysql->options.connect_timeout= *(uint*) arg; - break; - case MYSQL_OPT_COMPRESS: - mysql->options.compress= 1; /* Remember for connect */ - mysql->options.client_flag|= CLIENT_COMPRESS; - break; - case MYSQL_OPT_NAMED_PIPE: - mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */ - break; - case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ - if (!arg || test(*(uint*) arg)) - mysql->options.client_flag|= CLIENT_LOCAL_FILES; - else - mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; - break; - case MYSQL_INIT_COMMAND: - add_init_command(&mysql->options,arg); - break; - case MYSQL_READ_DEFAULT_FILE: - my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.my_cnf_file=my_strdup(arg,MYF(MY_WME)); - break; - case MYSQL_READ_DEFAULT_GROUP: - my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.my_cnf_group=my_strdup(arg,MYF(MY_WME)); - break; - case MYSQL_SET_CHARSET_DIR: - my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.charset_dir=my_strdup(arg,MYF(MY_WME)); - break; - case MYSQL_SET_CHARSET_NAME: - my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.charset_name=my_strdup(arg,MYF(MY_WME)); - break; - case MYSQL_OPT_PROTOCOL: - mysql->options.protocol= *(uint*) arg; - break; - case MYSQL_SHARED_MEMORY_BASE_NAME: -#ifdef HAVE_SMEM - if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) - my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME)); -#endif - break; - default: - DBUG_RETURN(1); - } - DBUG_RETURN(0); -} - -/**************************************************************************** - Functions to get information from the MySQL structure - These are functions to make shared libraries more usable. -****************************************************************************/ - -/* MYSQL_RES */ -my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res) -{ - return res->row_count; -} - -unsigned int STDCALL mysql_num_fields(MYSQL_RES *res) -{ - return res->field_count; -} - my_bool STDCALL mysql_eof(MYSQL_RES *res) { return res->eof; @@ -3503,14 +1421,9 @@ my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql) return mysql->last_used_con->insert_id; } -uint STDCALL mysql_errno(MYSQL *mysql) -{ - return mysql->net.last_errno; -} - -const char * STDCALL mysql_error(MYSQL *mysql) +const char *STDCALL mysql_sqlstate(MYSQL *mysql) { - return mysql->net.last_error; + return mysql->net.sqlstate; } uint STDCALL mysql_warning_count(MYSQL *mysql) @@ -3758,7 +1671,8 @@ myodbc_remove_escape(MYSQL *mysql,char *name) Set the internal stmt error messages */ -static void set_stmt_error(MYSQL_STMT * stmt, int errcode) +static void set_stmt_error(MYSQL_STMT * stmt, int errcode, + const char *sqlstate) { DBUG_ENTER("set_stmt_error"); DBUG_PRINT("enter", ("error: %d '%s'", errcode, ER(errcode))); @@ -3766,6 +1680,7 @@ static void set_stmt_error(MYSQL_STMT * stmt, int errcode) stmt->last_errno= errcode; strmov(stmt->last_error, ER(errcode)); + strmov(stmt->sqlstate, sqlstate); DBUG_VOID_RETURN; } @@ -3775,15 +1690,17 @@ static void set_stmt_error(MYSQL_STMT * stmt, int errcode) Copy error message to statement handler */ -static void set_stmt_errmsg(MYSQL_STMT * stmt, char *err, int errcode) +static void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode, + const char *sqlstate) { DBUG_ENTER("set_stmt_error_msg"); - DBUG_PRINT("enter", ("error: %d '%s'", errcode, err)); + DBUG_PRINT("enter", ("error: %d/%s '%s'", errcode, sqlstate, err)); DBUG_ASSERT(stmt != 0); stmt->last_errno= errcode; if (err && err[0]) strmov(stmt->last_error, err); + strmov(stmt->sqlstate, sqlstate); DBUG_VOID_RETURN; } @@ -3793,7 +1710,7 @@ static void set_stmt_errmsg(MYSQL_STMT * stmt, char *err, int errcode) Set the internal error message to mysql handler */ -static void set_mysql_error(MYSQL * mysql, int errcode) +static void set_mysql_error(MYSQL * mysql, int errcode, const char *sqlstate) { DBUG_ENTER("set_mysql_error"); DBUG_PRINT("enter", ("error :%d '%s'", errcode, ER(errcode))); @@ -3801,6 +1718,7 @@ static void set_mysql_error(MYSQL * mysql, int errcode) mysql->net.last_errno= errcode; strmov(mysql->net.last_error, ER(errcode)); + strmov(mysql->net.sqlstate, sqlstate); } @@ -3847,13 +1765,12 @@ static my_bool my_realloc_str(NET *net, ulong length) 1 error */ -static my_bool read_prepare_result(MYSQL_STMT *stmt) +static my_bool read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) { uchar *pos; uint field_count; ulong length, param_count; MYSQL_DATA *fields_data; - MYSQL *mysql= stmt->mysql; DBUG_ENTER("read_prepare_result"); mysql= mysql->last_used_con; @@ -3871,7 +1788,7 @@ static my_bool read_prepare_result(MYSQL_STMT *stmt) mysql->server_status|= SERVER_STATUS_IN_TRANS; mysql->extra_info= net_field_length_ll(&pos); - if (!(fields_data= read_rows(mysql, (MYSQL_FIELD*) 0, 8))) + if (!(fields_data= read_rows(mysql, (MYSQL_FIELD*) 0, 9))) DBUG_RETURN(1); if (!(stmt->fields= unpack_fields(fields_data,&stmt->mem_root, field_count,0, @@ -3883,7 +1800,7 @@ static my_bool read_prepare_result(MYSQL_STMT *stmt) (param_count + field_count)))) { - set_stmt_error(stmt, CR_OUT_OF_MEMORY); + set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(0); } stmt->bind= (stmt->params + param_count); @@ -3913,7 +1830,7 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length) #ifdef CHECK_EXTRA_ARGUMENTS if (!query) { - set_mysql_error(mysql, CR_NULL_POINTER); + set_mysql_error(mysql, CR_NULL_POINTER, unknown_sqlstate); DBUG_RETURN(0); } #endif @@ -3923,7 +1840,7 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length) !(stmt->query= my_strdup_with_length((byte *) query, length, MYF(0)))) { my_free((gptr) stmt, MYF(MY_ALLOW_ZERO_PTR)); - set_mysql_error(mysql, CR_OUT_OF_MEMORY); + set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(0); } if (simple_command(mysql, COM_PREPARE, query, length, 1)) @@ -3933,13 +1850,13 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length) } init_alloc_root(&stmt->mem_root,8192,0); - stmt->mysql= mysql; - if (read_prepare_result(stmt)) + if (read_prepare_result(mysql, stmt)) { stmt_close(stmt, 1); DBUG_RETURN(0); } stmt->state= MY_ST_PREPARE; + stmt->mysql= mysql; mysql->stmts= list_add(mysql->stmts, &stmt->list); stmt->list.data= stmt; DBUG_PRINT("info", ("Parameter count: %ld", stmt->param_count)); @@ -3955,11 +1872,12 @@ unsigned int alloc_stmt_fields(MYSQL_STMT *stmt) { MYSQL_FIELD *fields, *field, *end; MEM_ROOT *alloc= &stmt->mem_root; + MYSQL *mysql= stmt->mysql->last_used_con; - if (!stmt->mysql->field_count) + if (stmt->state != MY_ST_EXECUTE || !mysql->field_count) return 0; - stmt->field_count= stmt->mysql->field_count; + stmt->field_count= mysql->field_count; /* Get the field information for non-select statements @@ -3971,7 +1889,7 @@ unsigned int alloc_stmt_fields(MYSQL_STMT *stmt) sizeof(MYSQL_BIND ) * stmt->field_count))) return 0; - for (fields= stmt->mysql->fields, end= fields+stmt->field_count, + for (fields= mysql->fields, end= fields+stmt->field_count, field= stmt->fields; field && fields < end; fields++, field++) { @@ -4263,7 +2181,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param) */ if ((my_realloc_str(net, 9 + *param->length))) { - set_stmt_error(stmt, CR_OUT_OF_MEMORY); + set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(1); } (*param->store_param_func)(net, param); @@ -4290,13 +2208,14 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length) length, 1) || mysql_read_query_result(mysql)) { - set_stmt_errmsg(stmt, net->last_error, net->last_errno); + set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); DBUG_RETURN(1); } stmt->state= MY_ST_EXECUTE; mysql_free_result(stmt->result); stmt->result= (MYSQL_RES *)0; stmt->result_buffered= 0; + stmt->current_row= 0; DBUG_RETURN(0); } @@ -4311,7 +2230,7 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) if (stmt->state == MY_ST_UNKNOWN) { - set_stmt_error(stmt, CR_NO_PREPARE_STMT); + set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate); DBUG_RETURN(1); } if (stmt->param_count) @@ -4327,7 +2246,7 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) if (!stmt->param_buffers) { /* Parameters exists, but no bound buffers */ - set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND); + set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND, unknown_sqlstate); DBUG_RETURN(1); } #endif @@ -4362,7 +2281,7 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) /* TODO: Look into avoding the following memdup */ if (!(param_data= my_memdup((const char*) net->buff, length, MYF(0)))) { - set_stmt_error(stmt, CR_OUT_OF_MEMORY); + set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(1); } net->write_pos= net->buff; /* Reset for net_write() */ @@ -4413,12 +2332,12 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) #ifdef CHECK_EXTRA_ARGUMENTS if (stmt->state == MY_ST_UNKNOWN) { - set_stmt_error(stmt, CR_NO_PREPARE_STMT); + set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate); DBUG_RETURN(1); } if (!stmt->param_count) { - set_stmt_error(stmt, CR_NO_PARAMETERS_EXISTS); + set_stmt_error(stmt, CR_NO_PARAMETERS_EXISTS, unknown_sqlstate); DBUG_RETURN(1); } #endif @@ -4501,6 +2420,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) param->store_param_func= store_param_str; break; default: + strmov(stmt->sqlstate, unknown_sqlstate); sprintf(stmt->last_error, ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE), param->buffer_type, count); @@ -4546,7 +2466,7 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number, if (param_number >= stmt->param_count) { - set_stmt_error(stmt, CR_INVALID_PARAMETER_NO); + set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate); DBUG_RETURN(1); } param= stmt->params+param_number; @@ -4557,6 +2477,7 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number, Long data handling should be used only for string/binary types only */ + strmov(stmt->sqlstate, unknown_sqlstate); sprintf(stmt->last_error, ER(stmt->last_errno= CR_INVALID_BUFFER_USE), param->param_number); DBUG_RETURN(1); @@ -4579,8 +2500,8 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number, if (advanced_command(mysql, COM_LONG_DATA, extra_data, MYSQL_LONG_DATA_HEADER, data, length, 1)) { - set_stmt_errmsg(stmt,(char *) mysql->net.last_error, - mysql->net.last_errno); + set_stmt_errmsg(stmt, mysql->net.last_error, + mysql->net.last_errno, mysql->net.sqlstate); DBUG_RETURN(1); } } @@ -4700,6 +2621,8 @@ static void send_data_long(MYSQL_BIND *param, longlong value) char *buffer= param->buffer; switch(param->buffer_type) { + case MYSQL_TYPE_NULL: /* do nothing */ + break; case MYSQL_TYPE_TINY: *param->buffer= (uchar) value; break; @@ -4726,9 +2649,14 @@ static void send_data_long(MYSQL_BIND *param, longlong value) } default: { - uint length= (uint)(longlong10_to_str(value,buffer,10)-buffer); - *param->length= length; - buffer[length]='\0'; + char tmp[NAME_LEN]; + uint length= (uint)(longlong10_to_str(value,(char *)tmp,10)-tmp); + ulong copy_length= min((ulong)length-param->offset, param->buffer_length); + memcpy(buffer, (char *)tmp+param->offset, copy_length); + *param->length= length; + + if (copy_length != param->buffer_length) + *(buffer+copy_length)= '\0'; } } } @@ -4740,6 +2668,8 @@ static void send_data_double(MYSQL_BIND *param, double value) char *buffer= param->buffer; switch(param->buffer_type) { + case MYSQL_TYPE_NULL: /* do nothing */ + break; case MYSQL_TYPE_TINY: *buffer= (uchar)value; break; @@ -4766,9 +2696,14 @@ static void send_data_double(MYSQL_BIND *param, double value) } default: { - uint length= my_sprintf(buffer,(buffer,"%g",value)); - *param->length= length; - buffer[length]='\0'; + char tmp[NAME_LEN]; + uint length= my_sprintf(tmp,(tmp,"%g",value)); + ulong copy_length= min((ulong)length-param->offset, param->buffer_length); + memcpy(buffer, (char *)tmp+param->offset, copy_length); + *param->length= length; + + if (copy_length != param->buffer_length) + *(buffer+copy_length)= '\0'; } } } @@ -4780,6 +2715,8 @@ static void send_data_str(MYSQL_BIND *param, char *value, uint length) int err=0; switch(param->buffer_type) { + case MYSQL_TYPE_NULL: /* do nothing */ + break; case MYSQL_TYPE_TINY: { uchar data= (uchar)my_strntol(&my_charset_latin1,value,length,10,NULL, @@ -4819,12 +2756,20 @@ static void send_data_str(MYSQL_BIND *param, char *value, uint length) float8store(buffer, data); break; } + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + *param->length= length; + length= min(length-param->offset, param->buffer_length); + memcpy(buffer, value+param->offset, length); + break; default: *param->length= length; - length= min(length, param->buffer_length); - memcpy(buffer, value, length); + length= min(length-param->offset, param->buffer_length); + memcpy(buffer, value+param->offset, length); if (length != param->buffer_length) - buffer[length]='\0'; + buffer[length]= '\0'; } } @@ -4832,6 +2777,8 @@ static void send_data_time(MYSQL_BIND *param, MYSQL_TIME ltime, uint length) { switch (param->buffer_type) { + case MYSQL_TYPE_NULL: /* do nothing */ + break; case MYSQL_TYPE_DATE: case MYSQL_TYPE_TIME: @@ -5038,6 +2985,14 @@ static void fetch_result_datetime(MYSQL_BIND *param, uchar **row) *row+= read_binary_datetime(tm, row); } +static void fetch_result_bin(MYSQL_BIND *param, uchar **row) +{ + ulong length= net_field_length(row); + ulong copy_length= min(length, param->buffer_length); + memcpy(param->buffer, (char *)*row, copy_length); + *param->length= length; + *row+= length; +} static void fetch_result_str(MYSQL_BIND *param, uchar **row) { @@ -5051,6 +3006,25 @@ static void fetch_result_str(MYSQL_BIND *param, uchar **row) *row+= length; } +static uint default_binary_field_length(uint field_type) +{ + switch(field_type) { + case MYSQL_TYPE_TINY: + return 1; + case MYSQL_TYPE_SHORT: + return 2; + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + return 4; + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_DOUBLE: + return 8; + default: + return 0; + } +} + + /* Setup the bind buffers for resultset processing */ @@ -5066,12 +3040,12 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) #ifdef CHECK_EXTRA_ARGUMENTS if (stmt->state == MY_ST_UNKNOWN) { - set_stmt_error(stmt, CR_NO_PREPARE_STMT); + set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate); DBUG_RETURN(1); } if (!bind) { - set_stmt_error(stmt, CR_NULL_POINTER); + set_stmt_error(stmt, CR_NULL_POINTER, unknown_sqlstate); DBUG_RETURN(1); } #endif @@ -5095,8 +3069,12 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) param->length= ¶m_length_is_dummy; param->param_number= param_count++; + param->offset= 0; + /* Setup data copy functions for the different supported types */ switch (param->buffer_type) { + case MYSQL_TYPE_NULL: /* for dummy binds */ + break; case MYSQL_TYPE_TINY: param->fetch_result= fetch_result_tinyint; *param->length= 1; @@ -5138,12 +3116,16 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_BLOB: + DBUG_ASSERT(param->buffer_length != 0); + param->fetch_result= fetch_result_bin; + break; case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_STRING: DBUG_ASSERT(param->buffer_length != 0); param->fetch_result= fetch_result_str; break; default: + strmov(stmt->sqlstate, unknown_sqlstate); sprintf(stmt->last_error, ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE), param->buffer_type, param_count); @@ -5179,10 +3161,11 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row) bind++, field++) { if (*null_ptr & bit) - *bind->is_null= 1; + *bind->is_null= bind->null_field= 1; else { - *bind->is_null= 0; + *bind->is_null= bind->null_field= 0; + bind->inter_buffer= row; if (field->type == bind->buffer_type) (*bind->fetch_result)(bind, &row); else @@ -5191,7 +3174,7 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row) fetch_results(bind, field->type, &row, field_is_unsigned); } } - if (! ((bit<<=1) & 255)) + if (!((bit<<=1) & 255)) { bit= 1; /* To next byte */ null_ptr++; @@ -5210,14 +3193,19 @@ int STDCALL mysql_fetch(MYSQL_STMT *stmt) uchar *row; DBUG_ENTER("mysql_fetch"); - row= (uchar *)0; + stmt->last_fetched_column= 0; /* reset */ if (stmt->result_buffered) /* buffered */ { MYSQL_RES *res; - if (!(res= stmt->result) || !res->data_cursor) + if (!(res= stmt->result)) goto no_data; - + + if (!res->data_cursor) + { + res->current_row= 0; + goto no_data; + } row= (uchar *)res->data_cursor->data; res->data_cursor= res->data_cursor->next; res->current_row= (MYSQL_ROW)row; @@ -5226,16 +3214,18 @@ int STDCALL mysql_fetch(MYSQL_STMT *stmt) { if (packet_error == net_safe_read(mysql)) { - set_stmt_errmsg(stmt,(char *)mysql->net.last_error, - mysql->net.last_errno); + set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, + mysql->net.sqlstate); DBUG_RETURN(1); } if (mysql->net.read_pos[0] == 254) { mysql->status= MYSQL_STATUS_READY; + stmt->current_row= 0; goto no_data; } - row= mysql->net.read_pos+1; + row= mysql->net.read_pos+1; + stmt->current_row= row; } DBUG_RETURN(stmt_fetch_row(stmt, row)); @@ -5244,6 +3234,120 @@ no_data: DBUG_RETURN(MYSQL_NO_DATA); /* no more data */ } +/* + Fetch only specified column data to buffers +*/ + +int STDCALL mysql_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, + my_ulonglong icol, + ulong offset) +{ + uchar *row; + my_bool null_data; + + DBUG_ENTER("mysql_fetch_column"); + + if (stmt->result_buffered) + { + if (!stmt->result || !(row= (uchar *)stmt->result->current_row)) + goto no_data; + } + else if (!(row= stmt->current_row)) + goto no_data; + +#ifdef CHECK_EXTRA_ARGUMENTS + if (!bind || icol >= stmt->field_count) + { + DBUG_PRINT("error",("Invalid column position")); + DBUG_RETURN(1); + } +#endif + + /* column '0' == first column */ + if (stmt->res_buffers) + { + /* + Already buffers are parsed and cached to stmt->bind + during mysql_fetch() call. + */ + MYSQL_BIND *param= stmt->bind+icol; + null_data= param->null_field; + row= param->inter_buffer; + } + else + { + if (stmt->last_fetched_column == icol+1) + { + /* + Data buffer is already parsed during the last call, get + the cached information + */ + if (!stmt->last_fetched_buffer) + null_data= 1; + else + { + null_data= 0; + row= stmt->last_fetched_buffer; + } + } + else + { + /* + Advance the data buffer to icol position and cache + the information for subsequent calls + */ + uint bit= icol > 6 ? 1 : 4; + stmt->last_fetched_column= icol+1; + + if (row[icol/8] & (bit << icol & 7)) + { + stmt->last_fetched_buffer= 0; + null_data= 1; + } + else + { + uint length, i; + + null_data= 0; + row+= (stmt->field_count+9)/8; /* skip null bits */ + + for (i=0; i < icol; i++) + { + if (!(length= default_binary_field_length((uint)(stmt->fields[i].type)))) + length= net_field_length(&row); + row+= length; + } + stmt->last_fetched_buffer= row; + } + } + } + if (null_data) + { + if (bind->is_null) + *bind->is_null= 1; + } + else + { + MYSQL_FIELD *field= stmt->fields+icol; + my_bool field_is_unsigned= (field->flags & UNSIGNED_FLAG) ? 1: 0; + + bind->offset= offset; + if (bind->is_null) + *bind->is_null= 0; + if (bind->length) /* Set the length if non char/binary types */ + *bind->length= default_binary_field_length(field->type); + else + bind->length= ¶m_length_is_dummy; + fetch_results(bind, field->type, &row, field_is_unsigned); + } + DBUG_RETURN(0); + +no_data: + DBUG_PRINT("info", ("end of data")); + DBUG_RETURN(MYSQL_NO_DATA); /* no more data */ +} + + /* Read all rows of data from server (binary format) */ @@ -5261,8 +3365,9 @@ static MYSQL_DATA *read_binary_rows(MYSQL_STMT *stmt) mysql= mysql->last_used_con; if ((pkt_len= net_safe_read(mysql)) == packet_error) { - set_stmt_errmsg(stmt,(char *)mysql->net.last_error, - mysql->net.last_errno); + set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, + mysql->net.sqlstate); + DBUG_RETURN(0); } if (mysql->net.read_pos[0] == 254) /* end of data */ @@ -5271,8 +3376,8 @@ static MYSQL_DATA *read_binary_rows(MYSQL_STMT *stmt) if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), MYF(MY_WME | MY_ZEROFILL)))) { - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); + set_stmt_errmsg(stmt, ER(CR_OUT_OF_MEMORY), CR_OUT_OF_MEMORY, + unknown_sqlstate); DBUG_RETURN(0); } init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ @@ -5288,8 +3393,8 @@ static MYSQL_DATA *read_binary_rows(MYSQL_STMT *stmt) !(cur->data= ((MYSQL_ROW) alloc_root(&result->alloc, pkt_len)))) { free_rows(result); - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); + set_stmt_errmsg(stmt, ER(CR_OUT_OF_MEMORY), CR_OUT_OF_MEMORY, + unknown_sqlstate); DBUG_RETURN(0); } *prev_ptr= cur; @@ -5328,7 +3433,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) DBUG_RETURN(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { - set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC); + set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); DBUG_RETURN(1); } mysql->status= MYSQL_STATUS_READY; /* server is ready */ @@ -5337,7 +3442,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) stmt->field_count), MYF(MY_WME | MY_ZEROFILL)))) { - set_stmt_error(stmt, CR_OUT_OF_MEMORY); + set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(1); } stmt->result_buffered= 1; @@ -5445,7 +3550,7 @@ my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt) 0 ok 1 error */ -static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list) +my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list) { MYSQL *mysql; DBUG_ENTER("mysql_stmt_close"); @@ -5477,16 +3582,19 @@ static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list) int4store(buff, stmt->stmt_id); if (simple_command(mysql, COM_CLOSE_STMT, buff, 4, 1)) { - set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno); + set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno, + mysql->net.sqlstate); stmt->mysql= NULL; /* connection isn't valid anymore */ DBUG_RETURN(1); } } mysql_free_result(stmt->result); + stmt->field_count= 0; free_root(&stmt->mem_root, MYF(0)); if (!skip_list) mysql->stmts= list_delete(mysql->stmts, &stmt->list); mysql->status= MYSQL_STATUS_READY; + my_free((gptr) stmt->query, MYF(MY_WME)); my_free((gptr) stmt, MYF(MY_WME)); DBUG_RETURN(0); } @@ -5506,6 +3614,12 @@ uint STDCALL mysql_stmt_errno(MYSQL_STMT * stmt) DBUG_RETURN(stmt->last_errno); } +const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt) +{ + DBUG_ENTER("mysql_stmt_sqlstate"); + DBUG_RETURN(stmt->sqlstate); +} + /* Return statement error message */ @@ -5587,6 +3701,7 @@ my_bool STDCALL mysql_next_result(MYSQL *mysql) mysql->net.last_error[0]= 0; mysql->net.last_errno= 0; + strmov(mysql->net.sqlstate, unknown_sqlstate); mysql->affected_rows= ~(my_ulonglong) 0; if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def index 5a333c51867..bc12e01e420 100644 --- a/libmysql/libmysql.def +++ b/libmysql/libmysql.def @@ -112,24 +112,28 @@ EXPORTS mysql_param_count mysql_bind_param mysql_bind_result + mysql_param_result mysql_prepare_result mysql_stmt_close mysql_stmt_error mysql_stmt_errno mysql_fetch + mysql_fetch_column mysql_send_long_data mysql_next_result + mysql_stmt_affected_rows + mysql_stmt_store_result + mysql_stmt_data_seek + mysql_stmt_row_seek + mysql_stmt_row_tell + mysql_stmt_num_rows + mysql_more_results mysql_commit mysql_rollback mysql_autocommit load_defaults free_defaults - - - - - - + my_path diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index b36f8d92490..c3c99583ad9 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -36,21 +36,21 @@ libmysqlsources = errmsg.c get_password.c noinst_HEADERS = embedded_priv.h -sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \ +sqlsources = derror.cc field.cc field_conv.cc filesort.cc \ ha_innodb.cc ha_berkeley.cc ha_heap.cc ha_isam.cc ha_isammrg.cc \ ha_myisam.cc ha_myisammrg.cc handler.cc sql_handler.cc \ hostname.cc init.cc password.c \ item.cc item_buff.cc item_cmpfunc.cc item_create.cc \ item_func.cc item_strfunc.cc item_sum.cc item_timefunc.cc \ - item_uniq.cc item_subselect.cc item_row.cc\ - key.cc lock.cc log.cc log_event.cc mf_iocache.cc\ - mini_client.cc protocol.cc net_serv.cc opt_ft.cc opt_range.cc \ + item_geofunc.cc item_uniq.cc item_subselect.cc item_row.cc\ + key.cc lock.cc log.cc log_event.cc \ + protocol.cc net_serv.cc opt_ft.cc opt_range.cc \ opt_sum.cc procedure.cc records.cc sql_acl.cc \ - repl_failsafe.cc slave.cc sql_load.cc sql_olap.cc \ + sql_load.cc sql_olap.cc \ sql_analyse.cc sql_base.cc sql_cache.cc sql_class.cc \ sql_crypt.cc sql_db.cc sql_delete.cc sql_error.cc sql_insert.cc \ sql_lex.cc sql_list.cc sql_manager.cc sql_map.cc sql_parse.cc \ - sql_prepare.cc sql_derived.cc sql_rename.cc sql_repl.cc \ + sql_prepare.cc sql_derived.cc sql_rename.cc \ sql_select.cc sql_do.cc sql_show.cc set_var.cc \ sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \ sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \ diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 12647a32713..ecb2cb88a0d 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -183,7 +183,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) MY_INIT((char *)"mysql_embedded"); // init my_sys library & pthreads } - if (init_common_variables("my", argc, argv, (const char **)groups)) + if (init_common_variables("my", *argcp, *argvp, (const char **)groups)) { mysql_server_end(); return 1; diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index 8cf4e2fbe7e..e6166f6bbe5 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -66,7 +66,7 @@ TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"", #define closesocket(A) close(A) #endif -void mysql_once_init(void); +void mysqld_once_init(void); static void end_server(MYSQL *mysql); static void append_wild(char *to,char *end,const char *wild); static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, @@ -373,7 +373,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, MYSQL * STDCALL mysql_init(MYSQL *mysql) { - mysql_once_init(); + mysqld_once_init(); if (!mysql) { if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) @@ -386,7 +386,7 @@ mysql_init(MYSQL *mysql) } -void mysql_once_init() +void mysqld_once_init() { if (!mysql_client_init) { diff --git a/man/Makefile.am b/man/Makefile.am index 7019d2aa865..9f919e77b8f 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -19,7 +19,7 @@ man_MANS = mysql.1 isamchk.1 isamlog.1 mysql_zap.1 mysqlaccess.1 \ mysqladmin.1 mysqld.1 mysqld_multi.1 mysqldump.1 mysqlshow.1 \ - perror.1 replace.1 mysqld_safe.1 + perror.1 replace.1 mysqld_safe.1 mysql_fix_privilege_tables.1 EXTRA_DIST = $(man_MANS) diff --git a/man/isamchk.1 b/man/isamchk.1 index bfc4ccd9c08..341e968a131 100644 --- a/man/isamchk.1 +++ b/man/isamchk.1 @@ -1,4 +1,4 @@ -.TH isamchk 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH isamchk 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME .BR isamchk \- Description, check and repair of ISAM tables. diff --git a/man/isamlog.1 b/man/isamlog.1 index a386f11c010..402c3052ad8 100644 --- a/man/isamlog.1 +++ b/man/isamlog.1 @@ -1,4 +1,4 @@ -.TH isamlog 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH isamlog 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME isamlog - Write info about whats in a nisam log file. .SH USAGE diff --git a/man/mysql.1 b/man/mysql.1 index 6664581072f..c0c37716b14 100644 --- a/man/mysql.1 +++ b/man/mysql.1 @@ -1,4 +1,4 @@ -.TH mysql 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysql 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME mysql \- text-based client for mysqld, a SQL-based relational database daemon .SH SYNOPSIS diff --git a/man/mysql_fix_privilege_tables.1 b/man/mysql_fix_privilege_tables.1 new file mode 100644 index 00000000000..bf4e0e15dfa --- /dev/null +++ b/man/mysql_fix_privilege_tables.1 @@ -0,0 +1,23 @@ +.TH mysql 1 "17 March 2003" "MySQL 4.0" "MySQL database" +.SH NAME +mysql_fix_privilege_tables \- Fixes MySQL privilege tables. +.SH SYNOPSIS +mysql_fix_privilege_tables [options] +.SH DESCRIPTION +This scripts updates the mysql.user, mysql.db, mysql.host and the +mysql.func tables to MySQL 3.22.14 and above. + +This is needed if you want to use the new GRANT functions, +CREATE AGGREGATE FUNCTION or want to use the more secure passwords in 3.23 + +If you get 'Access denied' errors, you should run this script again +and give the MySQL root user password as an argument! + +For more information start the program with '--help'. +.SH "SEE ALSO" +mysql (1), mysqld (1) +.SH AUTHOR +This manpage was written by Christian Hammers <ch@debian.org>. + +MySQL is available at http://www.mysql.com/. +.\" end of man page diff --git a/man/mysql_zap.1 b/man/mysql_zap.1 index 144fc212372..71931c03db6 100644 --- a/man/mysql_zap.1 +++ b/man/mysql_zap.1 @@ -1,4 +1,4 @@ -.TH zap 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH zap 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME zap - a perl script used to kill processes .SH USAGE diff --git a/man/mysqlaccess.1 b/man/mysqlaccess.1 index c1c61d4a8a7..fc7c185e050 100644 --- a/man/mysqlaccess.1 +++ b/man/mysqlaccess.1 @@ -1,4 +1,4 @@ -.TH mysqlaccess 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysqlaccess 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME .BR mysqlaccess \- Create new users to mysql. diff --git a/man/mysqladmin.1 b/man/mysqladmin.1 index 9d7d73aad21..693e8aa5a72 100644 --- a/man/mysqladmin.1 +++ b/man/mysqladmin.1 @@ -1,4 +1,4 @@ -.TH mysqladmin 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysqladmin 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME mysqladmin [OPTIONS] command command.... \- A utility for performing administrative operations .SH OPTION SYNOPSIS diff --git a/man/mysqld.1 b/man/mysqld.1 index 0a6fcccbef2..98247cd9445 100644 --- a/man/mysqld.1 +++ b/man/mysqld.1 @@ -1,4 +1,4 @@ -.TH mysqld 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysqld 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME .BR mysqld \- Starts the MySQL server demon diff --git a/man/mysqld_multi.1 b/man/mysqld_multi.1 index 68b9d1e876f..47418835939 100644 --- a/man/mysqld_multi.1 +++ b/man/mysqld_multi.1 @@ -1,4 +1,4 @@ -.TH mysqld_multi 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysqld_multi 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME mysqld_multi - is meant for managing several mysqld processes running in different UNIX sockets and TCP/IP ports. .SH USAGE diff --git a/man/mysqld_safe.1 b/man/mysqld_safe.1 index b8271c848cc..3679346d7db 100644 --- a/man/mysqld_safe.1 +++ b/man/mysqld_safe.1 @@ -1,4 +1,4 @@ -.TH safe_mysqld 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH safe_mysqld 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME mysqld_safe \- start the mysqld daemon on Unix. .SH SYNOPSIS diff --git a/man/mysqldump.1 b/man/mysqldump.1 index b4aba2ade13..af50366f24c 100644 --- a/man/mysqldump.1 +++ b/man/mysqldump.1 @@ -1,4 +1,4 @@ -.TH mysqldump 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysqldump 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME mysqldump \- text-based client for dumping or backing up mysql databases , tables and or data. diff --git a/man/mysqlshow.1 b/man/mysqlshow.1 index b6aceec82e3..39590b54375 100644 --- a/man/mysqlshow.1 +++ b/man/mysqlshow.1 @@ -1,4 +1,4 @@ -.TH mysqlshow 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH mysqlshow 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME .BR mysqlshow \- Shows the structure of a mysql database (databases,tables and columns) diff --git a/man/perror.1 b/man/perror.1 index 2c5dd9a295f..b8eec8af318 100644 --- a/man/perror.1 +++ b/man/perror.1 @@ -1,4 +1,4 @@ -.TH perror 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH perror 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME perror \- describes a system or MySQL error code. .SH SYNOPSIS diff --git a/man/replace.1 b/man/replace.1 index 7c3b79f605b..46d542d57f4 100644 --- a/man/replace.1 +++ b/man/replace.1 @@ -1,4 +1,4 @@ -.TH replace 1 "19 December 2000" "MySQL 3.23" "MySQL database" +.TH replace 1 "19 December 2000" "MySQL 4.0" "MySQL database" .SH NAME .TP replace - A utility program that is used by msql2mysql, but that has more general applicability as well. replace changes strings in place in files or on the standard input. Uses a finite state machine to match longer strings first. Can be used to swap strings. diff --git a/myisam/ft_boolean_search.c b/myisam/ft_boolean_search.c index 6fa71348002..c59d140da85 100644 --- a/myisam/ft_boolean_search.c +++ b/myisam/ft_boolean_search.c @@ -321,10 +321,10 @@ static void _ftb_init_index_search(FT_INFO *ftb) else /* 3 */ { if (!is_tree_inited(& ftb->no_dupes)) - { init_tree(&ftb->no_dupes,0,0,sizeof(my_off_t), _ftb_no_dupes_cmp, 0, NULL, NULL); - } + else + reset_tree(& ftb->no_dupes); } } diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 75f2a6c83c4..019222fdf22 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -858,15 +858,19 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) { if (b_type & BLOCK_LAST) { - mi_check_print_error(param,"Record link to short for record at %s", - llstr(start_recpos,llbuff)); + mi_check_print_error(param, + "Wrong record length %s of %s at %s", + llstr(block_info.rec_len-left_length,llbuff), + llstr(block_info.rec_len, llbuff2), + llstr(start_recpos,llbuff3)); got_error=1; break; } if (info->state->data_file_length < block_info.next_filepos) { - mi_check_print_error(param,"Found next-recordlink that points outside datafile at %s", - llstr(block_info.filepos,llbuff)); + mi_check_print_error(param, + "Found next-recordlink that points outside datafile at %s", + llstr(block_info.filepos,llbuff)); got_error=1; break; } @@ -2233,7 +2237,17 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, else rec_length=share->base.pack_reclength; sort_info.max_records= - ((param->testflag & T_CREATE_MISSING_KEYS) ? info->state->records : + /* +1 below is required hack for parallel repair mode. + The info->state->records value, that is compared later + to sort_info.max_records and cannot exceed it, is + increased in sort_key_write. In mi_repair_by_sort, sort_key_write + is called after sort_key_read, where the comparison is performed, + but in parallel mode master thread can call sort_key_write + before some other repair thread calls sort_key_read. + Furthermore I'm not even sure +1 would be enough. + May be sort_info.max_records shold be always set to max value in + parallel mode. */ + ((param->testflag & T_CREATE_MISSING_KEYS) ? info->state->records + 1: (ha_rows) (sort_info.filelength/rec_length+1)); del=info->state->del; @@ -3681,12 +3695,14 @@ int update_state_info(MI_CHECK *param, MI_INFO *info,uint update) } if (update & UPDATE_STAT) { - uint key_parts= mi_uint2korr(share->state.header.key_parts); + uint i, key_parts= mi_uint2korr(share->state.header.key_parts); share->state.rec_per_key_rows=info->state->records; - memcpy((char*) share->state.rec_per_key_part, - (char*) param->rec_per_key_part, - sizeof(*param->rec_per_key_part)*key_parts); share->state.changed&= ~STATE_NOT_ANALYZED; + for (i=0; i<key_parts; i++) + { + if (!(share->state.rec_per_key_part[i]=param->rec_per_key_part[i])) + share->state.changed|= STATE_NOT_ANALYZED; + } } if (update & (UPDATE_STAT | UPDATE_SORT | UPDATE_TIME | UPDATE_AUTO_INC)) { diff --git a/myisam/mi_create.c b/myisam/mi_create.c index 964845cc051..26bb23c3a7f 100644 --- a/myisam/mi_create.c +++ b/myisam/mi_create.c @@ -441,7 +441,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, mi_int2store(share.state.header.base_info_length,MI_BASE_INFO_SIZE); mi_int2store(share.state.header.base_pos,base_pos); share.state.header.language= (ci->language ? - ci->language : MY_CHARSET_CURRENT); + ci->language : default_charset_info->number); share.state.header.max_block_size=max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH; share.state.dellink = HA_OFFSET_ERROR; diff --git a/myisam/mi_dynrec.c b/myisam/mi_dynrec.c index dc51269ac35..faf86c3ffbd 100644 --- a/myisam/mi_dynrec.c +++ b/myisam/mi_dynrec.c @@ -485,7 +485,7 @@ int _mi_write_part_record(MI_INFO *info, { info->update&= ~HA_STATE_EXTEND_BLOCK; if (my_block_write(&info->rec_cache,(byte*) *record-head_length, - length+extra_length+del_length,filepos)) + length+extra_length+del_length,filepos)) goto err; } else if (my_b_write(&info->rec_cache,(byte*) *record-head_length, @@ -1412,10 +1412,7 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0))); if (my_read(file,(char*) header,sizeof(info->header),MYF(0)) != sizeof(info->header)) - { - my_errno=HA_ERR_WRONG_IN_RECORD; - return BLOCK_FATAL_ERROR; - } + goto err; } DBUG_DUMP("header",(byte*) header,MI_BLOCK_INFO_HEADER_LENGTH); if (info->second_read) @@ -1435,10 +1432,7 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) if ((info->block_len=(uint) mi_uint3korr(header+1)) < MI_MIN_BLOCK_LENGTH || (info->block_len & (MI_DYN_ALIGN_SIZE -1))) - { - my_errno=HA_ERR_WRONG_IN_RECORD; - return BLOCK_ERROR; - } + goto err; info->filepos=filepos; info->next_filepos=mi_sizekorr(header+4); info->prev_filepos=mi_sizekorr(header+12); @@ -1449,7 +1443,7 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) (mi_uint4korr(header+12) != 0 && (mi_uint4korr(header+12) != (ulong) ~0 || info->prev_filepos != (ulong) ~0))) - return BLOCK_FATAL_ERROR; + goto err; #endif return return_val | BLOCK_DELETED; /* Deleted block */ @@ -1529,8 +1523,9 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) info->second_read=1; info->filepos=filepos+12; return return_val; - default: - my_errno=HA_ERR_WRONG_IN_RECORD; /* Garbage */ - return BLOCK_ERROR; } + +err: + my_errno=HA_ERR_WRONG_IN_RECORD; /* Garbage */ + return BLOCK_ERROR; } diff --git a/myisam/mi_info.c b/myisam/mi_info.c index 0be3cc44d80..32767e73bb1 100644 --- a/myisam/mi_info.c +++ b/myisam/mi_info.c @@ -14,7 +14,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Ger tillbaka en struct med information om isam-filen */ +/* Return useful base information for an open table */ #include "myisamdef.h" #ifdef __WIN__ diff --git a/myisam/mi_key.c b/myisam/mi_key.c index 00a64bca269..a375a415103 100644 --- a/myisam/mi_key.c +++ b/myisam/mi_key.c @@ -145,11 +145,26 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key, } /* _mi_make_key */ - /* Pack a key to intern format from given format (c_rkey) */ - /* returns length of packed key */ +/* + Pack a key to intern format from given format (c_rkey) + + SYNOPSIS + _mi_pack_key() + info MyISAM handler + uint keynr key number + key Store packed key here + old Not packed key + k_length Length of 'old' to use + last_used_keyseg out parameter. May be NULL + + RETURN + length of packed key + + last_use_keyseg Store pointer to the keyseg after the last used one +*/ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, - uint k_length) + uint k_length, HA_KEYSEG **last_used_keyseg) { uint length; uchar *pos,*end,*start_key=key; @@ -220,6 +235,8 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, key+= length; k_length-=length; } + if (last_used_keyseg) + *last_used_keyseg= keyseg; #ifdef NOT_USED if (keyseg->type) diff --git a/myisam/mi_open.c b/myisam/mi_open.c index a1ce135f02f..178365577aa 100644 --- a/myisam/mi_open.c +++ b/myisam/mi_open.c @@ -116,8 +116,10 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) errpos=1; if (my_read(kfile,(char*) share->state.header.file_version,head_length, MYF(MY_NABP))) + { + my_errno= HA_ERR_NOT_A_TABLE; goto err; - + } if (memcmp((byte*) share->state.header.file_version, (byte*) myisam_file_magic, 4)) { @@ -166,7 +168,10 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) } errpos=3; if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP))) + { + my_errno=HA_ERR_CRASHED; goto err; + } len=mi_uint2korr(share->state.header.state_info_length); keys= (uint) share->state.header.keys; uniques= (uint) share->state.header.uniques; diff --git a/myisam/mi_range.c b/myisam/mi_range.c index 4b98b48199a..379ffba135a 100644 --- a/myisam/mi_range.c +++ b/myisam/mi_range.c @@ -59,7 +59,8 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, const byte *start_key, if (start_key_len == 0) start_key_len=USE_WHOLE_KEY; key_buff=info->lastkey+info->s->base.max_key_length; - start_key_len=_mi_pack_key(info,inx,key_buff,(uchar*) start_key,start_key_len); + start_key_len= _mi_pack_key(info,inx,key_buff,(uchar*) start_key, + start_key_len, (HA_KEYSEG**) 0); res=rtree_estimate(info, inx, key_buff, start_key_len, myisam_read_vec[start_search_flag]); res=res?res:1; break; @@ -103,7 +104,8 @@ static ha_rows _mi_record_pos(MI_INFO *info, const byte *key, uint key_len, if (key_len == 0) key_len=USE_WHOLE_KEY; key_buff=info->lastkey+info->s->base.max_key_length; - key_len=_mi_pack_key(info,inx,key_buff,(uchar*) key,key_len); + key_len=_mi_pack_key(info,inx,key_buff,(uchar*) key,key_len, + (HA_KEYSEG**) 0); DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE,keyinfo->seg, (uchar*) key_buff,key_len);); nextflag=myisam_read_vec[search_flag]; diff --git a/myisam/mi_rkey.c b/myisam/mi_rkey.c index 4a3c76809e8..ddfac0a39a2 100644 --- a/myisam/mi_rkey.c +++ b/myisam/mi_rkey.c @@ -23,10 +23,12 @@ /* Ordinary search_flag is 0 ; Give error if no record with key */ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, - enum ha_rkey_function search_flag) + enum ha_rkey_function search_flag) { uchar *key_buff; MYISAM_SHARE *share=info->s; + MI_KEYDEF *keyinfo; + HA_KEYSEG *last_used_keyseg; uint pack_key_length, use_key_length, nextflag; DBUG_ENTER("mi_rkey"); DBUG_PRINT("enter",("base: %lx inx: %d search_flag: %d", @@ -36,25 +38,29 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, DBUG_RETURN(my_errno); info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - info->last_key_func=search_flag; + info->last_key_func= search_flag; + keyinfo= share->keyinfo + inx; if (info->once_flags & USE_PACKED_KEYS) { - /* key is already packed! */ + info->once_flags&= ~USE_PACKED_KEYS; /* Reset flag */ + /* + key is already packed!; This happens when we are using a MERGE TABLE + */ key_buff=info->lastkey+info->s->base.max_key_length; - info->last_rkey_length=pack_key_length=key_len; + pack_key_length= key_len; bmove(key_buff,key,key_len); - info->once_flags&= ~USE_PACKED_KEYS; + last_used_keyseg= 0; } else { if (key_len == 0) key_len=USE_WHOLE_KEY; key_buff=info->lastkey+info->s->base.max_key_length; - pack_key_length=_mi_pack_key(info,(uint) inx,key_buff,(uchar*) key,key_len); - info->last_rkey_length=pack_key_length; - DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE,share->keyinfo[inx].seg, - key_buff,pack_key_length);); + pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key, + key_len, &last_used_keyseg); + DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg, + key_buff, pack_key_length);); } if (fast_mi_readinfo(info)) @@ -67,9 +73,9 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST))) use_key_length=USE_WHOLE_KEY; - switch(info->s->keyinfo[inx].key_alg){ + switch (info->s->keyinfo[inx].key_alg) { case HA_KEY_ALG_RTREE: - if(rtree_find_first(info,inx,key_buff,use_key_length,nextflag)<0) + if (rtree_find_first(info,inx,key_buff,use_key_length,nextflag) < 0) { my_errno=HA_ERR_CRASHED; goto err; @@ -77,8 +83,8 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, break; case HA_KEY_ALG_BTREE: default: - if (!_mi_search(info,info->s->keyinfo+inx,key_buff,use_key_length, - myisam_read_vec[search_flag],info->s->state.key_root[inx])) + if (!_mi_search(info, keyinfo, key_buff, use_key_length, + myisam_read_vec[search_flag], info->s->state.key_root[inx])) { while (info->lastpos >= info->state->data_file_length) { @@ -88,7 +94,7 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, exact key, because the keys are sorted according to position */ - if (_mi_search_next(info,info->s->keyinfo+inx,info->lastkey, + if (_mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length, myisam_readnext_vec[search_flag], info->s->state.key_root[inx])) @@ -99,8 +105,17 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, if (share->concurrent_insert) rw_unlock(&share->key_root_lock[inx]); + /* Calculate length of the found key; Used by mi_rnext_same */ + if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg && + info->lastpos != HA_OFFSET_ERROR) + info->last_rkey_length= _mi_keylength_part(keyinfo, info->lastkey, + last_used_keyseg); + else + info->last_rkey_length= pack_key_length; + + /* Check if we don't want to have record back, only error message */ if (!buf) - DBUG_RETURN(info->lastpos==HA_OFFSET_ERROR ? my_errno : 0); + DBUG_RETURN(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0); if (!(*info->read_record)(info,info->lastpos,buf)) { @@ -110,8 +125,9 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len, info->lastpos = HA_OFFSET_ERROR; /* Didn't find key */ - /* Store key for read next */ + /* Store last used key as a base for read next */ memcpy(info->lastkey,key_buff,pack_key_length); + info->last_rkey_length= pack_key_length; bzero((char*) info->lastkey+pack_key_length,info->s->base.rec_reflength); info->lastkey_length=pack_key_length+info->s->base.rec_reflength; diff --git a/myisam/mi_search.c b/myisam/mi_search.c index 04803d7a901..7e8577c0656 100644 --- a/myisam/mi_search.c +++ b/myisam/mi_search.c @@ -1033,6 +1033,37 @@ uint _mi_keylength(MI_KEYDEF *keyinfo, register uchar *key) } /* _mi_keylength */ +/* + Calculate length of part key. + + Used in mi_rkey() to find the key found for the key-part that was used. + This is needed in case of multi-byte character sets where we may search + after '0xDF' but find 'ss' +*/ + +uint _mi_keylength_part(MI_KEYDEF *keyinfo, register uchar *key, + HA_KEYSEG *end) +{ + reg1 HA_KEYSEG *keyseg; + uchar *start= key; + + for (keyseg=keyinfo->seg ; keyseg != end ; keyseg++) + { + if (keyseg->flag & HA_NULL_PART) + if (!*key++) + continue; + if (keyseg->flag & (HA_SPACE_PACK | HA_BLOB_PART | HA_VAR_LENGTH)) + { + uint length; + get_key_length(length,key); + key+=length; + } + else + key+= keyseg->length; + } + return (uint) (key-start); +} + /* Move a key */ uchar *_mi_move_key(MI_KEYDEF *keyinfo, uchar *to, uchar *from) diff --git a/myisam/mi_test1.c b/myisam/mi_test1.c index 6aa4b9cf9f1..5a6818b8a3e 100644 --- a/myisam/mi_test1.c +++ b/myisam/mi_test1.c @@ -99,7 +99,7 @@ static int run_test(const char *filename) keyinfo[0].seg[0].length=key_length; keyinfo[0].seg[0].null_bit= null_fields ? 2 : 0; keyinfo[0].seg[0].null_pos=0; - keyinfo[0].seg[0].language=MY_CHARSET_CURRENT; + keyinfo[0].seg[0].language= default_charset_info->number; if (pack_seg & HA_BLOB_PART) { keyinfo[0].seg[0].bit_start=4; /* Length of blob length */ @@ -122,7 +122,7 @@ static int run_test(const char *filename) uniqueseg[i].start=start; start+=recinfo[i+1].length; uniqueseg[i].length=recinfo[i+1].length; - uniqueseg[i].language=MY_CHARSET_CURRENT; + uniqueseg[i].language= default_charset_info->number; } uniqueseg[0].type= key_type; uniqueseg[0].null_bit= null_fields ? 2 : 0; diff --git a/myisam/mi_test2.c b/myisam/mi_test2.c index 8c7713c4b4d..8dc279b6d97 100644 --- a/myisam/mi_test2.c +++ b/myisam/mi_test2.c @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) keyinfo[0].seg[0].start=0; keyinfo[0].seg[0].length=6; keyinfo[0].seg[0].type=HA_KEYTYPE_TEXT; - keyinfo[0].seg[0].language=MY_CHARSET_CURRENT; + keyinfo[0].seg[0].language= default_charset_info->number; keyinfo[0].seg[0].flag=(uint8) pack_seg; keyinfo[0].seg[0].null_bit=0; keyinfo[0].seg[0].null_pos=0; @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) keyinfo[3].seg[0].start=0; keyinfo[3].seg[0].length=reclength-(use_blob ? 8 : 0); keyinfo[3].seg[0].type=HA_KEYTYPE_TEXT; - keyinfo[3].seg[0].language=MY_CHARSET_CURRENT; + keyinfo[3].seg[0].language=default_charset_info->number; keyinfo[3].seg[0].flag=(uint8) pack_seg; keyinfo[3].seg[0].null_bit=0; keyinfo[3].seg[0].null_pos=0; @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) keyinfo[4].seg[0].start=0; keyinfo[4].seg[0].length=5; keyinfo[4].seg[0].type=HA_KEYTYPE_TEXT; - keyinfo[4].seg[0].language=MY_CHARSET_CURRENT; + keyinfo[4].seg[0].language=default_charset_info->number; keyinfo[4].seg[0].flag=0; keyinfo[4].seg[0].null_bit=0; keyinfo[4].seg[0].null_pos=0; @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) keyinfo[5].seg[0].start=0; keyinfo[5].seg[0].length=4; keyinfo[5].seg[0].type=HA_KEYTYPE_TEXT; - keyinfo[5].seg[0].language=MY_CHARSET_CURRENT; + keyinfo[5].seg[0].language=default_charset_info->number; keyinfo[5].seg[0].flag=pack_seg; keyinfo[5].seg[0].null_bit=0; keyinfo[5].seg[0].null_pos=0; @@ -645,14 +645,14 @@ int main(int argc, char *argv[]) if ((long) range_records < (long) records*7/10-2 || (long) range_records > (long) records*14/10+2) { - printf("mi_records_range for key: %d returned %ld; Should be about %ld\n", - i, (long) range_records, (long) records); + printf("mi_records_range for key: %d returned %lu; Should be about %lu\n", + i, (ulong) range_records, (ulong) records); goto end; } if (verbose && records) { - printf("mi_records_range returned %ld; Exact is %ld (diff: %4.2g %%)\n", - (long) range_records, (long) records, + printf("mi_records_range returned %lu; Exact is %lu (diff: %4.2g %%)\n", + (ulong) range_records, (ulong) records, labs((long) range_records-(long) records)*100.0/records); } @@ -666,8 +666,8 @@ int main(int argc, char *argv[]) || info.keys != keys) { puts("Wrong info from mi_info"); - printf("Got: records: %ld delete: %ld i_keys: %d\n", - (long) info.records, (long) info.deleted,info.keys); + printf("Got: records: %lu delete: %lu i_keys: %d\n", + (ulong) info.records, (ulong) info.deleted, info.keys); } if (verbose) { diff --git a/myisam/mi_unique.c b/myisam/mi_unique.c index 3eb25aefe0e..f4ee39e55ca 100644 --- a/myisam/mi_unique.c +++ b/myisam/mi_unique.c @@ -109,7 +109,7 @@ ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const byte *record) if (type == HA_KEYTYPE_TEXT || type == HA_KEYTYPE_VARTEXT) { ulong nr=1, nr2=4; - keyseg->charset->hash_sort(keyseg->charset,(const uchar*)pos,length,&nr, &nr2); + keyseg->charset->coll->hash_sort(keyseg->charset,(const uchar*)pos,length,&nr, &nr2); crc=nr; } else diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 104b344a9e2..834ad818972 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -44,6 +44,8 @@ static const char *load_default_groups[]= { "myisamchk", 0 }; static const char *set_charset_name, *opt_tmpdir; static CHARSET_INFO *set_charset; static long opt_myisam_block_size; +static const char *my_progname_short; +static int stopwords_inited= 0; static MY_TMPDIR myisamchk_tmpdir; static const char *type_names[]= @@ -86,6 +88,7 @@ int main(int argc, char **argv) { int error; MY_INIT(argv[0]); + my_progname_short= my_progname+dirname_length(my_progname); #ifdef __EMX__ _wildcard (&argc, &argv); @@ -332,7 +335,7 @@ static void usage(void) puts("This software comes with NO WARRANTY: see the PUBLIC for details.\n"); puts("Description, check and repair of MyISAM tables."); puts("Used without options all tables on the command will be checked for errors"); - printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname); + printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname_short); puts("\nGlobal options:\n\ -#, --debug=... Output debug log. Often this is 'd:t:o,filename'\n\ -?, --help Display this help and exit.\n\ @@ -689,7 +692,7 @@ static void get_options(register int *argc,register char ***argv) { VOID(fprintf(stderr, "%s: --unpack can't be used with --quick or --sort-records\n", - my_progname)); + my_progname_short)); exit(1); } if ((check_param.testflag & T_READONLY) && @@ -699,7 +702,7 @@ static void get_options(register int *argc,register char ***argv) { VOID(fprintf(stderr, "%s: Can't use --readonly when repairing or sorting\n", - my_progname)); + my_progname_short)); exit(1); } @@ -874,7 +877,7 @@ static int myisamchk(MI_CHECK *param, my_string filename) } else { - if (share->state.header.fulltext_keys) + if (share->state.header.fulltext_keys && !stopwords_inited++) ft_init_stopwords(); if (!(param->testflag & T_READONLY)) @@ -1674,13 +1677,13 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...) if (!param->warning_printed && !param->error_printed) { if (param->testflag & T_SILENT) - fprintf(stderr,"%s: MyISAM file %s\n",my_progname, + fprintf(stderr,"%s: MyISAM file %s\n",my_progname_short, param->isam_file_name); param->out_flag|= O_DATA_LOST; } param->warning_printed=1; va_start(args,fmt); - fprintf(stderr,"%s: warning: ",my_progname); + fprintf(stderr,"%s: warning: ",my_progname_short); VOID(vfprintf(stderr, fmt, args)); VOID(fputc('\n',stderr)); fflush(stderr); @@ -1700,12 +1703,12 @@ void mi_check_print_error(MI_CHECK *param, const char *fmt,...) if (!param->warning_printed && !param->error_printed) { if (param->testflag & T_SILENT) - fprintf(stderr,"%s: MyISAM file %s\n",my_progname,param->isam_file_name); + fprintf(stderr,"%s: MyISAM file %s\n",my_progname_short,param->isam_file_name); param->out_flag|= O_DATA_LOST; } param->error_printed|=1; va_start(args,fmt); - fprintf(stderr,"%s: error: ",my_progname); + fprintf(stderr,"%s: error: ",my_progname_short); VOID(vfprintf(stderr, fmt, args)); VOID(fputc('\n',stderr)); fflush(stderr); diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h index 50320f1ecbd..c986c483902 100644 --- a/myisam/myisamdef.h +++ b/myisam/myisamdef.h @@ -537,6 +537,8 @@ extern uchar *_mi_get_last_key(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *keypos, extern uchar *_mi_get_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *page, uchar *key, uchar *keypos, uint *return_key_length); extern uint _mi_keylength(MI_KEYDEF *keyinfo,uchar *key); +extern uint _mi_keylength_part(MI_KEYDEF *keyinfo, register uchar *key, + HA_KEYSEG *end); extern uchar *_mi_move_key(MI_KEYDEF *keyinfo,uchar *to,uchar *from); extern int _mi_search_next(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, uint key_length,uint nextflag,my_off_t pos); @@ -551,7 +553,7 @@ extern my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo); extern uint _mi_make_key(MI_INFO *info,uint keynr,uchar *key, const byte *record,my_off_t filepos); extern uint _mi_pack_key(MI_INFO *info,uint keynr,uchar *key,uchar *old, - uint key_length); + uint key_length, HA_KEYSEG **last_used_keyseg); extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,byte *buf); extern int _mi_read_cache(IO_CACHE *info,byte *buff,my_off_t pos, uint length,int re_read_if_possibly); diff --git a/myisam/rt_test.c b/myisam/rt_test.c index 8bb4687e967..61890bfded1 100644 --- a/myisam/rt_test.c +++ b/myisam/rt_test.c @@ -98,7 +98,7 @@ int run_test(const char *filename) keyinfo[0].seg[i].length=key_length; keyinfo[0].seg[i].null_bit= null_fields ? 2 : 0; keyinfo[0].seg[i].null_pos=0; - keyinfo[0].seg[i].language=MY_CHARSET_CURRENT; + keyinfo[0].seg[i].language=default_charset_info->number; } diff --git a/myisam/sort.c b/myisam/sort.c index 09e487e1165..a41713f750f 100644 --- a/myisam/sort.c +++ b/myisam/sort.c @@ -185,8 +185,8 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, if (maxbuffer == 0) { if (!no_messages) - printf(" - Dumping %lu keys\n",records); - if (write_index(info,sort_keys,(uint) records)) + printf(" - Dumping %lu keys\n", (ulong) records); + if (write_index(info,sort_keys, (uint) records)) goto err; /* purecov: inspected */ } else @@ -195,7 +195,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, if (maxbuffer >= MERGEBUFF2) { if (!no_messages) - printf(" - Merging %lu keys\n",records); /* purecov: tested */ + printf(" - Merging %lu keys\n", (ulong) records); /* purecov: tested */ if (merge_many_buff(info,keys,sort_keys, dynamic_element(&buffpek,0,BUFFPEK *),&maxbuffer,&tempfile)) goto err; /* purecov: inspected */ @@ -308,6 +308,8 @@ pthread_handler_decl(thr_find_all_keys,arg) uint idx, maxbuffer; uchar **sort_keys=0; + LINT_INIT(keys); + error=1; if (my_thread_init()) diff --git a/myisam/sp_test.c b/myisam/sp_test.c index 7021cb4a8ee..c4847217efd 100644 --- a/myisam/sp_test.c +++ b/myisam/sp_test.c @@ -96,7 +96,7 @@ int run_test(const char *filename) keyinfo[0].seg[0].length=1; /* Spatial ignores it anyway */ keyinfo[0].seg[0].null_bit= null_fields ? 2 : 0; keyinfo[0].seg[0].null_pos=0; - keyinfo[0].seg[0].language=MY_CHARSET_CURRENT; + keyinfo[0].seg[0].language=default_charset_info->number; keyinfo[0].seg[0].bit_start=4; /* Long BLOB */ diff --git a/myisammrg/myrg_extra.c b/myisammrg/myrg_extra.c index d375b45df99..62cf5f01aba 100644 --- a/myisammrg/myrg_extra.c +++ b/myisammrg/myrg_extra.c @@ -33,7 +33,7 @@ int myrg_extra(MYRG_INFO *info,enum ha_extra_function function, if (function == HA_EXTRA_CACHE) { info->cache_in_use=1; - info->cache_size= (extra_arg ? *(long*) extra_arg : + info->cache_size= (extra_arg ? *(ulong*) extra_arg : my_default_record_cache_size); } else diff --git a/mysql-test/include/have_ucs2.inc b/mysql-test/include/have_ucs2.inc new file mode 100644 index 00000000000..92ec9b5fb44 --- /dev/null +++ b/mysql-test/include/have_ucs2.inc @@ -0,0 +1,4 @@ +-- require r/have_ucs2.require +disable_query_log; +show collation like "ucs2_general_ci"; +enable_query_log; diff --git a/mysql-test/include/have_ujis.inc b/mysql-test/include/have_ujis.inc new file mode 100644 index 00000000000..ecceb7a8408 --- /dev/null +++ b/mysql-test/include/have_ujis.inc @@ -0,0 +1,4 @@ +-- require r/have_ujis.require +disable_query_log; +show collation like "ujis_japanese_ci"; +enable_query_log; diff --git a/mysql-test/include/not_embedded.inc b/mysql-test/include/not_embedded.inc index 52ae026ece3..fcc1756caab 100644 --- a/mysql-test/include/not_embedded.inc +++ b/mysql-test/include/not_embedded.inc @@ -1,5 +1,5 @@ -- require r/not_embedded.require disable_query_log; -select version() like "%embedded%" as "have_embedded"; +select version() like N'%embedded%' as 'have_embedded'; enable_query_log; diff --git a/mysql-test/install_test_db.sh b/mysql-test/install_test_db.sh index fc3e00d8501..ca6d393e3b4 100644 --- a/mysql-test/install_test_db.sh +++ b/mysql-test/install_test_db.sh @@ -11,10 +11,12 @@ if [ x$1 = x"-bin" ]; then bindir=../bin BINARY_DIST=1 fix_bin=mysql-test + scriptdir=../bin else execdir=../sql bindir=../client fix_bin=. + scriptdir=../scripts fi vardir=var @@ -60,217 +62,11 @@ basedir=. EXTRA_ARG="--language=../sql/share/english/" fi -# Initialize variables -c_d="" i_d="" -c_h="" i_h="" -c_u="" i_u="" -c_f="" i_f="" -c_t="" c_c="" -c_hl="" c_hl="" -c_hc="" c_hc="" -c_clr="" c_clr="" - -# Check for old tables -if test ! -f $mdata/db.frm -then - # mysqld --bootstrap wants one command/line - c_d="$c_d CREATE TABLE db (" - c_d="$c_d Host char(60) DEFAULT '' NOT NULL," - c_d="$c_d Db char(64) DEFAULT '' NOT NULL," - c_d="$c_d User char(16) DEFAULT '' NOT NULL," - c_d="$c_d Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d References_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d PRIMARY KEY Host (Host,Db,User)," - c_d="$c_d KEY User (User)" - c_d="$c_d )" - c_d="$c_d comment='Database privileges';" - - i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); - INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');" -fi - -if test ! -f $mdata/host.frm -then - c_h="$c_h CREATE TABLE host (" - c_h="$c_h Host char(60) DEFAULT '' NOT NULL," - c_h="$c_h Db char(64) DEFAULT '' NOT NULL," - c_h="$c_h Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h References_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h PRIMARY KEY Host (Host,Db)" - c_h="$c_h )" - c_h="$c_h comment='Host privileges; Merged with database privileges';" -fi - -if test ! -f $mdata/user.frm -then - c_u="$c_u CREATE TABLE user (" - c_u="$c_u Host char(60) binary DEFAULT '' NOT NULL," - c_u="$c_u User char(16) binary DEFAULT '' NOT NULL," - c_u="$c_u Password char(45) binary DEFAULT '' NOT NULL," - c_u="$c_u Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Process_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u File_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u References_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Super_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u ssl_type enum('','ANY','X509', 'SPECIFIED') DEFAULT '' NOT NULL," - c_u="$c_u ssl_cipher BLOB NOT NULL," - c_u="$c_u x509_issuer BLOB NOT NULL," - c_u="$c_u x509_subject BLOB NOT NULL," - c_u="$c_u max_questions int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_updates int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_connections int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u PRIMARY KEY Host (Host,User)" - c_u="$c_u )" - c_u="$c_u comment='Users and global privileges';" - - i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - REPLACE INTO user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - INSERT INTO user (host,user) values ('localhost',''); - INSERT INTO user (host,user) values ('$hostname','');" -fi - -if test ! -f $mdata/func.frm -then - c_f="$c_f CREATE TABLE func (" - c_f="$c_f name char(64) DEFAULT '' NOT NULL," - c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL," - c_f="$c_f dl char(128) DEFAULT '' NOT NULL," - c_f="$c_f type enum ('function','aggregate') NOT NULL," - c_f="$c_f PRIMARY KEY (name)" - c_f="$c_f )" - c_f="$c_f comment='User defined functions';" -fi - -if test ! -f $mdata/tables_priv.frm -then - c_t="$c_t CREATE TABLE tables_priv (" - c_t="$c_t Host char(60) DEFAULT '' NOT NULL," - c_t="$c_t Db char(64) DEFAULT '' NOT NULL," - c_t="$c_t User char(16) DEFAULT '' NOT NULL," - c_t="$c_t Table_name char(60) DEFAULT '' NOT NULL," - c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL," - c_t="$c_t Timestamp timestamp(14)," - c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL," - c_t="$c_t Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," - c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name)," - c_t="$c_t KEY Grantor (Grantor)" - c_t="$c_t )" - c_t="$c_t comment='Table privileges';" -fi - -if test ! -f $mdata/columns_priv.frm -then - c_c="$c_c CREATE TABLE columns_priv (" - c_c="$c_c Host char(60) DEFAULT '' NOT NULL," - c_c="$c_c Db char(64) DEFAULT '' NOT NULL," - c_c="$c_c User char(16) DEFAULT '' NOT NULL," - c_c="$c_c Table_name char(64) DEFAULT '' NOT NULL," - c_c="$c_c Column_name char(64) DEFAULT '' NOT NULL," - c_c="$c_c Timestamp timestamp(14)," - c_c="$c_c Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," - c_c="$c_c PRIMARY KEY (Host,Db,User,Table_name,Column_name)" - c_c="$c_c )" - c_c="$c_c comment='Column privileges';" -fi - -if test ! -f $mdata/help_topic.frm -then - c_hl="$c_hl CREATE TABLE help_topic (" - c_hl="$c_hl help_topic_id int unsigned not null auto_increment," - c_hl="$c_hl name varchar(64) not null," - c_hl="$c_hl description text not null," - c_hl="$c_hl example text not null," - c_hl="$c_hl url varchar(128) not null," - c_hl="$c_hl primary key (help_topic_id)," - c_hl="$c_hl unique index (name)" - c_hl="$c_hl )" - c_hl="$c_hl comment='help topics';" -fi - -if test ! -f $mdata/help_category.frm -then - c_clr="$c_clr CREATE TABLE help_category (" - c_clr="$c_clr help_category_id smallint unsigned not null auto_increment," - c_clr="$c_clr name varchar(64) not null," - c_clr="$c_clr url varchar(128) not null," - c_clr="$c_clr primary key (help_category_id)," - c_clr="$c_clr unique index (name)" - c_clr="$c_clr )" - c_clr="$c_clr comment='help topics-categories relation';" -fi - -if test ! -f $mdata/help_relation.frm -then - c_hc="$c_hc CREATE TABLE help_relation (" - c_hc="$c_hc help_topic_id int unsigned not null references help_topic," - c_hc="$c_hc help_category_id smallint unsigned not null references help_category," - c_hc="$c_hc primary key (help_category_id, help_topic_id)," - c_hc="$c_hc )" - c_hc="$c_hc comment='categories of help topics';" -fi - mysqld_boot=" $execdir/mysqld --no-defaults --bootstrap --skip-grant-tables \ --basedir=$basedir --datadir=$ldata --skip-innodb --skip-bdb $EXTRA_ARG" echo "running $mysqld_boot" -if $mysqld_boot << END_OF_DATA -use mysql; -$c_d -$i_d - -$c_h -$i_h - -$c_u -$i_u - -$c_f -$i_f - -$c_t -$c_c - -$c_hl -$c_hc -$c_clr -END_OF_DATA +if $scriptdir/mysql_create_system_tables test $mdata $hostname | $mysqld_boot then exit 0 else diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index a3343b8e019..81e3f866709 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -110,11 +110,11 @@ GREP=grep if test $? != 0; then exit 1; fi PRINTF=printf RM=rm -TIME=`which time` if test $? != 0; then exit 1; fi TR=tr XARGS=`which xargs` if test $? != 0; then exit 1; fi +SORT=sort # Are we using a source or a binary distribution? @@ -413,7 +413,7 @@ fi if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi E=`$EXPR $COLUMNS - 8` -DASH72=`$ECHO '------------------------------------------------------------------------'|$CUT -c 1-$E` +DASH72=`$ECHO '------------------------------------------'|$CUT -c 1-$E` # on source dist, we pick up freshly build executables # on binary, use what is installed @@ -592,9 +592,8 @@ skip_test() { USERT=" ...." SYST=" ...." REALT=" ...." - timestr="$USERT $SYST $REALT" pname=`$ECHO "$1 "|$CUT -c 1-24` - RES="$pname $timestr" + RES="$pname" skip_inc $ECHO "$RES$RES_SPACE [ skipped ]" } @@ -1221,31 +1220,15 @@ run_testcase () $RM -f r/$tname.*reject mysql_test_args="-R r/$tname.result $EXTRA_MYSQL_TEST_OPT" if [ -z "$DO_CLIENT_GDB" ] ; then - mytime=`$TIME -p $MYSQL_TEST $mysql_test_args < $tf 2> $TIMEFILE` + `$MYSQL_TEST $mysql_test_args < $tf 2> $TIMEFILE`; else do_gdb_test "$mysql_test_args" "$tf" fi res=$? - if [ $res = 0 ]; then - mytime=`$CAT $TIMEFILE | $TAIL -3 | $TR '\n' ':'` - - USERT=`$ECHO $mytime | $CUT -d : -f 2 | $CUT -d ' ' -f 2` - USERT=`prefix_to_8 $USERT` - SYST=`$ECHO $mytime | $CUT -d : -f 3 | $CUT -d ' ' -f 2` - SYST=`prefix_to_8 $SYST` - REALT=`$ECHO $mytime | $CUT -d : -f 1 | $CUT -d ' ' -f 2` - REALT=`prefix_to_8 $REALT` - else - USERT=" ...." - SYST=" ...." - REALT=" ...." - fi - - timestr="$USERT $SYST $REALT" pname=`$ECHO "$tname "|$CUT -c 1-24` - RES="$pname $timestr" + RES="$pname" if [ x$many_slaves = x1 ] ; then stop_slave 1 @@ -1380,7 +1363,7 @@ then fi $ECHO -$ECHO " TEST USER SYSTEM ELAPSED RESULT" +$ECHO " TEST RESULT" $ECHO $DASH72 if [ -z "$1" ] ; @@ -1389,7 +1372,7 @@ then $ECHO "Will not run in record mode without a specific test case." else if [ x$TEST_REPLICATION = x1 ]; then - for tf in $TESTDIR/rpl*.$TESTSUFFIX + for tf in `ls -1 $TESTDIR/*.$TESTSUFFIX | $SORT` do run_testcase $tf done diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index aadb35c32e8..6c5e06a289f 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -51,8 +51,8 @@ KEY NAME (NAME)); ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null; SHOW FULL COLUMNS FROM t1; Field Type Collation Null Key Default Extra Privileges Comment -GROUP_ID int(10) unsigned binary PRI 0 select,insert,update,references -LANG_ID smallint(5) unsigned binary PRI 0 select,insert,update,references +GROUP_ID int(10) unsigned NULL PRI 0 select,insert,update,references +LANG_ID smallint(5) unsigned NULL PRI 0 select,insert,update,references NAME char(80) latin1_swedish_ci MUL select,insert,update,references DROP TABLE t1; create table t1 (n int); @@ -92,6 +92,25 @@ key (n2, n3, n4, n1), key (n3, n4, n1, n2), key (n4, n1, n2, n3) ); alter table t1 disable keys; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t1 0 n1 1 n1 A 0 NULL NULL BTREE +t1 1 n1_2 1 n1 A NULL NULL NULL BTREE disabled +t1 1 n1_2 2 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n1_2 3 n3 A NULL NULL NULL YES BTREE disabled +t1 1 n1_2 4 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n2 1 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n2 2 n3 A NULL NULL NULL YES BTREE disabled +t1 1 n2 3 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n2 4 n1 A NULL NULL NULL BTREE disabled +t1 1 n3 1 n3 A NULL NULL NULL YES BTREE disabled +t1 1 n3 2 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n3 3 n1 A NULL NULL NULL BTREE disabled +t1 1 n3 4 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n4 1 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n4 2 n1 A NULL NULL NULL BTREE disabled +t1 1 n4 3 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n4 4 n3 A NULL NULL NULL YES BTREE disabled insert into t1 values(10,RAND()*1000,RAND()*1000,RAND()); insert into t1 values(9,RAND()*1000,RAND()*1000,RAND()); insert into t1 values(8,RAND()*1000,RAND()*1000,RAND()); @@ -103,6 +122,25 @@ insert into t1 values(3,RAND()*1000,RAND()*1000,RAND()); insert into t1 values(2,RAND()*1000,RAND()*1000,RAND()); insert into t1 values(1,RAND()*1000,RAND()*1000,RAND()); alter table t1 enable keys; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t1 0 n1 1 n1 A 10 NULL NULL BTREE +t1 1 n1_2 1 n1 A 10 NULL NULL BTREE +t1 1 n1_2 2 n2 A 10 NULL NULL YES BTREE +t1 1 n1_2 3 n3 A 10 NULL NULL YES BTREE +t1 1 n1_2 4 n4 A 10 NULL NULL YES BTREE +t1 1 n2 1 n2 A 10 NULL NULL YES BTREE +t1 1 n2 2 n3 A 10 NULL NULL YES BTREE +t1 1 n2 3 n4 A 10 NULL NULL YES BTREE +t1 1 n2 4 n1 A 10 NULL NULL BTREE +t1 1 n3 1 n3 A 10 NULL NULL YES BTREE +t1 1 n3 2 n4 A 10 NULL NULL YES BTREE +t1 1 n3 3 n1 A 10 NULL NULL BTREE +t1 1 n3 4 n2 A 10 NULL NULL YES BTREE +t1 1 n4 1 n4 A 10 NULL NULL YES BTREE +t1 1 n4 2 n1 A 10 NULL NULL BTREE +t1 1 n4 3 n2 A 10 NULL NULL YES BTREE +t1 1 n4 4 n3 A 10 NULL NULL YES BTREE drop table t1; create table t1 (i int unsigned not null auto_increment primary key); insert into t1 values (null),(null),(null),(null); @@ -118,7 +156,123 @@ create table t1 (i int unsigned not null auto_increment primary key); alter table t1 rename t2; alter table t2 rename t1, add c char(10) comment "no comment"; show columns from t1; -Field Type Collation Null Key Default Extra -i int(10) unsigned binary PRI NULL auto_increment -c char(10) latin1_swedish_ci YES NULL +Field Type Null Key Default Extra +i int(10) unsigned PRI NULL auto_increment +c char(10) YES NULL +drop table t1; +create table t1 (a int, b int); +insert into t1 values(1,100), (2,100), (3, 100); +insert into t1 values(1,99), (2,99), (3, 99); +insert into t1 values(1,98), (2,98), (3, 98); +insert into t1 values(1,97), (2,97), (3, 97); +insert into t1 values(1,96), (2,96), (3, 96); +insert into t1 values(1,95), (2,95), (3, 95); +insert into t1 values(1,94), (2,94), (3, 94); +insert into t1 values(1,93), (2,93), (3, 93); +insert into t1 values(1,92), (2,92), (3, 92); +insert into t1 values(1,91), (2,91), (3, 91); +insert into t1 values(1,90), (2,90), (3, 90); +insert into t1 values(1,89), (2,89), (3, 89); +insert into t1 values(1,88), (2,88), (3, 88); +insert into t1 values(1,87), (2,87), (3, 87); +insert into t1 values(1,86), (2,86), (3, 86); +insert into t1 values(1,85), (2,85), (3, 85); +insert into t1 values(1,84), (2,84), (3, 84); +insert into t1 values(1,83), (2,83), (3, 83); +insert into t1 values(1,82), (2,82), (3, 82); +insert into t1 values(1,81), (2,81), (3, 81); +insert into t1 values(1,80), (2,80), (3, 80); +insert into t1 values(1,79), (2,79), (3, 79); +insert into t1 values(1,78), (2,78), (3, 78); +insert into t1 values(1,77), (2,77), (3, 77); +insert into t1 values(1,76), (2,76), (3, 76); +insert into t1 values(1,75), (2,75), (3, 75); +insert into t1 values(1,74), (2,74), (3, 74); +insert into t1 values(1,73), (2,73), (3, 73); +insert into t1 values(1,72), (2,72), (3, 72); +insert into t1 values(1,71), (2,71), (3, 71); +insert into t1 values(1,70), (2,70), (3, 70); +insert into t1 values(1,69), (2,69), (3, 69); +insert into t1 values(1,68), (2,68), (3, 68); +insert into t1 values(1,67), (2,67), (3, 67); +insert into t1 values(1,66), (2,66), (3, 66); +insert into t1 values(1,65), (2,65), (3, 65); +insert into t1 values(1,64), (2,64), (3, 64); +insert into t1 values(1,63), (2,63), (3, 63); +insert into t1 values(1,62), (2,62), (3, 62); +insert into t1 values(1,61), (2,61), (3, 61); +insert into t1 values(1,60), (2,60), (3, 60); +insert into t1 values(1,59), (2,59), (3, 59); +insert into t1 values(1,58), (2,58), (3, 58); +insert into t1 values(1,57), (2,57), (3, 57); +insert into t1 values(1,56), (2,56), (3, 56); +insert into t1 values(1,55), (2,55), (3, 55); +insert into t1 values(1,54), (2,54), (3, 54); +insert into t1 values(1,53), (2,53), (3, 53); +insert into t1 values(1,52), (2,52), (3, 52); +insert into t1 values(1,51), (2,51), (3, 51); +insert into t1 values(1,50), (2,50), (3, 50); +insert into t1 values(1,49), (2,49), (3, 49); +insert into t1 values(1,48), (2,48), (3, 48); +insert into t1 values(1,47), (2,47), (3, 47); +insert into t1 values(1,46), (2,46), (3, 46); +insert into t1 values(1,45), (2,45), (3, 45); +insert into t1 values(1,44), (2,44), (3, 44); +insert into t1 values(1,43), (2,43), (3, 43); +insert into t1 values(1,42), (2,42), (3, 42); +insert into t1 values(1,41), (2,41), (3, 41); +insert into t1 values(1,40), (2,40), (3, 40); +insert into t1 values(1,39), (2,39), (3, 39); +insert into t1 values(1,38), (2,38), (3, 38); +insert into t1 values(1,37), (2,37), (3, 37); +insert into t1 values(1,36), (2,36), (3, 36); +insert into t1 values(1,35), (2,35), (3, 35); +insert into t1 values(1,34), (2,34), (3, 34); +insert into t1 values(1,33), (2,33), (3, 33); +insert into t1 values(1,32), (2,32), (3, 32); +insert into t1 values(1,31), (2,31), (3, 31); +insert into t1 values(1,30), (2,30), (3, 30); +insert into t1 values(1,29), (2,29), (3, 29); +insert into t1 values(1,28), (2,28), (3, 28); +insert into t1 values(1,27), (2,27), (3, 27); +insert into t1 values(1,26), (2,26), (3, 26); +insert into t1 values(1,25), (2,25), (3, 25); +insert into t1 values(1,24), (2,24), (3, 24); +insert into t1 values(1,23), (2,23), (3, 23); +insert into t1 values(1,22), (2,22), (3, 22); +insert into t1 values(1,21), (2,21), (3, 21); +insert into t1 values(1,20), (2,20), (3, 20); +insert into t1 values(1,19), (2,19), (3, 19); +insert into t1 values(1,18), (2,18), (3, 18); +insert into t1 values(1,17), (2,17), (3, 17); +insert into t1 values(1,16), (2,16), (3, 16); +insert into t1 values(1,15), (2,15), (3, 15); +insert into t1 values(1,14), (2,14), (3, 14); +insert into t1 values(1,13), (2,13), (3, 13); +insert into t1 values(1,12), (2,12), (3, 12); +insert into t1 values(1,11), (2,11), (3, 11); +insert into t1 values(1,10), (2,10), (3, 10); +insert into t1 values(1,9), (2,9), (3, 9); +insert into t1 values(1,8), (2,8), (3, 8); +insert into t1 values(1,7), (2,7), (3, 7); +insert into t1 values(1,6), (2,6), (3, 6); +insert into t1 values(1,5), (2,5), (3, 5); +insert into t1 values(1,4), (2,4), (3, 4); +insert into t1 values(1,3), (2,3), (3, 3); +insert into t1 values(1,2), (2,2), (3, 2); +insert into t1 values(1,1), (2,1), (3, 1); +alter table t1 add unique (a,b), add key (b); +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 0 a 2 b A NULL NULL NULL YES BTREE +t1 1 b 1 b A 100 NULL NULL YES BTREE +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t1 0 a 1 a A 3 NULL NULL YES BTREE +t1 0 a 2 b A 300 NULL NULL YES BTREE +t1 1 b 1 b A 100 NULL NULL YES BTREE drop table t1; diff --git a/mysql-test/r/ansi.result b/mysql-test/r/ansi.result new file mode 100644 index 00000000000..f9f96310b73 --- /dev/null +++ b/mysql-test/r/ansi.result @@ -0,0 +1,10 @@ +drop table if exists t1; +SELECT 'A' || 'B'; +'A' || 'B' +AB +CREATE TABLE t1 (id INT, id2 int); +SELECT id,NULL,1,1.1,'a' FROM t1 GROUP BY id; +id NULL 1 1.1 a +SELECT id FROM t1 GROUP BY id2; +'t1.id' isn't in GROUP BY +drop table t1; diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 2facb504294..c993a47198a 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -124,6 +124,8 @@ select last_insert_id(); last_insert_id() 255 insert into t1 set i = null; +Warnings: +Warning 1262 Data truncated, out of range for column 'i' at row 1 select last_insert_id(); last_insert_id() 255 diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 7909fabc971..a14ea4d61a6 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -28,6 +28,20 @@ cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME) select cast("1:2:3" as TIME); cast("1:2:3" as TIME) 01:02:03 +set names binary; +select cast(_latin1'test' as char character set latin2); +cast(_latin1'test' as char character set latin2) +test +select cast(_koi8r'ÔÅÓÔ' as char character set cp1251); +cast(_koi8r'ÔÅÓÔ' as char character set cp1251) +òåñò +create table t1 select cast(_koi8r'ÔÅÓÔ' as char character set cp1251) as t; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `t` char(4) character set cp1251 NOT NULL default '' +) TYPE=MyISAM CHARSET=latin1 +drop table t1; select cast("2001-1-1" as date) = "2001-01-01"; cast("2001-1-1" as date) = "2001-01-01" 0 diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index b7243ac5d0b..a80ddc24d05 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -4,6 +4,7 @@ columns_priv db func help_category +help_keyword help_relation help_topic host @@ -19,6 +20,7 @@ columns_priv db func help_category +help_keyword help_relation help_topic host @@ -34,6 +36,7 @@ columns_priv db func help_category +help_keyword help_relation help_topic host diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 76e749ab6e7..45b37dfb719 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -9,6 +9,8 @@ drop table if exists t1; create table t1 (b char(0) not null); create table if not exists t1 (b char(0) not null); insert into t1 values (""),(null); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'b' at row 2 select * from t1; b @@ -27,13 +29,9 @@ The used storage engine can't index column 'b' create table t1 (a int not null auto_increment,primary key (a)) type=heap; create table t1 (a int not null,b text) type=heap; The used table type doesn't support BLOB/TEXT columns -create table t1 (a int ,primary key(a)) type=heap; -All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead drop table if exists t1; create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) type=heap; Incorrect table definition; There can only be one auto column and it must be defined as a key -create table t1 (ordid int(8), primary key (ordid)); -All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead create table not_existing_database.test (a int); Got one of the listed errors create table `a/a` (a int); @@ -84,37 +82,37 @@ drop table t1,t2; create table t1(x varchar(50) ); create table t2 select x from t1 where 1=2; describe t1; -Field Type Collation Null Key Default Extra -x varchar(50) latin1_swedish_ci YES NULL +Field Type Null Key Default Extra +x varchar(50) YES NULL describe t2; -Field Type Collation Null Key Default Extra -x char(50) latin1_swedish_ci YES NULL +Field Type Null Key Default Extra +x char(50) YES NULL drop table t2; create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f; describe t2; -Field Type Collation Null Key Default Extra -a datetime latin1_swedish_ci 0000-00-00 00:00:00 -b time latin1_swedish_ci 00:00:00 -c date latin1_swedish_ci 0000-00-00 -d bigint(17) binary 0 -e double(18,1) binary 0.0 -f bigint(17) binary 0 +Field Type Null Key Default Extra +a datetime 0000-00-00 00:00:00 +b time 00:00:00 +c date 0000-00-00 +d bigint(17) 0 +e double(18,1) 0.0 +f bigint(17) 0 drop table t2; create table t2 select CAST("2001-12-29" AS DATE) as d, CAST("20:45:11" AS TIME) as t, CAST("2001-12-29 20:45:11" AS DATETIME) as dt; describe t2; -Field Type Collation Null Key Default Extra -d date latin1_swedish_ci 0000-00-00 -t time latin1_swedish_ci 00:00:00 -dt datetime latin1_swedish_ci 0000-00-00 00:00:00 +Field Type Null Key Default Extra +d date 0000-00-00 +t time 00:00:00 +dt datetime 0000-00-00 00:00:00 drop table t1,t2; create table t1 (a tinyint); create table t2 (a int) select * from t1; describe t1; -Field Type Collation Null Key Default Extra -a tinyint(4) binary YES NULL +Field Type Null Key Default Extra +a tinyint(4) YES NULL describe t2; -Field Type Collation Null Key Default Extra -a int(11) binary YES NULL +Field Type Null Key Default Extra +a int(11) YES NULL drop table if exists t2; create table t2 (a int, a float) select * from t1; Duplicate column name 'a' @@ -178,6 +176,40 @@ select * from t1; if('2002'='2002','Y','N') Y drop table if exists t1; +SET SESSION table_type="heap"; +SELECT @@table_type; +@@table_type +HEAP +CREATE TABLE t1 (a int not null); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL default '0' +) TYPE=HEAP CHARSET=latin1 +drop table t1; +SET SESSION table_type="gemini"; +SELECT @@table_type; +@@table_type +GEMINI +CREATE TABLE t1 (a int not null); +Warnings: +Warning 1264 Using storage engine MYISAM for table 't1' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL default '0' +) TYPE=MyISAM CHARSET=latin1 +SET SESSION table_type=default; +drop table t1; +create table t1 ( k1 varchar(2), k2 int, primary key(k1,k2)); +insert into t1 values ("a", 1), ("b", 2); +insert into t1 values ("c", NULL); +Column 'k2' cannot be null +insert into t1 values (NULL, 3); +Column 'k1' cannot be null +insert into t1 values (NULL, NULL); +Column 'k1' cannot be null +drop table t1; create table t1 (a int, key(a)); create table t2 (b int, foreign key(b) references t1(a), key(b)); drop table if exists t1,t2; @@ -270,7 +302,7 @@ SELECT @@table_type; GEMINI CREATE TABLE t1 (a int not null); Warnings: -Warning 1259 Using storage engine MYISAM for table 't1' +Warning 1264 Using storage engine MYISAM for table 't1' show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/r/ctype_collate.result b/mysql-test/r/ctype_collate.result index 6e09cff7fd8..00a642d9ee6 100644 --- a/mysql-test/r/ctype_collate.result +++ b/mysql-test/r/ctype_collate.result @@ -4,7 +4,7 @@ CREATE TABLE t1 ( latin1_f CHAR(32) CHARACTER SET latin1 NOT NULL ); CREATE TABLE t2 ( -latin1_f CHAR(32) CHARACTER SET latin1 COLLATE koi8r NOT NULL +latin1_f CHAR(32) CHARACTER SET latin1 COLLATE koi8r_general_ci NOT NULL ); COLLATION 'koi8r_general_ci' is not valid for CHARACTER SET 'latin1' INSERT INTO t1 (latin1_f) VALUES (_latin1'A'); @@ -63,7 +63,7 @@ z Ä ä ß -SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1; +SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1_swedish_ci; latin1_f A a @@ -179,9 +179,9 @@ z ä å ü -SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE koi8r; -COLLATION 'koi8r' is not valid for CHARACTER SET 'latin1' -SELECT latin1_f COLLATE latin1 AS latin1_f_as FROM t1 ORDER BY latin1_f_as; +SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE koi8r_general_ci; +COLLATION 'koi8r_general_ci' is not valid for CHARACTER SET 'latin1' +SELECT latin1_f COLLATE latin1_swedish_ci AS latin1_f_as FROM t1 ORDER BY latin1_f_as; latin1_f_as A a @@ -297,8 +297,8 @@ z ä å ü -SELECT latin1_f COLLATE koi8r AS latin1_f_as FROM t1 ORDER BY latin1_f_as; -COLLATION 'koi8r' is not valid for CHARACTER SET 'latin1' +SELECT latin1_f COLLATE koi8r_general_ci AS latin1_f_as FROM t1 ORDER BY latin1_f_as; +COLLATION 'koi8r_general_ci' is not valid for CHARACTER SET 'latin1' SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f; latin1_f count(*) A 2 @@ -314,7 +314,7 @@ Z 2 Å 2 Ä 2 ß 1 -SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1; +SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1_swedish_ci; latin1_f count(*) A 2 AD 2 @@ -389,8 +389,8 @@ z 1 ä 1 å 1 ü 1 -SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE koi8r; -COLLATION 'koi8r' is not valid for CHARACTER SET 'latin1' +SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE koi8r_general_ci; +COLLATION 'koi8r_general_ci' is not valid for CHARACTER SET 'latin1' SELECT DISTINCT latin1_f FROM t1; latin1_f A @@ -406,8 +406,8 @@ UE SS ß Z -SELECT DISTINCT latin1_f COLLATE latin1 FROM t1; -latin1_f COLLATE latin1 +SELECT DISTINCT latin1_f COLLATE latin1_swedish_ci FROM t1; +latin1_f COLLATE latin1_swedish_ci A AD AE @@ -489,8 +489,8 @@ t1 CREATE TABLE `t1` ( `latin1_f` char(32) NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 SHOW FIELDS FROM t1; -Field Type Collation Null Key Default Extra -latin1_f char(32) latin1_swedish_ci +Field Type Null Key Default Extra +latin1_f char(32) ALTER TABLE t1 CHANGE latin1_f latin1_f CHAR(32) CHARACTER SET latin1 COLLATE latin1_bin; SHOW CREATE TABLE t1; @@ -499,8 +499,8 @@ t1 CREATE TABLE `t1` ( `latin1_f` char(32) character set latin1 collate latin1_bin default NULL ) TYPE=MyISAM CHARSET=latin1 SHOW FIELDS FROM t1; -Field Type Collation Null Key Default Extra -latin1_f char(32) character set latin1 latin1_bin YES NULL +Field Type Null Key Default Extra +latin1_f char(32) YES NULL ALTER TABLE t1 CHARACTER SET latin1 COLLATE latin1_bin; SHOW CREATE TABLE t1; Table Create Table @@ -508,67 +508,21 @@ t1 CREATE TABLE `t1` ( `latin1_f` char(32) collate latin1_bin default NULL ) TYPE=MyISAM CHARSET=latin1 COLLATE=latin1_bin SHOW FIELDS FROM t1; -Field Type Collation Null Key Default Extra -latin1_f char(32) latin1_bin YES NULL +Field Type Null Key Default Extra +latin1_f char(32) YES NULL SET CHARACTER SET 'latin1'; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client latin1_swedish_ci -SET CHARACTER SET latin1; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client latin1_swedish_ci -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client latin1_swedish_ci -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -charset('a') collation('a') coercibility('a') 'a'='A' -latin1 latin1_swedish_ci 3 1 -SET CHARACTER SET latin1 COLLATE latin1_bin; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client latin1_bin -SET CHARACTER SET LATIN1 COLLATE Latin1_Bin; -SHOW VARIABLES LIKE 'collation_client'; +SHOW VARIABLES LIKE 'character_set_client'; Variable_name Value -collation_client latin1_bin -SET CHARACTER SET 'latin1' COLLATE 'latin1_bin'; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client latin1_bin +character_set_client latin1 SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; charset('a') collation('a') coercibility('a') 'a'='A' latin1 latin1_swedish_ci 3 1 SET CHARACTER SET koi8r; SHOW VARIABLES LIKE 'collation_client'; Variable_name Value -collation_client koi8r_general_ci -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -charset('a') collation('a') coercibility('a') 'a'='A' -latin1 latin1_swedish_ci 3 1 -SET CHARACTER SET koi8r COLLATE koi8r_bin; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client koi8r_bin -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -charset('a') collation('a') coercibility('a') 'a'='A' -latin1 latin1_swedish_ci 3 1 -SET CHARACTER SET koi8r COLLATE DEFAULT; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client koi8r_general_ci SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; charset('a') collation('a') coercibility('a') 'a'='A' latin1 latin1_swedish_ci 3 1 -SET CHARACTER SET DEFAULT; -SHOW VARIABLES LIKE 'collation_client'; -Variable_name Value -collation_client latin1_swedish_ci -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -charset('a') collation('a') coercibility('a') 'a'='A' -latin1 latin1_swedish_ci 3 1 -SET CHARACTER SET latin1 COLLATE koi8r; -COLLATION 'koi8r_general_ci' is not valid for CHARACTER SET 'latin1' SET CHARACTER SET 'DEFAULT'; Unknown character set: 'DEFAULT' DROP TABLE t1; diff --git a/mysql-test/r/ctype_latin1_de.result b/mysql-test/r/ctype_latin1_de.result index b79bc67138c..630fef9b679 100644 --- a/mysql-test/r/ctype_latin1_de.result +++ b/mysql-test/r/ctype_latin1_de.result @@ -212,3 +212,55 @@ select * from t1 where match a against ("te*" in boolean mode)+0; a test drop table t1; +create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word)); +insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); +update t1 set word2=word; +select word, word=0xdf as t from t1 having t > 0; +word t +ß 1 +select word, word=cast(0xdf AS CHAR) as t from t1 having t > 0; +word t +ss 1 +ß 1 +select * from t1 where word=0xDF; +word word2 +ß ß +select * from t1 where word=CAST(0xDF as CHAR); +word word2 +ss ss +ß ß +select * from t1 where word2=0xDF; +word word2 +ß ß +select * from t1 where word2=CAST(0xDF as CHAR); +word word2 +ss ss +ß ß +select * from t1 where word='ae'; +word word2 +ä ä +ae ae +select * from t1 where word= 0xe4 or word=CAST(0xe4 as CHAR); +word word2 +ä ä +ae ae +select * from t1 where word between 0xDF and 0xDF; +word word2 +ß ß +select * from t1 where word between CAST(0xDF AS CHAR) and CAST(0xDF AS CHAR); +word word2 +ss ss +ß ß +select * from t1 where word like 'ae'; +word word2 +ae ae +select * from t1 where word like 'AE'; +word word2 +ae ae +select * from t1 where word like 0xDF; +word word2 +ß ß +select * from t1 where word like CAST(0xDF as CHAR); +word word2 +ß ß +drop table t1; diff --git a/mysql-test/r/ctype_recoding.result b/mysql-test/r/ctype_recoding.result index fb813e394f4..23a90be1306 100644 --- a/mysql-test/r/ctype_recoding.result +++ b/mysql-test/r/ctype_recoding.result @@ -13,8 +13,8 @@ Table Create Table `ÐÏÌÅ` char(32) character set koi8r NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 SHOW FIELDS FROM ÔÁÂÌÉÃÁ; -Field Type Collation Null Key Default Extra -ÐÏÌÅ char(32) character set koi8r koi8r_general_ci +Field Type Null Key Default Extra +ÐÏÌÅ char(32) SET CHARACTER SET cp1251; SHOW TABLES; Tables_in_test @@ -25,8 +25,8 @@ Table Create Table `ïîëå` char(32) character set koi8r NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 SHOW FIELDS FROM òàáëèöà; -Field Type Collation Null Key Default Extra -ïîëå char(32) character set koi8r koi8r_general_ci +Field Type Null Key Default Extra +ïîëå char(32) SET CHARACTER SET utf8; SHOW TABLES; Tables_in_test @@ -37,7 +37,8 @@ Table Create Table `поле` char(32) character set koi8r NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 SHOW FIELDS FROM таблица; -Field Type Collation Null Key Default Extra -поле char(32) character set koi8r koi8r_general_ci +Field Type Null Key Default Extra +поле char(32) SET CHARACTER SET koi8r; DROP TABLE ÔÁÂÌÉÃÁ; +SET CHARACTER SET default; diff --git a/mysql-test/r/ctype_ujis.result b/mysql-test/r/ctype_ujis.result new file mode 100644 index 00000000000..ffb305a81cf --- /dev/null +++ b/mysql-test/r/ctype_ujis.result @@ -0,0 +1,8 @@ +drop table if exists t1; +create table t1 (c text character set ujis); +insert into t1 values (0xa4a2),(0xa4a3); +select hex(left(c,1)) from t1 group by c; +hex(left(c,1)) +A4A2 +A4A3 +drop table t1; diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result index ae216f9b380..c87fa8fb927 100644 --- a/mysql-test/r/delete.result +++ b/mysql-test/r/delete.result @@ -46,4 +46,15 @@ NULL d 7 delete from t1 where misc > 5 and bool is null; select * from t1 where misc > 5 and bool is null; bool not_null misc +select count(*) from t1; +count(*) +2 +delete from t1 where 1 > 2; +select count(*) from t1; +count(*) +2 +delete from t1 where 3 > 2; +select count(*) from t1; +count(*) +0 drop table t1; diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index c40e9d9bfa2..5b410396390 100644 --- a/mysql-test/r/fulltext.result +++ b/mysql-test/r/fulltext.result @@ -216,3 +216,13 @@ test.t1 repair status OK select * from t1 where match (a) against ('aaaa'); a drop table t1; +create table t1 ( ref_mag text not null, fulltext (ref_mag)); +insert into t1 values ('test'); +select ref_mag from t1 where match ref_mag against ('+test' in boolean mode); +ref_mag +test +alter table t1 change ref_mag ref_mag char (255) not null; +select ref_mag from t1 where match ref_mag against ('+test' in boolean mode); +ref_mag +test +drop table t1; diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index b7bf3a5cd80..99d7bd2d087 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -47,7 +47,7 @@ sum(all a) count(all a) avg(all a) std(all a) variance(all a) bit_or(all a) bit_ 21 6 3.5000 1.7078 2.9167 7 0 1 6 E select grp, sum(a),count(a),avg(a),std(a),variance(a),bit_or(a),bit_and(a),min(a),max(a),min(c),max(c) from t1 group by grp; grp sum(a) count(a) avg(a) std(a) variance(a) bit_or(a) bit_and(a) min(a) max(a) min(c) max(c) -NULL 0 0 NULL NULL NULL 0 0 NULL NULL +NULL NULL 0 NULL NULL NULL 0 0 NULL NULL 1 1 1 1.0000 0.0000 0.0000 1 1 1 1 a a 2 5 2 2.5000 0.5000 0.2500 3 2 2 3 b c 3 15 3 5.0000 0.8165 0.6667 7 4 4 6 C E @@ -561,4 +561,45 @@ select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 3 NULL 14 Using index 1 SIMPLE t2 index NULL k2 4 NULL 6 Using where; Using index -drop table if exists t1, t2; +drop table t1, t2; +CREATE TABLE t1 (a int, b int); +select count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1; +count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +0 NULL NULL NULL NULL NULL 18446744073709551615 0 +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +insert into t1 values (1,null); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 +insert into t1 values (1,null); +insert into t1 values (2,null); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 0 0 +2 0 NULL NULL NULL NULL NULL 0 0 +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 +2 0 NULL NULL NULL NULL NULL 18446744073709551615 0 +insert into t1 values (2,1); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 0 0 +2 1 1 1.0000 0.0000 1 1 0 1 +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 +2 1 1 1.0000 0.0000 1 1 1 1 +insert into t1 values (3,1); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 0 0 +2 1 1 1.0000 0.0000 1 1 0 1 +3 1 1 1.0000 0.0000 1 1 1 1 +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) +1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 +2 1 1 1.0000 0.0000 1 1 1 1 +3 1 1 1.0000 0.0000 1 1 1 1 +drop table t1; diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 4eed80c4cc9..8d05adcc1ba 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -10,3 +10,6 @@ inet_aton("255.255.255.255.255") inet_aton("255.255.1.255") inet_aton("0.1.255") select inet_ntoa(1099511627775),inet_ntoa(4294902271),inet_ntoa(511); inet_ntoa(1099511627775) inet_ntoa(4294902271) inet_ntoa(511) NULL 255.255.1.255 0.0.1.255 +select length(format('nan', 2)) > 0; +length(format('nan', 2)) > 0 +1 diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 0b386eaf40a..b69af17edd7 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -249,3 +249,45 @@ INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf'); SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password"); 1 DROP TABLE t1; +select collation(lcase(_latin2'a')), coercibility(lcase(_latin2'a')); +collation(lcase(_latin2'a')) coercibility(lcase(_latin2'a')) +latin2_general_ci 3 +select collation(ucase(_latin2'a')), coercibility(ucase(_latin2'a')); +collation(ucase(_latin2'a')) coercibility(ucase(_latin2'a')) +latin2_general_ci 3 +select collation(left(_latin2'a',1)), coercibility(left(_latin2'a',1)); +collation(left(_latin2'a',1)) coercibility(left(_latin2'a',1)) +latin2_general_ci 3 +select collation(right(_latin2'a',1)), coercibility(right(_latin2'a',1)); +collation(right(_latin2'a',1)) coercibility(right(_latin2'a',1)) +latin2_general_ci 3 +select collation(substring(_latin2'a',1,1)), coercibility(substring(_latin2'a',1,1)); +collation(substring(_latin2'a',1,1)) coercibility(substring(_latin2'a',1,1)) +latin2_general_ci 3 +select collation(concat(_latin2'a',_latin2'b')), coercibility(concat(_latin2'a',_latin2'b')); +collation(concat(_latin2'a',_latin2'b')) coercibility(concat(_latin2'a',_latin2'b')) +latin2_general_ci 3 +select collation(concat_ws(_latin2'a',_latin2'b')), coercibility(concat_ws(_latin2'a',_latin2'b')); +collation(concat_ws(_latin2'a',_latin2'b')) coercibility(concat_ws(_latin2'a',_latin2'b')) +latin2_general_ci 3 +create table t1 +select +left(_latin2'a',1), +right(_latin2'a',1), +lcase(_latin2'a'), +ucase(_latin2'a'), +substring(_latin2'a',1,1), +concat(_latin2'a',_latin2'b'), +concat_ws(_latin2'a',_latin2'b'); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `left(_latin2'a',1)` char(1) character set latin2 NOT NULL default '', + `right(_latin2'a',1)` char(1) character set latin2 NOT NULL default '', + `lcase(_latin2'a')` char(1) character set latin2 NOT NULL default '', + `ucase(_latin2'a')` char(1) character set latin2 NOT NULL default '', + `substring(_latin2'a',1,1)` char(1) character set latin2 NOT NULL default '', + `concat(_latin2'a',_latin2'b')` char(2) character set latin2 NOT NULL default '', + `concat_ws(_latin2'a',_latin2'b')` char(1) character set latin2 NOT NULL default '' +) TYPE=MyISAM CHARSET=latin1 +drop table t1; diff --git a/mysql-test/r/func_system.result b/mysql-test/r/func_system.result index 83e78a30396..15ff34a6d80 100644 --- a/mysql-test/r/func_system.result +++ b/mysql-test/r/func_system.result @@ -1,9 +1,51 @@ -select database(),user() like "%@%"; -database() user() like "%@%" -test 1 +select database(); +database() +test +select charset(database()); +charset(database()) +utf8 +select database() = "test"; +database() = "test" +1 +select database() = _utf8"test"; +database() = _utf8"test" +1 +select database() = _latin1"test"; +database() = _latin1"test" +1 +select user() like "%@%"; +user() like "%@%" +1 +select user() like _utf8"%@%"; +user() like _utf8"%@%" +1 +select user() like _latin1"%@%"; +user() like _latin1"%@%" +1 +select charset(user()); +charset(user()) +utf8 +select version()>="3.23.29"; +version()>="3.23.29" +1 select version()>=_utf8"3.23.29"; version()>=_utf8"3.23.29" 1 +select version()>=_latin1"3.23.29"; +version()>=_latin1"3.23.29" +1 +select charset(version()); +charset(version()) +utf8 +create table t1 select database(), user(), version(); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `database()` char(102) character set utf8 NOT NULL default '', + `user()` char(231) character set utf8 NOT NULL default '', + `version()` char(21) character set utf8 NOT NULL default '' +) TYPE=MyISAM CHARSET=latin1 +drop table t1; select TRUE,FALSE,NULL; TRUE FALSE NULL 1 0 NULL diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index a5a280b974f..4317daea0b3 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -8,37 +8,37 @@ CREATE TABLE mp (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON); CREATE TABLE gc (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION); CREATE TABLE geo (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY); SHOW FIELDS FROM pt; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g point binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g point YES NULL SHOW FIELDS FROM ls; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g linestring binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g linestring YES NULL SHOW FIELDS FROM p; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g polygon binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g polygon YES NULL SHOW FIELDS FROM mpt; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g multipoint binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g multipoint YES NULL SHOW FIELDS FROM mls; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g multilinestring binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g multilinestring YES NULL SHOW FIELDS FROM mp; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g multipolygon binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g multipolygon YES NULL SHOW FIELDS FROM gc; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g geometrycollection binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g geometrycollection YES NULL SHOW FIELDS FROM geo; -Field Type Collation Null Key Default Extra -fid int(11) binary PRI 0 -g geometry binary YES NULL +Field Type Null Key Default Extra +fid int(11) PRI 0 +g geometry YES NULL INSERT INTO pt VALUES (101, PointFromText('POINT(10 10)')), (102, PointFromText('POINT(20 10)')), @@ -366,27 +366,27 @@ gc geometrycollection, gm geometry ); SHOW FIELDS FROM g1; -Field Type Collation Null Key Default Extra -pt point binary YES NULL -ln linestring binary YES NULL -pg polygon binary YES NULL -mpt multipoint binary YES NULL -mln multilinestring binary YES NULL -mpg multipolygon binary YES NULL -gc geometrycollection binary YES NULL -gm geometry binary YES NULL +Field Type Null Key Default Extra +pt point YES NULL +ln linestring YES NULL +pg polygon YES NULL +mpt multipoint YES NULL +mln multilinestring YES NULL +mpg multipolygon YES NULL +gc geometrycollection YES NULL +gm geometry YES NULL ALTER TABLE g1 ADD fid INT NOT NULL; SHOW FIELDS FROM g1; -Field Type Collation Null Key Default Extra -pt point binary YES NULL -ln linestring binary YES NULL -pg polygon binary YES NULL -mpt multipoint binary YES NULL -mln multilinestring binary YES NULL -mpg multipolygon binary YES NULL -gc geometrycollection binary YES NULL -gm geometry binary YES NULL -fid int(11) binary 0 +Field Type Null Key Default Extra +pt point YES NULL +ln linestring YES NULL +pg polygon YES NULL +mpt multipoint YES NULL +mln multilinestring YES NULL +mpg multipolygon YES NULL +gc geometrycollection YES NULL +gm geometry YES NULL +fid int(11) 0 DROP TABLE g1; SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))); AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 337d5639056..9e89f2c0e5a 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -29,6 +29,8 @@ PRIMARY KEY (userID) INSERT INTO t2 VALUES (1,'name','pass','mail','Y','v','n','adr','1','1','1'); INSERT INTO t2 VALUES (2,'name','pass','mail','Y','v','n','adr','1','1','1'); INSERT INTO t2 VALUES (3,'name','pass','mail','Y','v','n','adr','1','1','1'); +INSERT INTO t2 VALUES (4,'name','pass','mail','Y','v','n','adr','1','1','1'); +INSERT INTO t2 VALUES (5,'name','pass','mail','Y','v','n','adr','1','1','1'); SELECT t2.userid, MIN(t1.score) FROM t1, t2 WHERE t1.userID=t2.userID GROUP BY t2.userid; userid MIN(t1.score) 1 1 @@ -49,8 +51,12 @@ userid MIN(t1.score+0.0) 2 2.0 SELECT t2.userid, MIN(t1.score+0.0) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid ORDER BY NULL; userid MIN(t1.score+0.0) -1 1.0 2 2.0 +1 1.0 +EXPLAIN SELECT t2.userid, MIN(t1.score+0.0) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid ORDER BY NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where; Using temporary +1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 t1.userID 1 Using index drop table t1,t2; CREATE TABLE t1 ( PID int(10) unsigned NOT NULL auto_increment, @@ -144,34 +150,92 @@ KEY qa_contact (qa_contact), KEY votes (votes) ); INSERT INTO t1 VALUES (1,0,0,'','normal','','2000-02-10 09:25:12',20000321114747,'','','Linux','P1','TestProduct','PC',3,'other','TestComponent','','M1',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (9,0,0,'','enhancement','','2000-03-10 11:49:36',20000321114747,'','','All','P5','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (10,0,0,'','enhancement','','2000-03-10 18:10:16',20000321114747,'','','All','P4','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (7,0,0,'','critical','','2000-03-09 10:50:21',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (6,0,0,'','normal','','2000-03-09 10:42:44',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (8,0,0,'','major','','2000-03-09 11:32:14',20000321114747,'','','All','P3','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (5,0,0,'','enhancement','','2000-03-09 10:38:59',20000321114747,'','','All','P5','CCC/CCCCCC','PC',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (4,0,0,'','normal','','2000-03-08 18:32:14',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent2','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (3,0,0,'','normal','','2000-03-08 18:30:52',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (2,0,0,'','enhancement','','2000-03-08 18:24:51',20000321114747,'','','All','P2','TestProduct','Other',4,'other','TestComponent2','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (11,0,0,'','blocker','','2000-03-13 09:43:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (12,0,0,'','normal','','2000-03-13 16:14:31',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (13,0,0,'','normal','','2000-03-15 16:20:44',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (14,0,0,'','blocker','','2000-03-15 18:13:47',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (15,0,0,'','minor','','2000-03-16 18:03:28',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (16,0,0,'','normal','','2000-03-16 18:33:41',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (17,0,0,'','normal','','2000-03-16 18:34:18',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (18,0,0,'','normal','','2000-03-16 18:34:56',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (19,0,0,'','enhancement','','2000-03-16 18:35:34',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (20,0,0,'','enhancement','','2000-03-16 18:36:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (21,0,0,'','enhancement','','2000-03-16 18:37:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (22,0,0,'','enhancement','','2000-03-16 18:38:16',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (23,0,0,'','normal','','2000-03-16 18:58:12',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (24,0,0,'','normal','','2000-03-17 11:08:10',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (25,0,0,'','normal','','2000-03-17 11:10:45',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (26,0,0,'','normal','','2000-03-17 11:15:47',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (27,0,0,'','normal','','2000-03-17 17:45:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (28,0,0,'','normal','','2000-03-20 09:51:45',20000321114747,'','','Windows NT','P2','TestProduct','PC',8,'other','TestComponent','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 INSERT INTO t1 VALUES (29,0,0,'','normal','','2000-03-20 11:15:09',20000321114747,'','','All','P5','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0); +Warnings: +Warning 1263 Data truncated for column 'bug_status' at row 1 CREATE TABLE t2 ( value tinytext, program varchar(64), @@ -244,34 +308,32 @@ score smallint(5) unsigned, key (spid), key (score) ); -INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3); +INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3),(6,3,3),(7,3,3); explain select userid,count(*) from t1 group by userid desc; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using temporary; Using filesort explain select userid,count(*) from t1 group by userid desc order by null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using temporary select userid,count(*) from t1 group by userid desc; userid count(*) -3 3 +3 5 2 1 1 2 select userid,count(*) from t1 group by userid desc having (count(*)+1) IN (4,3); userid count(*) -3 3 1 2 select userid,count(*) from t1 group by userid desc having 3 IN (1,COUNT(*)); userid count(*) -3 3 explain select spid,count(*) from t1 where spid between 1 and 2 group by spid desc; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range spID spID 5 NULL 2 Using where; Using index +1 SIMPLE t1 range spID spID 5 NULL 3 Using where; Using index explain select spid,count(*) from t1 where spid between 1 and 2 group by spid; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range spID spID 5 NULL 2 Using where; Using index +1 SIMPLE t1 range spID spID 5 NULL 3 Using where; Using index explain select spid,count(*) from t1 where spid between 1 and 2 group by spid order by null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range spID spID 5 NULL 2 Using where; Using index +1 SIMPLE t1 range spID spID 5 NULL 3 Using where; Using index select spid,count(*) from t1 where spid between 1 and 2 group by spid; spid count(*) 1 1 @@ -282,12 +344,14 @@ spid count(*) 1 1 explain select sql_big_result spid,sum(userid) from t1 group by spid desc; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using filesort explain select sql_big_result spid,sum(userid) from t1 group by spid desc order by null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 6 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 select sql_big_result spid,sum(userid) from t1 group by spid desc; spid sum(userid) +7 3 +6 3 5 3 4 3 3 3 @@ -295,13 +359,13 @@ spid sum(userid) 1 1 explain select sql_big_result score,count(*) from t1 group by score desc; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL score 3 NULL 6 Using index +1 SIMPLE t1 index NULL score 3 NULL 8 Using index explain select sql_big_result score,count(*) from t1 group by score desc order by null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL score 3 NULL 6 Using index +1 SIMPLE t1 index NULL score 3 NULL 8 Using index select sql_big_result score,count(*) from t1 group by score desc; score count(*) -3 3 +3 5 2 1 1 2 drop table t1; @@ -536,15 +600,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL a NULL NULL NULL 4 Using where drop table t1,t2; create table t1 (a int, b int); -insert into t1 values (1, 4); -insert into t1 values (10, 40); -insert into t1 values (1, 4); -insert into t1 values (10, 43); -insert into t1 values (1, 4); -insert into t1 values (10, 41); -insert into t1 values (1, 4); -insert into t1 values (10, 43); -insert into t1 values (1, 4); +insert into t1 values (1, 4),(10, 40),(1, 4),(10, 43),(1, 4),(10, 41),(1, 4),(10, 43),(1, 4); select a, MAX(b), INTERVAL (MAX(b), 1,3,10,30,39,40,50,60,100,1000) from t1 group by a; a MAX(b) INTERVAL (MAX(b), 1,3,10,30,39,40,50,60,100,1000) 1 4 2 diff --git a/mysql-test/r/have_ucs2.require b/mysql-test/r/have_ucs2.require new file mode 100644 index 00000000000..c53250aeaef --- /dev/null +++ b/mysql-test/r/have_ucs2.require @@ -0,0 +1,2 @@ +Collation Charset Id Default Compiled Sortlen +ucs2_general_ci ucs2 35 Yes Yes 1 diff --git a/mysql-test/r/have_ujis.require b/mysql-test/r/have_ujis.require new file mode 100644 index 00000000000..b4de2234ec7 --- /dev/null +++ b/mysql-test/r/have_ujis.require @@ -0,0 +1,2 @@ +Collation Charset Id Default Compiled Sortlen +ujis_japanese_ci ujis 12 Yes Yes 0 diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index bd1bd523964..fc0b3c652ef 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -67,3 +67,18 @@ Fld1 max(Fld2) 1 20 3 50 drop table t1; +create table t1 (id int not null, qty int not null); +insert into t1 values (1,2),(1,3),(2,4),(2,5); +select id, sum(qty) as sqty from t1 group by id having sqty>2; +id sqty +1 5 +2 9 +select sum(qty) as sqty from t1 group by id having count(id) > 0; +sqty +5 +9 +select sum(qty) as sqty from t1 group by id having count(distinct id) > 0; +sqty +5 +9 +drop table t1; diff --git a/mysql-test/r/heap.result b/mysql-test/r/heap.result index 76022b66100..ab5870357f9 100644 --- a/mysql-test/r/heap.result +++ b/mysql-test/r/heap.result @@ -164,6 +164,12 @@ select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn; update t1 set new_col=btn; +Warnings: +Warning 1263 Data truncated for column 'new_col' at row 1 +Warning 1263 Data truncated for column 'new_col' at row 2 +Warning 1263 Data truncated for column 'new_col' at row 3 +Warning 1263 Data truncated for column 'new_col' at row 4 +Warning 1263 Data truncated for column 'new_col' at row 5 explain select * from t1 where btn="a"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where diff --git a/mysql-test/r/heap_btree.result b/mysql-test/r/heap_btree.result index bf24f78321f..7f6c9f8e591 100644 --- a/mysql-test/r/heap_btree.result +++ b/mysql-test/r/heap_btree.result @@ -180,6 +180,12 @@ select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn; update t1 set new_col=btn; +Warnings: +Warning 1263 Data truncated for column 'new_col' at row 1 +Warning 1263 Data truncated for column 'new_col' at row 2 +Warning 1263 Data truncated for column 'new_col' at row 3 +Warning 1263 Data truncated for column 'new_col' at row 4 +Warning 1263 Data truncated for column 'new_col' at row 5 explain select * from t1 where btn="a"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref btn btn 10 const 1 Using where diff --git a/mysql-test/r/heap_hash.result b/mysql-test/r/heap_hash.result index 3c2baa645f7..9554990aa34 100644 --- a/mysql-test/r/heap_hash.result +++ b/mysql-test/r/heap_hash.result @@ -164,6 +164,12 @@ select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn; update t1 set new_col=btn; +Warnings: +Warning 1263 Data truncated for column 'new_col' at row 1 +Warning 1263 Data truncated for column 'new_col' at row 2 +Warning 1263 Data truncated for column 'new_col' at row 3 +Warning 1263 Data truncated for column 'new_col' at row 4 +Warning 1263 Data truncated for column 'new_col' at row 5 explain select * from t1 where btn="a"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where diff --git a/mysql-test/r/help.result b/mysql-test/r/help.result index 4da4a84d4ad..d22539b2bcb 100644 --- a/mysql-test/r/help.result +++ b/mysql-test/r/help.result @@ -1,123 +1,243 @@ -truncate mysql.help_topic; -truncate mysql.help_category; -truncate mysql.help_relation; -insert into mysql.help_topic(name,description,example)values('impossible_function_1','description of \n impossible_function1','example of \n impossible_function1'); -SELECT @topic1_id:=LAST_INSERT_ID(); -@topic1_id:=LAST_INSERT_ID() +insert into mysql.help_category(help_category_id,name)values(1,'impossible_category_1'); +select @category1_id:= 1; +@category1_id:= 1 1 -insert into mysql.help_topic(name,description,example)values('impossible_function_2','description of \n impossible_function2','example of \n impossible_function2'); -SELECT @topic2_id:=LAST_INSERT_ID(); -@topic2_id:=LAST_INSERT_ID() +insert into mysql.help_category(help_category_id,name)values(2,'impossible_category_2'); +select @category2_id:= 2; +@category2_id:= 2 2 -insert into mysql.help_topic(name,description,example)values('impossible_function_3','description of \n impossible_function3','example of \n impossible_function3'); -SELECT @topic3_id:=LAST_INSERT_ID(); -@topic3_id:=LAST_INSERT_ID() +insert into mysql.help_category(help_category_id,name,parent_category_id)values(3,'impossible_category_3',@category2_id); +select @category3_id:= 3; +@category3_id:= 3 3 -insert into mysql.help_category(name)values('impossible_category_1'); -SELECT @category1_id:=LAST_INSERT_ID(); -@category1_id:=LAST_INSERT_ID() +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(1,'impossible_function_1',@category1_id,'description of \n impossible_function1\n','example of \n impossible_function1'); +select @topic1_id:= 1; +@topic1_id:= 1 1 -insert into mysql.help_category(name)values('impossible_category_2'); -SELECT @category2_id:=LAST_INSERT_ID(); -@category2_id:=LAST_INSERT_ID() +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(2,'impossible_function_2',@category1_id,'description of \n impossible_function2\n','example of \n impossible_function2'); +select @topic2_id:= 2; +@topic2_id:= 2 2 -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category1_id,@topic1_id); -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category1_id,@topic2_id); -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category2_id,@topic2_id); -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category2_id,@topic3_id); +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(3,'impossible_function_3',@category2_id,'description of \n impossible_function3\n','example of \n impossible_function3'); +select @topic3_id:= 3; +@topic3_id:= 3 +3 +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(4,'impossible_function_4',@category2_id,'description of \n impossible_function4\n','example of \n impossible_function4'); +select @topic4_id:= 4; +@topic4_id:= 4 +4 +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(5,'impossible_function_7',@category3_id,'description of \n impossible_function5\n','example of \n impossible_function7'); +select @topic5_id:= 5; +@topic5_id:= 5 +5 +insert into mysql.help_keyword(help_keyword_id,name)values(1,'impossible_function_1'); +select @keyword1_id:= 1; +@keyword1_id:= 1 +1 +insert into mysql.help_keyword(help_keyword_id,name)values(2,'impossible_function_5'); +select @keyword2_id:= 2; +@keyword2_id:= 2 +2 +insert into mysql.help_keyword(help_keyword_id,name)values(3,'impossible_function_6'); +select @keyword3_id:= 3; +@keyword3_id:= 3 +3 +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword1_id,@topic2_id); +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword2_id,@topic1_id); +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword3_id,@topic3_id); +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword3_id,@topic4_id); help 'function_of_my_dream'; -Name Category -impossible_category_1 Y -impossible_category_2 Y +name is_it_category help '%possible_f%'; -Name Category +name is_it_category impossible_function_1 N impossible_function_2 N impossible_function_3 N +impossible_function_4 N +impossible_function_7 N help 'impossible_func%'; -Name Category +name is_it_category impossible_function_1 N impossible_function_2 N impossible_function_3 N +impossible_function_4 N +impossible_function_7 N help 'impossible_category%'; -Name Category +name is_it_category impossible_category_1 Y impossible_category_2 Y +impossible_category_3 Y help 'impossible_%'; -Name Category +name is_it_category impossible_function_1 N impossible_function_2 N impossible_function_3 N +impossible_function_4 N +impossible_function_7 N impossible_category_1 Y impossible_category_2 Y +impossible_category_3 Y +help '%function_1'; +name description example +impossible_function_1 description of + impossible_function1 + example of + impossible_function1 help '%function_2'; -Name Category Description Example -impossible_function_2 N description of - impossible_function2 example of +name description example +impossible_function_2 description of + impossible_function2 + example of impossible_function2 +help '%function_3'; +name description example +impossible_function_3 description of + impossible_function3 + example of + impossible_function3 +help '%function_4'; +name description example +impossible_function_4 description of + impossible_function4 + example of + impossible_function4 +help '%function_5'; +name description example +impossible_function_1 description of + impossible_function1 + example of + impossible_function1 +help '%function_6'; +name is_it_category +impossible_function_3 N +impossible_function_4 N +help '%function_7'; +name description example +impossible_function_7 description of + impossible_function5 + example of + impossible_function7 help '%category_2'; -Name Category Description Example -impossible_category_2 Y impossible_function_2 -impossible_function_3 - +source_category_name name is_it_category +impossible_category_2 impossible_function_3 N +impossible_category_2 impossible_function_4 N +impossible_category_2 impossible_category_3 Y help 'impossible_function_1'; -Name Category Description Example -impossible_function_1 N description of - impossible_function1 example of +name description example +impossible_function_1 description of + impossible_function1 + example of impossible_function1 help 'impossible_category_1'; -Name Category Description Example -impossible_category_1 Y impossible_function_1 -impossible_function_2 - +source_category_name name is_it_category +impossible_category_1 impossible_function_1 N +impossible_category_1 impossible_function_2 N +alter table mysql.help_relation type=innodb; +alter table mysql.help_keyword type=innodb; alter table mysql.help_topic type=innodb; alter table mysql.help_category type=innodb; -alter table mysql.help_relation type=innodb; help 'function_of_my_dream'; -Name Category -impossible_category_1 Y -impossible_category_2 Y -help '%ble_f%'; -Name Category +name is_it_category +help '%possible_f%'; +name is_it_category impossible_function_1 N impossible_function_2 N impossible_function_3 N +impossible_function_4 N +impossible_function_7 N help 'impossible_func%'; -Name Category +name is_it_category impossible_function_1 N impossible_function_2 N impossible_function_3 N +impossible_function_4 N +impossible_function_7 N help 'impossible_category%'; -Name Category +name is_it_category impossible_category_1 Y impossible_category_2 Y +impossible_category_3 Y help 'impossible_%'; -Name Category +name is_it_category impossible_function_1 N impossible_function_2 N impossible_function_3 N +impossible_function_4 N +impossible_function_7 N impossible_category_1 Y impossible_category_2 Y +impossible_category_3 Y +help '%function_1'; +name description example +impossible_function_1 description of + impossible_function1 + example of + impossible_function1 help '%function_2'; -Name Category Description Example -impossible_function_2 N description of - impossible_function2 example of +name description example +impossible_function_2 description of + impossible_function2 + example of impossible_function2 +help '%function_3'; +name description example +impossible_function_3 description of + impossible_function3 + example of + impossible_function3 +help '%function_4'; +name description example +impossible_function_4 description of + impossible_function4 + example of + impossible_function4 +help '%function_5'; +name description example +impossible_function_1 description of + impossible_function1 + example of + impossible_function1 +help '%function_6'; +name is_it_category +impossible_function_3 N +impossible_function_4 N +help '%function_7'; +name description example +impossible_function_7 description of + impossible_function5 + example of + impossible_function7 help '%category_2'; -Name Category Description Example -impossible_category_2 Y impossible_function_2 -impossible_function_3 - +source_category_name name is_it_category +impossible_category_2 impossible_function_3 N +impossible_category_2 impossible_function_4 N +impossible_category_2 impossible_category_3 Y help 'impossible_function_1'; -Name Category Description Example -impossible_function_1 N description of - impossible_function1 example of +name description example +impossible_function_1 description of + impossible_function1 + example of impossible_function1 help 'impossible_category_1'; -Name Category Description Example -impossible_category_1 Y impossible_function_1 -impossible_function_2 - +source_category_name name is_it_category +impossible_category_1 impossible_function_1 N +impossible_category_1 impossible_function_2 N +alter table mysql.help_relation type=myisam; +alter table mysql.help_keyword type=myisam; alter table mysql.help_topic type=myisam; alter table mysql.help_category type=myisam; -alter table mysql.help_relation type=myisam; +delete from mysql.help_topic where help_topic_id=@topic1_id; +delete from mysql.help_topic where help_topic_id=@topic2_id; +delete from mysql.help_topic where help_topic_id=@topic3_id; +delete from mysql.help_topic where help_topic_id=@topic4_id; +delete from mysql.help_topic where help_topic_id=@topic5_id; +delete from mysql.help_category where help_category_id=@category3_id; +delete from mysql.help_category where help_category_id=@category2_id; +delete from mysql.help_category where help_category_id=@category1_id; +delete from mysql.help_keyword where help_keyword_id=@keyword1_id; +delete from mysql.help_keyword where help_keyword_id=@keyword2_id; +delete from mysql.help_keyword where help_keyword_id=@keyword3_id; +delete from mysql.help_relation where help_keyword_id=@keyword1_id and help_topic_id=@topic2_id; +delete from mysql.help_relation where help_keyword_id=@keyword2_id and help_topic_id=@topic1_id; +delete from mysql.help_relation where help_keyword_id=@keyword3_id and help_topic_id=@topic3_id; +delete from mysql.help_relation where help_keyword_id=@keyword3_id and help_topic_id=@topic4_id; diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 51669f563de..71dceddab29 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -138,15 +138,6 @@ id parent_id level 1008 102 2 1010 102 2 1015 102 2 -explain select level from t1 where level=1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref level level 1 const # Using where; Using index -explain select level,id from t1 where level=1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref level level 1 const # Using where; Using index -explain select level,id,parent_id from t1 where level=1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref level level 1 const # Using where select level,id from t1 where level=1; level id 1 1002 @@ -208,7 +199,7 @@ create index skr on t1 (a); insert into t1 values (3,""), (4,"testing"); analyze table t1; Table Op Msg_type Msg_text -test.t1 analyze error The storage enginge for the table doesn't support analyze +test.t1 analyze status OK show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 1 skr 1 a A 3 NULL NULL YES BTREE @@ -595,9 +586,6 @@ id parent_id level 1009 102 2 1025 102 2 1016 102 2 -explain select level from t1 where level=1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref level level 1 const 6 Using where; Using index select level,id from t1 where level=1; level id 1 1004 @@ -918,8 +906,8 @@ id select_type table type possible_keys key key_len ref rows Extra drop table t1; create table t1 (t int not null default 1, key (t)) type=innodb; desc t1; -Field Type Collation Null Key Default Extra -t int(11) binary MUL 1 +Field Type Null Key Default Extra +t int(11) MUL 1 drop table t1; CREATE TABLE t1 ( number bigint(20) NOT NULL default '0', @@ -1141,7 +1129,7 @@ a b drop table t1; CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) type=innodb; CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) type=innodb; -INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12); INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); update t1,t2 set t1.a=t1.a+100; select * from t1; @@ -1155,6 +1143,9 @@ a b 107 7 108 8 109 9 +110 10 +111 11 +112 12 update t1,t2 set t1.a=t1.a+100 where t1.a=101; select * from t1; a b @@ -1167,6 +1158,9 @@ a b 107 7 108 8 109 9 +110 10 +111 11 +112 12 update t1,t2 set t1.b=t1.b+10 where t1.b=2; select * from t1; a b @@ -1178,8 +1172,11 @@ a b 107 7 108 8 109 9 +110 10 +111 11 102 12 -update t1,t2 set t1.b=t1.b+2,t2.b=t1.b where t1.b between 3 and 5; +112 12 +update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100; select * from t1; a b 201 1 @@ -1190,19 +1187,107 @@ a b 107 7 108 8 109 9 +110 10 +111 11 102 12 +112 12 select * from t2; a b -1 5 -2 5 -3 5 -4 5 -5 5 -6 5 -7 5 -8 5 -9 5 +1 1 +2 2 +6 6 +7 7 +8 8 +9 9 +3 13 +4 14 +5 15 drop table t1,t2; +CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) TYPE=MyISAM; +CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) TYPE=InnoDB; +SET AUTOCOMMIT=0; +INSERT INTO t1 ( B_ID ) VALUES ( 1 ); +INSERT INTO t2 ( NEXT_T ) VALUES ( 1 ); +ROLLBACK; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +SELECT * FROM t1; +B_ID +drop table t1,t2; +create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) type = innodb; +insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2); +select distinct parent,child from t1 order by parent; +parent child +0 4 +1 2 +1 3 +2 1 +drop table t1; +create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) type=innodb; +create table t2 (a int not null auto_increment primary key, b int); +insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null); +insert into t2 (a) select b from t1; +insert into t1 (b) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +select count(*) from t1; +count(*) +29267 +explain select * from t1 where c between 1 and 10000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range c c 5 NULL 1 Using where +update t1 set c=a; +explain select * from t1 where c between 1 and 10000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL c NULL NULL NULL 29537 Using where +drop table t1,t2; +create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) type=innodb; +insert into t1 (id) values (null),(null),(null),(null),(null); +update t1 set fk=69 where fk is null order by id limit 1; +SELECT * from t1; +id fk +2 NULL +3 NULL +4 NULL +5 NULL +1 69 +drop table t1; +create table t1 (a int not null, b int not null, key (a)); +insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3); +SET @tmp=0; +update t1 set b=(@tmp:=@tmp+1) order by a; +update t1 set b=99 where a=1 order by b asc limit 1; +update t1 set b=100 where a=1 order by b desc limit 2; +update t1 set a=a+10+b where a=1 order by b; +select * from t1 order by a,b; +a b +2 4 +2 5 +2 6 +3 7 +3 8 +3 9 +3 10 +3 11 +3 12 +13 2 +111 100 +111 100 +drop table t1; CREATE TABLE t1 (col1 int(1))TYPE=InnoDB; CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP(+0),INDEX stamp_idx (stamp))TYPE=InnoDB; diff --git a/mysql-test/r/innodb_handler.result b/mysql-test/r/innodb_handler.result index 4ce104506f1..38c39e2936f 100644 --- a/mysql-test/r/innodb_handler.result +++ b/mysql-test/r/innodb_handler.result @@ -139,4 +139,13 @@ a b alter table t1 type=innodb; handler t2 read first; Unknown table 't2' in HANDLER -drop table if exists t1; +drop table t1; +CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY (no1,no2)) TYPE=InnoDB; +INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2); +HANDLER t1 OPEN; +HANDLER t1 READ `primary` = (1, 1000); +no1 no2 +HANDLER t1 READ `primary` PREV; +no1 no2 +1 275 +DROP TABLE t1; diff --git a/mysql-test/r/isam.result b/mysql-test/r/isam.result index 3f557e072ee..5975ac8a8a0 100644 --- a/mysql-test/r/isam.result +++ b/mysql-test/r/isam.result @@ -1,5 +1,13 @@ drop table if exists t1,t2; create table t1 (a tinyint not null auto_increment, b blob not null, primary key (a)) type=isam; +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 delete from t1 where (a & 1); select sum(length(b)) from t1; sum(length(b)) @@ -65,14 +73,14 @@ test.t2 check error Table 't2' was not locked with LOCK TABLES test.t1 check status OK show columns from t1; Field Type Collation Null Key Default Extra -a int(11) binary PRI 0 -b int(11) binary MUL 0 -c int(11) binary 0 +a int(11) NULL PRI 0 +b int(11) NULL MUL 0 +c int(11) NULL 0 show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment -a int(11) binary PRI 0 select,insert,update,references -b int(11) binary MUL 0 select,insert,update,references -c int(11) binary 0 select,insert,update,references +a int(11) NULL PRI 0 select,insert,update,references +b int(11) NULL MUL 0 select,insert,update,references +c int(11) NULL 0 select,insert,update,references show index from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 0 PRIMARY 1 a A 4 NULL NULL BTREE diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index 09b819888eb..4bc045aa2f7 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -274,3 +274,101 @@ SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (site rate_code base_rate cust 20 drop table t1,t2; +CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, Value1 VARCHAR(255)); +CREATE TABLE t2 (ID INTEGER NOT NULL PRIMARY KEY, Value2 VARCHAR(255)); +INSERT INTO t1 VALUES (1, 'A'); +INSERT INTO t2 VALUES (1, 'B'); +SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND (Value1 = 'A' AND Value2 <> 'B'); +ID Value1 ID Value2 +SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND Value1 = 'A' AND Value2 <> 'B'; +ID Value1 ID Value2 +SELECT * FROM t1 NATURAL JOIN t2 WHERE (Value1 = 'A' AND Value2 <> 'B') AND 1; +ID Value1 ID Value2 +drop table t1,t2; +create table t1 (i int); +create table t2 (i int); +create table t3 (i int); +insert into t1 values(1),(2); +insert into t2 values(2),(3); +insert into t3 values (2),(4); +select * from t1 natural left join t2; +i i +1 NULL +2 2 +select * from t1 left join t2 on (t1.i=t2.i); +i i +1 NULL +2 2 +select * from t1 natural left join t2 natural left join t3; +i i i +1 NULL NULL +2 2 2 +select * from t1 left join t2 on (t1.i=t2.i) left join t3 on (t2.i=t3.i); +i i i +1 NULL NULL +2 2 2 +select * from t3 natural right join t2; +i i +2 2 +NULL 3 +select * from t3 right join t2 on (t3.i=t2.i); +i i +2 2 +NULL 3 +select * from t3 natural right join t2 natural right join t1; +i i i +NULL NULL 1 +2 2 2 +select * from t3 right join t2 on (t3.i=t2.i) right join t1 on (t2.i=t1.i); +i i i +NULL NULL 1 +2 2 2 +select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i; +i i i +1 2 2 +1 3 NULL +2 2 2 +2 3 NULL +select * from t1,t2 left join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i; +i i i +1 2 2 +1 3 NULL +2 2 2 +2 3 NULL +select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i; +i i i +1 2 2 +1 3 NULL +2 2 2 +2 3 NULL +select t1.i,t2.i,t3.i from t2 left join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i; +i i i +1 2 2 +1 3 NULL +2 2 2 +2 3 NULL +select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i; +i i i +1 NULL 4 +1 2 2 +2 NULL 4 +2 2 2 +select * from t1,t2 right join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i; +i i i +1 NULL 4 +1 2 2 +2 NULL 4 +2 2 2 +select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i; +i i i +1 NULL 4 +1 2 2 +2 NULL 4 +2 2 2 +select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i; +i i i +1 NULL 4 +1 2 2 +2 NULL 4 +2 2 2 +drop table t1,t2,t3; diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 9ac44bec377..123de82fe09 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -350,12 +350,7 @@ select t1.name, t2.name, t2.id,t3.id from t1 right join t2 on (t1.id = t2.owner) name name id id Antonio Paz El Gato 1 1 Antonio Paz Perrito 2 1 -NULL Happy 3 1 -NULL El Gato 1 2 -NULL Perrito 2 2 -NULL Happy 3 2 -NULL El Gato 1 3 -NULL Perrito 2 3 +NULL NULL NULL 2 Thimble Smith Happy 3 3 select t1.name, t2.name, t2.id, t2.owner, t3.id from t1 left join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner; name name id owner id @@ -372,10 +367,10 @@ Thimble Smith Happy 3 3 3 drop table t1,t2; create table t1 (id int not null, str char(10), index(str)); insert into t1 values (1, null), (2, null), (3, "foo"), (4, "bar"); -select * from t1 where str is not null; +select * from t1 where str is not null order by id; id str -4 bar 3 foo +4 bar select * from t1 where str is null; id str 1 NULL @@ -651,3 +646,14 @@ fooID barID fooID 20 2 NULL 30 3 30 drop table t1,t2; +create table t1 (i int); +create table t2 (i int); +create table t3 (i int); +insert into t1 values(1),(2); +insert into t2 values(2),(3); +insert into t3 values(2),(4); +select * from t1 natural left join t2 natural left join t3; +i i i +1 NULL NULL +2 2 2 +drop table t1,t2,t3; diff --git a/mysql-test/r/key.result b/mysql-test/r/key.result index 9e1f743d132..5060fbff5e8 100644 --- a/mysql-test/r/key.result +++ b/mysql-test/r/key.result @@ -32,6 +32,11 @@ KEY price (price,area,type,transityes,shopsyes,schoolsyes,petsyes) INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','N','N','N','N'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','N','N','N','N'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','','','',''); +Warnings: +Warning 1263 Data truncated for column 'transityes' at row 1 +Warning 1263 Data truncated for column 'shopsyes' at row 1 +Warning 1263 Data truncated for column 'schoolsyes' at row 1 +Warning 1263 Data truncated for column 'petsyes' at row 1 INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); @@ -42,7 +47,6 @@ price area type transityes shopsyes schoolsyes petsyes drop table t1; CREATE TABLE t1 (program enum('signup','unique','sliding') not null, type enum('basic','sliding','signup'), sites set('mt'), PRIMARY KEY (program)); ALTER TABLE t1 modify program enum('signup','unique','sliding'); -All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead drop table t1; CREATE TABLE t1 ( name varchar(50) DEFAULT '' NOT NULL, @@ -90,9 +94,13 @@ INSERT t1 VALUES(NULL,'/'); INSERT t1 VALUES(NULL,'[T,U]_axpby'); SELECT * FROM t1 WHERE name='[T,U]_axpy'; name_id name +Warnings: +Warning 1263 Data truncated for column 'name' at row 1 SELECT * FROM t1 WHERE name='[T,U]_axpby'; name_id name 2 [T,U]_axpby +Warnings: +Warning 1263 Data truncated for column 'name' at row 1 create table t2 ( name_id int not null auto_increment, @@ -150,6 +158,9 @@ drop table t1; CREATE TABLE t1 (c CHAR(10) NOT NULL,i INT NOT NULL AUTO_INCREMENT, UNIQUE (c,i)); INSERT INTO t1 (c) VALUES (NULL),(NULL); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'c' at row 1 +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'c' at row 2 SELECT * FROM t1; c i 1 diff --git a/mysql-test/r/loaddata.result b/mysql-test/r/loaddata.result new file mode 100644 index 00000000000..7b4802136f3 --- /dev/null +++ b/mysql-test/r/loaddata.result @@ -0,0 +1,18 @@ +drop table if exists t1; +create table t1 (a date, b date, c date not null, d date); +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ','; +Warnings: +Warning 1263 Data truncated for column 'a' at row 1 +Warning 1263 Data truncated for column 'c' at row 1 +Warning 1263 Data truncated for column 'd' at row 1 +Warning 1263 Data truncated for column 'a' at row 2 +Warning 1263 Data truncated for column 'b' at row 2 +Warning 1263 Data truncated for column 'd' at row 2 +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; +SELECT * from t1; +a b c d +0000-00-00 NULL 0000-00-00 0000-00-00 +0000-00-00 0000-00-00 0000-00-00 0000-00-00 +2003-03-03 2003-03-03 2003-03-03 NULL +2003-03-03 2003-03-03 2003-03-03 NULL +drop table t1; diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index da1c429df63..2aa7db1599e 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -300,7 +300,7 @@ a b 107 7 108 8 109 9 -update t1,t2 set t1.b=t1.b+2,t2.b=t1.b where t1.b between 3 and 5; +update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t2.a=t1.a-100; select * from t1; a b 201 1 @@ -314,13 +314,21 @@ a b 109 9 select * from t2; a b -1 3 -2 3 -3 3 -4 3 -5 3 -6 3 -7 3 -8 3 -9 3 +1 1 +2 2 +3 13 +4 14 +5 15 +6 6 +7 7 +8 8 +9 9 drop table t1,t2; +CREATE TABLE t3 ( KEY1 varchar(50) NOT NULL default '', PARAM_CORR_DISTANCE_RUSH double default NULL, PARAM_CORR_DISTANCE_GEM double default NULL, PARAM_AVG_TARE double default NULL, PARAM_AVG_NB_DAYS double default NULL, PARAM_DEFAULT_PROP_GEM_SRVC varchar(50) default NULL, PARAM_DEFAULT_PROP_GEM_NO_ETIK varchar(50) default NULL, PARAM_SCENARIO_COSTS varchar(50) default NULL, PARAM_DEFAULT_WAGON_COST double default NULL, tmp int(11) default NULL, PRIMARY KEY (KEY1)) TYPE=MyISAM; +INSERT INTO t3 VALUES ('A',1,1,22,3.2,'R','R','BASE2',0.24,NULL); +create table t1 (A varchar(1)); +insert into t1 values ("A") ,("B"),("C"),("D"); +create table t2(Z varchar(15)); +insert into t2(Z) select concat(a.a,b.a,c.a,d.a) from t1 as a, t1 as b, t1 as c, t1 as d; +update t2,t3 set Z =param_scenario_costs; +drop table t1,t2,t3; diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 13e0933adf4..5cfd1afd867 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -14,6 +14,34 @@ Table Op Msg_type Msg_text test.t1 check status OK drop table t1; create table t1 (a tinyint not null auto_increment, b blob not null, primary key (a)); +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 check table t1; Table Op Msg_type Msg_text test.t1 check status OK diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index 08612fa191f..d6dfb4621ab 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -76,27 +76,43 @@ drop table t1; CREATE TABLE t1 (a varchar(16) NOT NULL, b smallint(6) NOT NULL, c datetime NOT NULL, d smallint(6) NOT NULL); INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55"; UPDATE t1 SET d=1/NULL; +Warnings: +Warning 1263 Data truncated for column 'd' at row 1 UPDATE t1 SET d=NULL; +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'd' at row 1 INSERT INTO t1 (a) values (null); Column 'a' cannot be null INSERT INTO t1 (a) values (1/null); Column 'a' cannot be null INSERT INTO t1 (a) values (null),(null); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'a' at row 1 +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'a' at row 2 INSERT INTO t1 (b) values (null); Column 'b' cannot be null INSERT INTO t1 (b) values (1/null); Column 'b' cannot be null INSERT INTO t1 (b) values (null),(null); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'b' at row 1 +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'b' at row 2 INSERT INTO t1 (c) values (null); Column 'c' cannot be null INSERT INTO t1 (c) values (1/null); Column 'c' cannot be null INSERT INTO t1 (c) values (null),(null); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'c' at row 1 +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'c' at row 2 INSERT INTO t1 (d) values (null); Column 'd' cannot be null INSERT INTO t1 (d) values (1/null); Column 'd' cannot be null INSERT INTO t1 (d) values (null),(null); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'd' at row 1 +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'd' at row 2 select * from t1; a b c d 0 0000-00-00 00:00:00 0 diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result index ce3af6c37cd..289290ba08c 100644 --- a/mysql-test/r/null_key.result +++ b/mysql-test/r/null_key.result @@ -84,7 +84,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a,b a 5 NULL 5 Using where explain select * from t1 where (a is null or a = 7) and b=7 and c=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 5 NULL 4 Using where +1 SIMPLE t1 ALL a,b NULL NULL NULL 12 Using where explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref a,b a 5 const 3 Using where @@ -234,6 +234,8 @@ index (id), index (id2) ); insert into t1 values(null,null),(1,1); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'id2' at row 1 select * from t1; id id2 NULL 0 diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index bd5b283f26a..3524b38e659 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -332,6 +332,11 @@ a b c 1 NULL b 1 NULL NULL alter table t1 modify b int not null, modify c varchar(10) not null; +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warning 1263 Data truncated for column 'c' at row 1 +Warning 1263 Data truncated for column 'b' at row 2 +Warning 1263 Data truncated for column 'c' at row 3 explain select * from t1 order by a, b, c; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL a 18 NULL 11 Using index @@ -516,6 +521,31 @@ SELECT titre,t1.numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,des titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug drop table t1,t2; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1, 2); +INSERT INTO t1 VALUES (3, 4); +INSERT INTO t1 VALUES (5, NULL); +SELECT * FROM t1 ORDER BY b; +a b +5 NULL +1 2 +3 4 +SELECT * FROM t1 ORDER BY b DESC; +a b +3 4 +1 2 +5 NULL +SELECT * FROM t1 ORDER BY (a + b); +a b +5 NULL +1 2 +3 4 +SELECT * FROM t1 ORDER BY (a + b) DESC; +a b +3 4 +1 2 +5 NULL +DROP TABLE t1; CREATE TABLE t1 ( FieldKey varchar(36) NOT NULL default '', LongVal bigint(20) default NULL, @@ -524,10 +554,10 @@ KEY FieldKey (FieldKey), KEY LongField (FieldKey,LongVal), KEY StringField (FieldKey,StringVal(32)) ); -INSERT INTO t1 VALUES ('0',3,'0'),('0',2,'1'),('0',1,'2'),('1',2,'1'),('1',1,'3'), ('1',0,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('3',2,'1'),('3',1,'2'),('3','3','3'); +INSERT INTO t1 VALUES ('0',3,'0'),('0',2,'1'),('0',1,'2'),('1',2,'1'),('1',1,'3'), ('1',0,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('3',2,'1'),('3',1,'2'),('3','3','3'); EXPLAIN SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref FieldKey,LongField,StringField LongField 36 const 2 Using where +1 SIMPLE t1 ref FieldKey,LongField,StringField LongField 36 const 3 Using where SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal; FieldKey LongVal StringVal 1 0 2 diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index 46fa12dd9bc..1d46d1dcf25 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -238,13 +238,18 @@ a show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 0 -select sql_cache * from t1; +select sql_cache * from t1 union select * from t1; a 1 2 3 set query_cache_type=2; -select sql_cache * from t1; +select sql_cache * from t1 union select * from t1; +a +1 +2 +3 +select * from t1 union select sql_cache * from t1; a 1 2 @@ -254,7 +259,7 @@ Variable_name Value Qcache_hits 4 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 1 +Qcache_queries_in_cache 2 set query_cache_type=on; reset query cache; show status like "Qcache_queries_in_cache"; @@ -377,14 +382,14 @@ a set CHARACTER SET cp1251_koi8; select * from t1; a -? +á set CHARACTER SET DEFAULT; show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 2 +Qcache_queries_in_cache 1 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 4 +Qcache_hits 5 drop table t1; create database if not exists mysqltest; create table mysqltest.t1 (i int not null); @@ -410,7 +415,7 @@ Variable_name Value Qcache_queries_in_cache 2 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 6 +Qcache_hits 7 drop database mysqltest; drop table t1; create table t1 (i int not null); @@ -424,7 +429,7 @@ FOUND_ROWS() 4 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 6 +Qcache_hits 7 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 1 @@ -436,7 +441,7 @@ FOUND_ROWS() 1 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 6 +Qcache_hits 7 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 2 @@ -449,7 +454,7 @@ FOUND_ROWS() 4 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 7 +Qcache_hits 8 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 2 @@ -461,7 +466,7 @@ FOUND_ROWS() 1 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 8 +Qcache_hits 9 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 2 @@ -530,7 +535,7 @@ a 3 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 11 +Qcache_hits 12 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 2 @@ -547,7 +552,7 @@ a 3 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 12 +Qcache_hits 13 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 2 @@ -636,3 +641,21 @@ show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 0 drop table t1; +create table t1 (a int); +insert into t1 values (1),(2); +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +select * from t1; +a +1 +2 +SET OPTION SQL_SELECT_LIMIT=1; +select * from t1; +a +1 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 2 +SET OPTION SQL_SELECT_LIMIT=DEFAULT; +drop table t1; diff --git a/mysql-test/r/raid.result b/mysql-test/r/raid.result index 41af50851e9..fd47a9451f6 100644 --- a/mysql-test/r/raid.result +++ b/mysql-test/r/raid.result @@ -1,3 +1,6 @@ +create database test_raid; +create table test_raid.r1 (i int) raid_type=1; +drop database test_raid; DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 ( id int unsigned not null auto_increment primary key, diff --git a/mysql-test/r/repair.result b/mysql-test/r/repair.result index 8b50f9a92e8..eb46622dcc1 100644 --- a/mysql-test/r/repair.result +++ b/mysql-test/r/repair.result @@ -4,4 +4,12 @@ repair table t1 use_frm; Table Op Msg_type Msg_text test.t1 repair warning Number of rows changed from 0 to 1 test.t1 repair status OK -drop table if exists t1; +alter table t1 TYPE=HEAP; +repair table t1 use_frm; +Table Op Msg_type Msg_text +test.t1 repair error The storage enginge for the table doesn't support repair +drop table t1; +repair table t1 use_frm; +Table Op Msg_type Msg_text +test.t1 repair error Table 'test.t1' doesn't exist +create table t1 type=myisam SELECT 1,"table 1"; diff --git a/mysql-test/r/repair_part2.result b/mysql-test/r/repair_part2.result new file mode 100644 index 00000000000..77aa98c3da9 --- /dev/null +++ b/mysql-test/r/repair_part2.result @@ -0,0 +1,8 @@ +repair table t1; +Table Op Msg_type Msg_text +test.t1 repair error Can't open file: 't1.MYI'. (errno: 130) +repair table t1 use_frm; +Table Op Msg_type Msg_text +test.t1 repair warning Number of rows changed from 0 to 1 +test.t1 repair status OK +drop table t1; diff --git a/mysql-test/r/rpl_flush_tables.result b/mysql-test/r/rpl_flush_tables.result index 40a35f4e0ca..6353a6101d6 100644 --- a/mysql-test/r/rpl_flush_tables.result +++ b/mysql-test/r/rpl_flush_tables.result @@ -14,7 +14,7 @@ rename table t1 to t5, t2 to t1; flush no_write_to_binlog tables; show binlog events; Log_name Pos Event_type Server_id Orig_log_pos Info -master-bin.000001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3 +master-bin.000001 4 Start 1 4 Server ver: SERVER_VERSION, Binlog ver: 3 master-bin.000001 79 Query 1 79 use `test`; create table t1 (a int) master-bin.000001 137 Query 1 137 use `test`; insert into t1 values (10) master-bin.000001 198 Query 1 198 use `test`; create table t2 (a int) @@ -27,7 +27,7 @@ a flush tables; show binlog events; Log_name Pos Event_type Server_id Orig_log_pos Info -master-bin.000001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3 +master-bin.000001 4 Start 1 4 Server ver: SERVER_VERSION, Binlog ver: 3 master-bin.000001 79 Query 1 79 use `test`; create table t1 (a int) master-bin.000001 137 Query 1 137 use `test`; insert into t1 values (10) master-bin.000001 198 Query 1 198 use `test`; create table t2 (a int) diff --git a/mysql-test/r/rpl_relayrotate.result b/mysql-test/r/rpl_relayrotate.result index 45f425a3532..0ad61a7687e 100644 --- a/mysql-test/r/rpl_relayrotate.result +++ b/mysql-test/r/rpl_relayrotate.result @@ -16,3 +16,4 @@ master_pos_wait('master-bin.001',3000,120)=-1 select * from t1 where a=8000; a 8000 +drop table t1; diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 0d1743d72b7..8be189752ea 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3218,16 +3218,16 @@ show tables from test like "t?"; Tables_in_test (t?) show full columns from t2; Field Type Collation Null Key Default Extra Privileges Comment -auto int(11) binary PRI NULL auto_increment select,insert,update,references -fld1 int(6) unsigned zerofill binary UNI 000000 select,insert,update,references -companynr tinyint(2) unsigned zerofill binary 00 select,insert,update,references +auto int(11) NULL PRI NULL auto_increment select,insert,update,references +fld1 int(6) unsigned zerofill NULL UNI 000000 select,insert,update,references +companynr tinyint(2) unsigned zerofill NULL 00 select,insert,update,references fld3 char(30) latin1_swedish_ci MUL select,insert,update,references fld4 char(35) latin1_swedish_ci select,insert,update,references fld5 char(35) latin1_swedish_ci select,insert,update,references fld6 char(4) latin1_swedish_ci select,insert,update,references show full columns from t2 from test like 'f%'; Field Type Collation Null Key Default Extra Privileges Comment -fld1 int(6) unsigned zerofill binary UNI 000000 select,insert,update,references +fld1 int(6) unsigned zerofill NULL UNI 000000 select,insert,update,references fld3 char(30) latin1_swedish_ci MUL select,insert,update,references fld4 char(35) latin1_swedish_ci select,insert,update,references fld5 char(35) latin1_swedish_ci select,insert,update,references @@ -3411,13 +3411,7 @@ a a a select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a)); a a a 1 1 1 -2 1 NULL -3 1 NULL -1 2 NULL 2 2 2 -3 2 NULL -1 3 NULL -2 3 NULL 3 3 3 select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1; a a a @@ -3473,13 +3467,7 @@ a a a select * from t1 natural join (t1 as t2 left join t1 as t3 using (a)); a a a 1 1 1 -2 1 NULL -3 1 NULL -1 2 NULL 2 2 2 -3 2 NULL -1 3 NULL -2 3 NULL 3 3 3 select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1; a a a diff --git a/mysql-test/r/select_safe.result b/mysql-test/r/select_safe.result index e225a0e3995..3303f19d9c7 100644 --- a/mysql-test/r/select_safe.result +++ b/mysql-test/r/select_safe.result @@ -1,6 +1,6 @@ drop table if exists t1; SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=4, SQL_MAX_JOIN_SIZE=9; -create table t1 (a int primary key, b char(20)); +create table t1 (a int auto_increment primary key, b char(20)); insert into t1 values(1,"test"); SELECT SQL_BUFFER_RESULT * from t1; a b @@ -30,10 +30,34 @@ You are using safe update mode and you tried to update a table without a WHERE t delete from t1 where a+0=1; You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column select 1 from t1,t1 as t2,t1 as t3,t1 as t4,t1 as t5; -The SELECT would examine too many records and probably take a very long time. Check your WHERE and use SET OPTION SQL_BIG_SELECTS=1 if the SELECT is ok +The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok update t1 set b="a" limit 1; update t1 set b="a" where b="b" limit 2; delete from t1 where b="test" limit 1; delete from t1 where a+0=1 limit 2; +SET MAX_JOIN_SIZE=2; +SELECT @@MAX_JOIN_SIZE, @@SQL_BIG_SELECTS; +@@max_join_size @@sql_big_selects +2 0 +insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"); +SELECT * from t1; +The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok +SET SQL_BIG_SELECTS=1; +SELECT * from t1; +a b +3 a +2 test2 +4 a +5 a +SET MAX_JOIN_SIZE=2; +SELECT * from t1; +The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok +SET MAX_JOIN_SIZE=DEFAULT; +SELECT * from t1; +a b +3 a +2 test2 +4 a +5 a drop table t1; SET SQL_SAFE_UPDATES=0,SQL_SELECT_LIMIT=DEFAULT, SQL_MAX_JOIN_SIZE=DEFAULT; diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index b1072fd41ce..b867eae5e8d 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -101,7 +101,7 @@ show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment test_set set('val1','val2','val3') latin1_swedish_ci select,insert,update,references name char(20) latin1_swedish_ci YES O'Brien select,insert,update,references O'Brien as default -c int(11) binary 0 select,insert,update,references int column +c int(11) NULL 0 select,insert,update,references int column drop table t1; create table t1 (a int not null, unique aa (a)); show create table t1; @@ -155,21 +155,21 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a decimal(9,2), b decimal (9,0), e double(9,2), f double(5,0), h float(3,2), i float(3,0)); show columns from t1; -Field Type Collation Null Key Default Extra -a decimal(9,2) binary YES NULL -b decimal(9,0) binary YES NULL -e double(9,2) binary YES NULL -f double(5,0) binary YES NULL -h float(3,2) binary YES NULL -i float(3,0) binary YES NULL +Field Type Null Key Default Extra +a decimal(9,2) YES NULL +b decimal(9,0) YES NULL +e double(9,2) YES NULL +f double(5,0) YES NULL +h float(3,2) YES NULL +i float(3,0) YES NULL show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment -a decimal(9,2) binary YES NULL select,insert,update,references -b decimal(9,0) binary YES NULL select,insert,update,references -e double(9,2) binary YES NULL select,insert,update,references -f double(5,0) binary YES NULL select,insert,update,references -h float(3,2) binary YES NULL select,insert,update,references -i float(3,0) binary YES NULL select,insert,update,references +a decimal(9,2) NULL YES NULL select,insert,update,references +b decimal(9,0) NULL YES NULL select,insert,update,references +e double(9,2) NULL YES NULL select,insert,update,references +f double(5,0) NULL YES NULL select,insert,update,references +h float(3,2) NULL YES NULL select,insert,update,references +i float(3,0) NULL YES NULL select,insert,update,references drop table t1; create table t1 ( type_bool bool not null, @@ -229,16 +229,16 @@ type_bool type_tiny type_short type_mediumint type_bigint type_decimal type_nume drop table t1; create table t1 (c decimal, d double, f float, r real); show columns from t1; -Field Type Collation Null Key Default Extra -c decimal(10,0) binary YES NULL -d double binary YES NULL -f float binary YES NULL -r double binary YES NULL +Field Type Null Key Default Extra +c decimal(10,0) YES NULL +d double YES NULL +f float YES NULL +r double YES NULL drop table t1; create table t1 (c decimal(3,3), d double(3,3), f float(3,3)); show columns from t1; -Field Type Collation Null Key Default Extra -c decimal(4,3) binary YES NULL -d double(4,3) binary YES NULL -f float(4,3) binary YES NULL +Field Type Null Key Default Extra +c decimal(4,3) YES NULL +d double(4,3) YES NULL +f float(4,3) YES NULL drop table t1; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 5c57ea87f21..511517ebdfd 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -606,14 +606,14 @@ x 3 INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2; You can't specify target table 't1' for update in FROM clause -INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2)); +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); select * from t1; x 1 2 3 3 -0 +2 drop table t1, t2, t3; CREATE TABLE t1 (x int not null, y int, primary key (x)); create table t2 (a int); @@ -688,6 +688,8 @@ id 2 INSERT INTO t2 VALUES ((SELECT * FROM t2)); You can't specify target table 't2' for update in FROM clause +INSERT INTO t2 VALUES ((SELECT id FROM t2)); +You can't specify target table 't2' for update in FROM clause SELECT * FROM t2; id 1 @@ -965,7 +967,13 @@ PRIMARY KEY (`numeropost`), UNIQUE KEY `maxnumrep` (`maxnumrep`) ) TYPE=MyISAM CHARSET=latin1; INSERT INTO t1 VALUES ('joce','1','','joce'),('test','2','','test'); +Warnings: +Warning 1263 Data truncated for column 'date' at row 1 +Warning 1263 Data truncated for column 'date' at row 2 INSERT INTO t2 VALUES ('joce','1','','joce'),('test','2','','test'); +Warnings: +Warning 1263 Data truncated for column 'date' at row 1 +Warning 1263 Data truncated for column 'date' at row 2 INSERT INTO t3 VALUES (1,1); SELECT DISTINCT topic FROM t2 WHERE NOT EXISTS(SELECT * FROM t3 WHERE numeropost=topic); @@ -1126,3 +1134,17 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref salary salary 5 const 1 Using where 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away drop table t1; +CREATE TABLE t1 ( +ID int(10) unsigned NOT NULL auto_increment, +SUB_ID int(3) unsigned NOT NULL default '0', +REF_ID int(10) unsigned default NULL, +REF_SUB int(3) unsigned default '0', +PRIMARY KEY (ID,SUB_ID), +UNIQUE KEY t1_PK (ID,SUB_ID), +KEY t1_FK (REF_ID,REF_SUB), +KEY t1_REFID (REF_ID) +) TYPE=MyISAM CHARSET=cp1251; +INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); +SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); +REF_ID +DROP TABLE t1; diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index 1eb595eb2a9..3efc69d2f64 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -36,7 +36,7 @@ show create table t9; Table Create Table t9 CREATE TABLE `t9` ( `a` int(11) NOT NULL auto_increment, - `b` char(16) character set latin1 NOT NULL default '', + `b` char(16) NOT NULL default '', `c` int(11) NOT NULL default '0', PRIMARY KEY (`a`) ) TYPE=MyISAM CHARSET=latin1 @@ -45,6 +45,8 @@ alter table t8 rename t7; rename table t7 to t9; drop table t1; Got one of the listed errors +Warnings: +Note 1008 Can't drop database 'test_mysqltest'. Database doesn't exist Got one of the listed errors Got one of the listed errors Got one of the listed errors @@ -57,7 +59,7 @@ show create table test_mysqltest.t9; Table Create Table t9 CREATE TABLE `t9` ( `a` int(11) NOT NULL auto_increment, - `b` char(16) character set latin1 NOT NULL default '', + `b` char(16) NOT NULL default '', `c` int(11) NOT NULL default '0', `d` int(11) NOT NULL default '0', PRIMARY KEY (`a`) diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index 6d1b1189185..ce1cd392819 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -1,22 +1,22 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7; CREATE TABLE t1 (a blob, b text, c blob(250), d text(70000), e text(70000000)); show columns from t1; -Field Type Collation Null Key Default Extra -a blob binary YES NULL -b text latin1_swedish_ci YES NULL -c blob binary YES NULL -d mediumtext latin1_swedish_ci YES NULL -e longtext latin1_swedish_ci YES NULL +Field Type Null Key Default Extra +a blob YES NULL +b text YES NULL +c blob YES NULL +d mediumtext YES NULL +e longtext YES NULL CREATE TABLE t2 (a char(257), b varchar(70000) binary, c varchar(70000000)); Warnings: Warning 1244 Converting column 'a' from CHAR to TEXT Warning 1244 Converting column 'b' from CHAR to BLOB Warning 1244 Converting column 'c' from CHAR to TEXT show columns from t2; -Field Type Collation Null Key Default Extra -a text latin1_swedish_ci YES NULL -b mediumblob binary YES NULL -c longtext latin1_swedish_ci YES NULL +Field Type Null Key Default Extra +a text YES NULL +b mediumblob YES NULL +c longtext YES NULL create table t3 (a long, b long byte); show create TABLE t3; Table Create Table @@ -72,15 +72,15 @@ show full fields from t1; Field Type Collation Null Key Default Extra Privileges Comment t text latin1_swedish_ci YES NULL select,insert,update,references c varchar(10) latin1_swedish_ci YES NULL select,insert,update,references -b blob binary YES NULL select,insert,update,references -d varchar(10) binary binary YES NULL select,insert,update,references +b blob NULL YES NULL select,insert,update,references +d varchar(10) binary YES NULL select,insert,update,references lock tables t1 WRITE; show full fields from t1; Field Type Collation Null Key Default Extra Privileges Comment t text latin1_swedish_ci YES NULL select,insert,update,references c varchar(10) latin1_swedish_ci YES NULL select,insert,update,references -b blob binary YES NULL select,insert,update,references -d varchar(10) binary binary YES NULL select,insert,update,references +b blob NULL YES NULL select,insert,update,references +d varchar(10) binary YES NULL select,insert,update,references unlock tables; select t from t1 where t like "hello"; t diff --git a/mysql-test/r/type_decimal.result b/mysql-test/r/type_decimal.result index 4c326957c03..c0e48fb42d8 100644 --- a/mysql-test/r/type_decimal.result +++ b/mysql-test/r/type_decimal.result @@ -156,8 +156,18 @@ insert into t1 values ("-.1"),("+.1"),(".1"); insert into t1 values ("00000000000001"),("+0000000000001"),("-0000000000001"); insert into t1 values ("+111111111.11"),("111111111.11"),("-11111111.11"); insert into t1 values ("-111111111.11"),("+1111111111.11"),("1111111111.11"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("1e+1000"),("1e-1000"),("-1e+1000"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1263 Data truncated for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("123.4e"),("123.4e+2"),("123.4e-2"),("123e1"),("123e+0"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 3 select * from t1; a 0.00 @@ -189,12 +199,33 @@ a drop table t1; create table t1 (a decimal(10,2) unsigned); insert into t1 values ("0.0"),("-0.0"),("+0.0"),("01.0"),("+01.0"),("-01.0"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 6 insert into t1 values ("-.1"),("+.1"),(".1"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 insert into t1 values ("00000000000001"),("+0000000000001"),("-0000000000001"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("+111111111.11"),("111111111.11"),("-11111111.11"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("-111111111.11"),("+1111111111.11"),("1111111111.11"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("1e+1000"),("1e-1000"),("-1e+1000"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1263 Data truncated for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("123.4e"),("123.4e+2"),("123.4e-2"),("123e1"),("123e+0"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 3 select * from t1; a 0.00 @@ -226,12 +257,33 @@ a drop table t1; create table t1 (a decimal(10,2) zerofill); insert into t1 values ("0.0"),("-0.0"),("+0.0"),("01.0"),("+01.0"),("-01.0"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 6 insert into t1 values ("-.1"),("+.1"),(".1"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 insert into t1 values ("00000000000001"),("+0000000000001"),("-0000000000001"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("+111111111.11"),("111111111.11"),("-11111111.11"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("-111111111.11"),("+1111111111.11"),("1111111111.11"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("1e+1000"),("1e-1000"),("-1e+1000"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1263 Data truncated for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values ("123.4e"),("123.4e+2"),("123.4e-2"),("123e1"),("123e+0"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 3 select * from t1; a 00000000.00 @@ -267,7 +319,14 @@ insert into t1 values (-.1),(+.1),(.1); insert into t1 values (00000000000001),(+0000000000001),(-0000000000001); insert into t1 values (+111111111.11),(111111111.11),(-11111111.11); insert into t1 values (-111111111.11),(+1111111111.11),(1111111111.11); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values (1e+100),(1e-100),(-1e+100); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 3 insert into t1 values (123.4e0),(123.4e+2),(123.4e-2),(123e1),(123e+0); select * from t1; a @@ -300,6 +359,9 @@ a drop table t1; create table t1 (a decimal); insert into t1 values (-99999999999999),(-1),('+1'),('01'),('+00000000000001'),('+12345678901'),(99999999999999); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 7 select * from t1; a -9999999999 @@ -312,6 +374,10 @@ a drop table t1; create table t1 (a decimal unsigned); insert into t1 values (-99999999999999),(-1),('+1'),('01'),('+00000000000001'),('+1234567890'),(99999999999999); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 7 select * from t1; a 0 @@ -324,6 +390,10 @@ a drop table t1; create table t1 (a decimal zerofill); insert into t1 values (-99999999999999),(-1),('+1'),('01'),('+00000000000001'),('+1234567890'),(99999999999999); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 7 select * from t1; a 0000000000 @@ -336,6 +406,10 @@ a drop table t1; create table t1 (a decimal unsigned zerofill); insert into t1 values (-99999999999999),(-1),('+1'),('01'),('+00000000000001'),('+1234567890'),(99999999999999); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'a' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 7 select * from t1; a 0000000000 @@ -348,12 +422,22 @@ a drop table t1; create table t1(a decimal(10,0)); insert into t1 values ("1e4294967295"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 select * from t1; a 99999999999 delete from t1; insert into t1 values("1e4294967297"); +Warnings: +Warning 1262 Data truncated, out of range for column 'a' at row 1 select * from t1; a 99999999999 drop table t1; +CREATE TABLE t1 (a_dec DECIMAL(-1,0)); +Too big column length for column 'a_dec' (max = 255). Use BLOB instead +CREATE TABLE t1 (a_dec DECIMAL(-2,1)); +Too big column length for column 'a_dec' (max = 255). Use BLOB instead +CREATE TABLE t1 (a_dec DECIMAL(-1,1)); +Too big column length for column 'a_dec' (max = 255). Use BLOB instead diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index 3914114d92c..92cf4f70843 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -11,9 +11,12 @@ SELECT 1e1,1.e1,1.0e1,1e+1,1.e+1,1.0e+1,1e-1,1.e-1,1.0e-1; create table t1 (f1 float(24),f2 float(52)); show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment -f1 float binary YES NULL select,insert,update,references -f2 double binary YES NULL select,insert,update,references +f1 float NULL YES NULL select,insert,update,references +f2 double NULL YES NULL select,insert,update,references insert into t1 values(10,10),(1e+5,1e+5),(1234567890,1234567890),(1e+10,1e+10),(1e+15,1e+15),(1e+20,1e+20),(1e+50,1e+50),(1e+150,1e+150); +Warnings: +Warning 1262 Data truncated, out of range for column 'f1' at row 7 +Warning 1262 Data truncated, out of range for column 'f1' at row 8 insert into t1 values(-10,-10),(1e-5,1e-5),(1e-10,1e-10),(1e-15,1e-15),(1e-20,1e-20),(1e-50,1e-50),(1e-150,1e-150); select * from t1; f1 f2 @@ -70,18 +73,18 @@ drop table t1; create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(5,6)); show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment -f float binary YES NULL select,insert,update,references -f2 float binary YES NULL select,insert,update,references -f3 float(6,2) binary YES NULL select,insert,update,references -d double binary YES NULL select,insert,update,references -d2 double binary YES NULL select,insert,update,references -d3 double(10,3) binary YES NULL select,insert,update,references -de decimal(10,0) binary YES NULL select,insert,update,references -de2 decimal(6,0) binary YES NULL select,insert,update,references -de3 decimal(5,2) binary YES NULL select,insert,update,references -n decimal(10,0) binary YES NULL select,insert,update,references -n2 decimal(8,0) binary YES NULL select,insert,update,references -n3 decimal(7,6) binary YES NULL select,insert,update,references +f float NULL YES NULL select,insert,update,references +f2 float NULL YES NULL select,insert,update,references +f3 float(6,2) NULL YES NULL select,insert,update,references +d double NULL YES NULL select,insert,update,references +d2 double NULL YES NULL select,insert,update,references +d3 double(10,3) NULL YES NULL select,insert,update,references +de decimal(10,0) NULL YES NULL select,insert,update,references +de2 decimal(6,0) NULL YES NULL select,insert,update,references +de3 decimal(5,2) NULL YES NULL select,insert,update,references +n decimal(10,0) NULL YES NULL select,insert,update,references +n2 decimal(8,0) NULL YES NULL select,insert,update,references +n3 decimal(7,6) NULL YES NULL select,insert,update,references drop table t1; create table t1 (a decimal(7,3) not null, key (a)); insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1"); diff --git a/mysql-test/r/type_ranges.result b/mysql-test/r/type_ranges.result index 3922826fdfd..c059d5b58a0 100644 --- a/mysql-test/r/type_ranges.result +++ b/mysql-test/r/type_ranges.result @@ -39,28 +39,28 @@ KEY (options,flags) ); show full fields from t1; Field Type Collation Null Key Default Extra Privileges Comment -auto int(5) unsigned binary PRI NULL auto_increment select,insert,update,references +auto int(5) unsigned NULL PRI NULL auto_increment select,insert,update,references string varchar(10) latin1_swedish_ci YES hello select,insert,update,references -tiny tinyint(4) binary MUL 0 select,insert,update,references -short smallint(6) binary MUL 1 select,insert,update,references -medium mediumint(8) binary MUL 0 select,insert,update,references -long_int int(11) binary 0 select,insert,update,references -longlong bigint(13) binary MUL 0 select,insert,update,references -real_float float(13,1) binary MUL 0.0 select,insert,update,references -real_double double(16,4) binary YES NULL select,insert,update,references -utiny tinyint(3) unsigned binary MUL 0 select,insert,update,references -ushort smallint(5) unsigned zerofill binary MUL 00000 select,insert,update,references -umedium mediumint(8) unsigned binary MUL 0 select,insert,update,references -ulong int(11) unsigned binary MUL 0 select,insert,update,references -ulonglong bigint(13) unsigned binary MUL 0 select,insert,update,references -time_stamp timestamp latin1_swedish_ci YES NULL select,insert,update,references -date_field date latin1_swedish_ci YES NULL select,insert,update,references -time_field time latin1_swedish_ci YES NULL select,insert,update,references -date_time datetime latin1_swedish_ci YES NULL select,insert,update,references -blob_col blob binary YES NULL select,insert,update,references -tinyblob_col tinyblob binary YES NULL select,insert,update,references -mediumblob_col mediumblob binary select,insert,update,references -longblob_col longblob binary select,insert,update,references +tiny tinyint(4) NULL MUL 0 select,insert,update,references +short smallint(6) NULL MUL 1 select,insert,update,references +medium mediumint(8) NULL MUL 0 select,insert,update,references +long_int int(11) NULL 0 select,insert,update,references +longlong bigint(13) NULL MUL 0 select,insert,update,references +real_float float(13,1) NULL MUL 0.0 select,insert,update,references +real_double double(16,4) NULL YES NULL select,insert,update,references +utiny tinyint(3) unsigned NULL MUL 0 select,insert,update,references +ushort smallint(5) unsigned zerofill NULL MUL 00000 select,insert,update,references +umedium mediumint(8) unsigned NULL MUL 0 select,insert,update,references +ulong int(11) unsigned NULL MUL 0 select,insert,update,references +ulonglong bigint(13) unsigned NULL MUL 0 select,insert,update,references +time_stamp timestamp NULL YES NULL select,insert,update,references +date_field date NULL YES NULL select,insert,update,references +time_field time NULL YES NULL select,insert,update,references +date_time datetime NULL YES NULL select,insert,update,references +blob_col blob NULL YES NULL select,insert,update,references +tinyblob_col tinyblob NULL YES NULL select,insert,update,references +mediumblob_col mediumblob NULL select,insert,update,references +longblob_col longblob NULL select,insert,update,references options enum('one','two','tree') latin1_swedish_ci MUL one select,insert,update,references flags set('one','two','tree') latin1_swedish_ci select,insert,update,references show keys from t1; @@ -87,8 +87,34 @@ insert into t1 values (10, 1,1,1,1,1,1,1,1,1,1,1,1,1,NULL,0,0,0,1,1,1,1,'one','o insert into t1 values (NULL,2,2,2,2,2,2,2,2,2,2,2,2,2,NULL,NULL,NULL,NULL,NULL,NULL,2,2,'two','two,one'); insert into t1 values (0,1/3,3,3,3,3,3,3,3,3,3,3,3,3,NULL,'19970303','10:10:10','19970303101010','','','','3',3,3); insert into t1 values (0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,NULL,19970807,080706,19970403090807,-1,-1,-1,'-1',-1,-1); +Warnings: +Warning 1262 Data truncated, out of range for column 'utiny' at row 1 +Warning 1262 Data truncated, out of range for column 'ushort' at row 1 +Warning 1262 Data truncated, out of range for column 'umedium' at row 1 +Warning 1262 Data truncated, out of range for column 'ulong' at row 1 +Warning 1263 Data truncated for column 'options' at row 1 +Warning 1263 Data truncated for column 'flags' at row 1 insert into t1 values (0,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,NULL,0,0,0,-4294967295,-4294967295,-4294967295,'-4294967295',0,"one,two,tree"); +Warnings: +Warning 1262 Data truncated, out of range for column 'tiny' at row 1 +Warning 1262 Data truncated, out of range for column 'short' at row 1 +Warning 1262 Data truncated, out of range for column 'medium' at row 1 +Warning 1262 Data truncated, out of range for column 'long_int' at row 1 +Warning 1262 Data truncated, out of range for column 'utiny' at row 1 +Warning 1262 Data truncated, out of range for column 'ushort' at row 1 +Warning 1262 Data truncated, out of range for column 'umedium' at row 1 +Warning 1262 Data truncated, out of range for column 'ulong' at row 1 +Warning 1263 Data truncated for column 'options' at row 1 insert into t1 values (0,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,NULL,0,0,0,4294967295,4294967295,4294967295,'4294967295',0,0); +Warnings: +Warning 1262 Data truncated, out of range for column 'tiny' at row 1 +Warning 1262 Data truncated, out of range for column 'short' at row 1 +Warning 1262 Data truncated, out of range for column 'medium' at row 1 +Warning 1262 Data truncated, out of range for column 'long_int' at row 1 +Warning 1262 Data truncated, out of range for column 'utiny' at row 1 +Warning 1262 Data truncated, out of range for column 'ushort' at row 1 +Warning 1262 Data truncated, out of range for column 'umedium' at row 1 +Warning 1263 Data truncated for column 'options' at row 1 insert into t1 (tiny) values (1); select auto,string,tiny,short,medium,long_int,longlong,real_float,real_double,utiny,ushort,umedium,ulong,ulonglong,mod(floor(time_stamp/1000000),1000000)-mod(curdate(),1000000),date_field,time_field,date_time,blob_col,tinyblob_col,mediumblob_col,longblob_col from t1; auto string tiny short medium long_int longlong real_float real_double utiny ushort umedium ulong ulonglong mod(floor(time_stamp/1000000),1000000)-mod(curdate(),1000000) date_field time_field date_time blob_col tinyblob_col mediumblob_col longblob_col @@ -136,6 +162,13 @@ new_field char(2), PRIMARY KEY (auto) ); INSERT INTO t2 (string,mediumblob_col,new_field) SELECT string,mediumblob_col,new_field from t1 where auto > 10; +Warnings: +Warning 1263 Data truncated for column 'new_field' at row 2 +Warning 1263 Data truncated for column 'new_field' at row 3 +Warning 1263 Data truncated for column 'new_field' at row 4 +Warning 1263 Data truncated for column 'new_field' at row 5 +Warning 1263 Data truncated for column 'new_field' at row 6 +Warning 1263 Data truncated for column 'new_field' at row 7 select * from t2; auto string mediumblob_col new_field 1 2 2 ne @@ -166,56 +199,60 @@ options flags one one drop table t2; create table t2 select * from t1; +Warnings: +Warning 1263 Data truncated for column 'options' at row 4 +Warning 1263 Data truncated for column 'options' at row 5 +Warning 1263 Data truncated for column 'options' at row 6 update t2 set string="changed" where auto=16; show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment -auto int(5) unsigned binary MUL NULL auto_increment select,insert,update,references +auto int(5) unsigned NULL MUL NULL auto_increment select,insert,update,references string varchar(10) latin1_swedish_ci YES new defaul select,insert,update,references -tiny tinyint(4) binary MUL 0 select,insert,update,references -short smallint(6) binary MUL 0 select,insert,update,references -medium mediumint(8) binary MUL 0 select,insert,update,references -long_int int(11) binary 0 select,insert,update,references -longlong bigint(13) binary MUL 0 select,insert,update,references -real_float float(13,1) binary MUL 0.0 select,insert,update,references -real_double double(16,4) binary YES NULL select,insert,update,references -utiny tinyint(3) unsigned binary 0 select,insert,update,references -ushort smallint(5) unsigned zerofill binary 00000 select,insert,update,references -umedium mediumint(8) unsigned binary MUL 0 select,insert,update,references -ulong int(11) unsigned binary MUL 0 select,insert,update,references -ulonglong bigint(13) unsigned binary MUL 0 select,insert,update,references -time_stamp timestamp latin1_swedish_ci YES NULL select,insert,update,references +tiny tinyint(4) NULL MUL 0 select,insert,update,references +short smallint(6) NULL MUL 0 select,insert,update,references +medium mediumint(8) NULL MUL 0 select,insert,update,references +long_int int(11) NULL 0 select,insert,update,references +longlong bigint(13) NULL MUL 0 select,insert,update,references +real_float float(13,1) NULL MUL 0.0 select,insert,update,references +real_double double(16,4) NULL YES NULL select,insert,update,references +utiny tinyint(3) unsigned NULL 0 select,insert,update,references +ushort smallint(5) unsigned zerofill NULL 00000 select,insert,update,references +umedium mediumint(8) unsigned NULL MUL 0 select,insert,update,references +ulong int(11) unsigned NULL MUL 0 select,insert,update,references +ulonglong bigint(13) unsigned NULL MUL 0 select,insert,update,references +time_stamp timestamp NULL YES NULL select,insert,update,references date_field varchar(10) latin1_swedish_ci YES NULL select,insert,update,references -time_field time latin1_swedish_ci YES NULL select,insert,update,references -date_time datetime latin1_swedish_ci YES NULL select,insert,update,references +time_field time NULL YES NULL select,insert,update,references +date_time datetime NULL YES NULL select,insert,update,references new_blob_col varchar(20) latin1_swedish_ci YES NULL select,insert,update,references -tinyblob_col tinyblob binary YES NULL select,insert,update,references -mediumblob_col mediumblob binary select,insert,update,references +tinyblob_col tinyblob NULL YES NULL select,insert,update,references +mediumblob_col mediumblob NULL select,insert,update,references options enum('one','two','tree') latin1_swedish_ci MUL one select,insert,update,references flags set('one','two','tree') latin1_swedish_ci select,insert,update,references new_field varchar(10) latin1_swedish_ci new select,insert,update,references show full columns from t2; Field Type Collation Null Key Default Extra Privileges Comment -auto int(5) unsigned binary 0 select,insert,update,references +auto int(5) unsigned NULL 0 select,insert,update,references string varchar(10) latin1_swedish_ci YES new defaul select,insert,update,references -tiny tinyint(4) binary 0 select,insert,update,references -short smallint(6) binary 0 select,insert,update,references -medium mediumint(8) binary 0 select,insert,update,references -long_int int(11) binary 0 select,insert,update,references -longlong bigint(13) binary 0 select,insert,update,references -real_float float(13,1) binary 0.0 select,insert,update,references -real_double double(16,4) binary YES NULL select,insert,update,references -utiny tinyint(3) unsigned binary 0 select,insert,update,references -ushort smallint(5) unsigned zerofill binary 00000 select,insert,update,references -umedium mediumint(8) unsigned binary 0 select,insert,update,references -ulong int(11) unsigned binary 0 select,insert,update,references -ulonglong bigint(13) unsigned binary 0 select,insert,update,references -time_stamp timestamp latin1_swedish_ci YES NULL select,insert,update,references +tiny tinyint(4) NULL 0 select,insert,update,references +short smallint(6) NULL 0 select,insert,update,references +medium mediumint(8) NULL 0 select,insert,update,references +long_int int(11) NULL 0 select,insert,update,references +longlong bigint(13) NULL 0 select,insert,update,references +real_float float(13,1) NULL 0.0 select,insert,update,references +real_double double(16,4) NULL YES NULL select,insert,update,references +utiny tinyint(3) unsigned NULL 0 select,insert,update,references +ushort smallint(5) unsigned zerofill NULL 00000 select,insert,update,references +umedium mediumint(8) unsigned NULL 0 select,insert,update,references +ulong int(11) unsigned NULL 0 select,insert,update,references +ulonglong bigint(13) unsigned NULL 0 select,insert,update,references +time_stamp timestamp NULL YES NULL select,insert,update,references date_field varchar(10) latin1_swedish_ci YES NULL select,insert,update,references -time_field time latin1_swedish_ci YES NULL select,insert,update,references -date_time datetime latin1_swedish_ci YES NULL select,insert,update,references +time_field time NULL YES NULL select,insert,update,references +date_time datetime NULL YES NULL select,insert,update,references new_blob_col varchar(20) latin1_swedish_ci YES NULL select,insert,update,references -tinyblob_col tinyblob binary YES NULL select,insert,update,references -mediumblob_col mediumblob binary select,insert,update,references +tinyblob_col tinyblob NULL YES NULL select,insert,update,references +mediumblob_col mediumblob NULL select,insert,update,references options enum('one','two','tree') latin1_swedish_ci one select,insert,update,references flags set('one','two','tree') latin1_swedish_ci select,insert,update,references new_field varchar(10) latin1_swedish_ci new select,insert,update,references @@ -229,11 +266,11 @@ drop table t2; create table t2 (primary key (auto)) select auto+1 as auto,1 as t1, "a" as t2, repeat("a",256) as t3, binary repeat("b",256) as t4 from t1; show full columns from t2; Field Type Collation Null Key Default Extra Privileges Comment -auto bigint(17) unsigned binary PRI 0 select,insert,update,references -t1 bigint(1) binary 0 select,insert,update,references +auto bigint(17) unsigned NULL PRI 0 select,insert,update,references +t1 bigint(1) NULL 0 select,insert,update,references t2 char(1) latin1_swedish_ci select,insert,update,references t3 mediumtext latin1_swedish_ci select,insert,update,references -t4 mediumtext character set latin1 latin1_bin select,insert,update,references +t4 mediumtext latin1_bin select,insert,update,references select * from t2; auto t1 t2 t3 t4 11 1 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb @@ -252,9 +289,9 @@ Duplicate column name 'c' create table t3 select t1.c AS c1, t2.c AS c2,1 as "const" from t1, t2; show full columns from t3; Field Type Collation Null Key Default Extra Privileges Comment -c1 int(11) binary YES NULL select,insert,update,references -c2 int(11) binary YES NULL select,insert,update,references -const bigint(1) binary 0 select,insert,update,references +c1 int(11) NULL YES NULL select,insert,update,references +c2 int(11) NULL YES NULL select,insert,update,references +const bigint(1) NULL 0 select,insert,update,references drop table t1,t2,t3; create table t1 ( myfield INT NOT NULL, UNIQUE INDEX (myfield), unique (myfield), index(myfield)); drop table t1; diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index bacc3ec0176..27f2de823c6 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -24,6 +24,10 @@ t 12:30:35 36:30:31 insert into t1 values("10.22.22"),(1234567),(123456789),(123456789.10),("10 22:22"),("12.45a"); +Warnings: +Warning 1262 Data truncated, out of range for column 't' at row 2 +Warning 1262 Data truncated, out of range for column 't' at row 3 +Warning 1262 Data truncated, out of range for column 't' at row 4 select * from t1; t 10:22:33 diff --git a/mysql-test/r/type_uint.result b/mysql-test/r/type_uint.result index 1acfc700d3a..ee81295e696 100644 --- a/mysql-test/r/type_uint.result +++ b/mysql-test/r/type_uint.result @@ -2,6 +2,8 @@ drop table if exists t1; create table t1 (this int unsigned); insert into t1 values (1); insert into t1 values (-1); +Warnings: +Warning 1262 Data truncated, out of range for column 'this' at row 1 select * from t1; this 1 diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 7b29a8fbcde..272ffdd330e 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -1,4 +1,4 @@ -drop table if exists t1,t2,t3; +drop table if exists t1,t2,t3,t4,t5,t6; CREATE TABLE t1 (a int not null, b char (10) not null); insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); CREATE TABLE t2 (a int not null, b char (10) not null); @@ -90,9 +90,6 @@ explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a l id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 2 UNION t2 ALL NULL NULL NULL NULL 4 Using filesort -select found_rows(); -found_rows() -0 explain select a,b from t1 union all select a,b from t2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 @@ -132,6 +129,23 @@ create table t3 select a,b from t1 union all select a,b from t2; insert into t3 select a,b from t1 union all select a,b from t2; replace into t3 select a,b as c from t1 union all select a,b from t2; drop table t1,t2,t3; +select * union select 1; +No tables used +select 1 as a,(select a union select a); +a (select a union select a) +1 1 +(select 1) union (select 2) order by 0; +Unknown column '0' in 'order clause' +SELECT @a:=1 UNION SELECT @a:=@a+1; +@a:=1 +1 +2 +(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a); +Unknown column 'a' in 'field list' +(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2); +1 3 +1 3 +2 1 CREATE TABLE t1 ( `pseudo` char(35) NOT NULL default '', `pseudo1` char(35) NOT NULL default '', @@ -198,12 +212,63 @@ a 11 set SQL_SELECT_LIMIT=DEFAULT; drop table t1,t2; -select * union select 1; -No tables used -select 1 as a,(select a union select a); -a (select a union select a) -1 1 -drop table if exists t1,t2; +CREATE TABLE t1 ( +cid smallint(5) unsigned NOT NULL default '0', +cv varchar(250) NOT NULL default '', +PRIMARY KEY (cid), +UNIQUE KEY cv (cv) +) ; +INSERT INTO t1 VALUES (8,'dummy'); +CREATE TABLE t2 ( +cid bigint(20) unsigned NOT NULL auto_increment, +cap varchar(255) NOT NULL default '', +PRIMARY KEY (cid), +KEY cap (cap) +) ; +CREATE TABLE t3 ( +gid bigint(20) unsigned NOT NULL auto_increment, +gn varchar(255) NOT NULL default '', +must tinyint(4) default NULL, +PRIMARY KEY (gid), +KEY gn (gn) +) ; +INSERT INTO t3 VALUES (1,'V1',NULL); +CREATE TABLE t4 ( +uid bigint(20) unsigned NOT NULL default '0', +gid bigint(20) unsigned default NULL, +rid bigint(20) unsigned default NULL, +cid bigint(20) unsigned default NULL, +UNIQUE KEY m (uid,gid,rid,cid), +KEY uid (uid), +KEY rid (rid), +KEY cid (cid), +KEY container (gid,rid,cid) +) ; +INSERT INTO t4 VALUES (1,1,NULL,NULL); +CREATE TABLE t5 ( +rid bigint(20) unsigned NOT NULL auto_increment, +rl varchar(255) NOT NULL default '', +PRIMARY KEY (rid), +KEY rl (rl) +) ; +CREATE TABLE t6 ( +uid bigint(20) unsigned NOT NULL auto_increment, +un varchar(250) NOT NULL default '', +uc smallint(5) unsigned NOT NULL default '0', +PRIMARY KEY (uid), +UNIQUE KEY nc (un,uc), +KEY un (un) +) ; +INSERT INTO t6 VALUES (1,'test',8); +SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test"; +uid rl g1 cid gg +1 NULL V1 NULL 1 +SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test"; +uid rl g1 cid gg +(SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test") UNION (SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test"); +uid rl g1 cid gg +1 NULL V1 NULL 1 +drop table t1,t2,t3,t4,t5,t6; CREATE TABLE t1 ( id int(3) unsigned default '0') TYPE=MyISAM; INSERT INTO t1 (id) VALUES("1"); CREATE TABLE t2 ( id int(3) unsigned default '0', id_master int(5) default '0', text1 varchar(5) default NULL, text2 varchar(5) default NULL) TYPE=MyISAM; @@ -230,10 +295,6 @@ id_master id text1 text2 1 3 NULL bar3 1 4 foo4 bar4 drop table if exists t1,t2; -(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2); -1 3 -1 3 -2 1 create table t1 (a int not null primary key auto_increment, b int, key(b)); create table t2 (a int not null primary key auto_increment, b int); insert into t1 (b) values (1),(2),(2),(3); @@ -267,11 +328,3 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 2 UNION t1 ref b b 5 const 1 Using where drop table t1,t2; -(select 1) union (select 2) order by 0; -Unknown column '0' in 'order clause' -SELECT @a:=1 UNION SELECT @a:=@a+1; -@a:=1 -1 -2 -(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a); -Unknown column 'a' in 'field list' diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result index 9978e3cb29c..1d483da2c77 100644 --- a/mysql-test/r/update.result +++ b/mysql-test/r/update.result @@ -102,16 +102,70 @@ select status from t1; status 1 drop table t1; -create table t1 (a int not null, b int not null); -insert into t1 values (1,1),(1,2),(1,3); -update t1 set b=4 where a=1 order by b asc limit 1; -update t1 set b=4 where a=1 order by b desc limit 1; -create table t2 (a int not null, b int not null); -insert into t2 values (1,1),(1,2),(1,3); -select * from t1; +create table t1 (a int not null, b int not null, key (a)); +insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3); +SET @tmp=0; +update t1 set b=(@tmp:=@tmp+1) order by a; +update t1 set b=99 where a=1 order by b asc limit 1; +select * from t1 order by a,b; a b -1 4 1 2 -1 4 +1 3 +1 99 +2 4 +2 5 +2 6 +3 7 +3 8 +3 9 +3 10 +3 11 +3 12 +update t1 set b=100 where a=1 order by b desc limit 2; +update t1 set a=a+10+b where a=1 order by b; +select * from t1 order by a,b; +a b +2 4 +2 5 +2 6 +3 7 +3 8 +3 9 +3 10 +3 11 +3 12 +13 2 +111 100 +111 100 +create table t2 (a int not null, b int not null); +insert into t2 values (1,1),(1,2),(1,3); update t1 set b=(select distinct 1 from (select * from t2) a); drop table t1,t2; +CREATE TABLE t1 ( +`id_param` smallint(3) unsigned NOT NULL default '0', +`nom_option` char(40) NOT NULL default '', +`valid` tinyint(1) NOT NULL default '0', +KEY `id_param` (`id_param`,`nom_option`) +) TYPE=MyISAM; +INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1); +UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1; +select * from t1; +id_param nom_option valid +185 test 1 +drop table t1; +create table t1 (F1 VARCHAR(30), F2 VARCHAR(30), F3 VARCHAR(30), cnt int, groupid int, KEY groupid_index (groupid)); +insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6), +('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2), +('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4), +('2','2','0',1,7); +delete from t1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3); +select * from t1; +F1 F2 F3 cnt groupid +0 0 0 1 6 +0 1 2 1 5 +0 2 0 1 3 +1 0 1 1 2 +1 2 1 1 1 +2 0 1 2 4 +2 2 0 1 7 +drop table t1; diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 5e613418ea1..b5e05cf6953 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -108,17 +108,14 @@ show global variables like 'table_type'; Variable_name Value table_type INNODB set GLOBAL query_cache_size=100000; -set myisam_max_sort_file_size=10000, GLOBAL myisam_max_sort_file_size=20000; -show variables like 'myisam_max_sort_file_size'; -Variable_name Value -myisam_max_sort_file_size 10000 +set GLOBAL myisam_max_sort_file_size=2000000; show global variables like 'myisam_max_sort_file_size'; Variable_name Value -myisam_max_sort_file_size 20000 -set myisam_max_sort_file_size=default; +myisam_max_sort_file_size 1048576 +set GLOBAL myisam_max_sort_file_size=default; show variables like 'myisam_max_sort_file_size'; Variable_name Value -myisam_max_sort_file_size 20000 +myisam_max_sort_file_size FILE_SIZE set global net_retry_count=10, session net_retry_count=10; set global net_buffer_length=1024, net_write_timeout=200, net_read_timeout=300; set session net_buffer_length=2048, net_write_timeout=500, net_read_timeout=600; @@ -156,9 +153,9 @@ show variables like 'net_buffer_length'; Variable_name Value net_buffer_length 1048576 set character set cp1251_koi8; -show variables like "collation_client"; +show variables like "character_set_client"; Variable_name Value -collation_client cp1251_bulgarian_ci +character_set_client cp1251 select @@timestamp>0; @@timestamp>0 1 @@ -185,7 +182,7 @@ set SESSION query_cache_size=10000; Variable 'query_cache_size' is a GLOBAL variable and should be set with SET GLOBAL set GLOBAL table_type=DEFAULT; Variable 'table_type' doesn't have a default value -set collation_client=UNKNOWN_CHARACTER_SET; +set character_set_client=UNKNOWN_CHARACTER_SET; Unknown character set: 'UNKNOWN_CHARACTER_SET' set global autocommit=1; Variable 'autocommit' is a LOCAL variable and can't be used with SET GLOBAL @@ -199,6 +196,10 @@ set @@global.sql_auto_is_null=1; Variable 'sql_auto_is_null' is a LOCAL variable and can't be used with SET GLOBAL select @@global.sql_auto_is_null; Variable 'sql_auto_is_null' is a LOCAL variable and can't be used with SET GLOBAL +set myisam_max_sort_file_size=100; +Variable 'myisam_max_sort_file_size' is a GLOBAL variable and should be set with SET GLOBAL +set myisam_max_extra_sort_file_size=100; +Variable 'myisam_max_extra_sort_file_size' is a GLOBAL variable and should be set with SET GLOBAL set autocommit=1; set big_tables=1; select @@autocommit, @@big_tables; @@ -252,11 +253,11 @@ select @@max_user_connections; @@max_user_connections 100 set global max_write_lock_count=100; -set myisam_max_extra_sort_file_size=100; +set global myisam_max_extra_sort_file_size=100; select @@myisam_max_extra_sort_file_size; @@myisam_max_extra_sort_file_size 100 -set myisam_max_sort_file_size=100; +set global myisam_max_sort_file_size=100; set myisam_sort_buffer_size=100; set net_buffer_length=100; set net_read_timeout=100; @@ -323,3 +324,8 @@ test.t1 check status OK test.t2 check status OK select max(a) +1, max(a) +2 into @xx,@yy from t1; drop table t1,t2; +select @@xxxxxxxxxx; +Unknown system variable 'xxxxxxxxxx' +select 1; +1 +1 diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result index d055511a50a..add9051ddfb 100644 --- a/mysql-test/r/warnings.result +++ b/mysql-test/r/warnings.result @@ -1,13 +1,24 @@ -drop table if exists t1; +drop table if exists t1, t2; Warnings: Note 1051 Unknown table 't1' +Note 1051 Unknown table 't2' create table t1 (a int); insert into t1 values (1); insert into t1 values ("hej"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 1 insert into t1 values ("hej"),("då"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 1 +Warning 1263 Data truncated for column 'a' at row 2 set SQL_WARNINGS=1; insert into t1 values ("hej"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 1 insert into t1 values ("hej"),("då"); +Warnings: +Warning 1263 Data truncated for column 'a' at row 1 +Warning 1263 Data truncated for column 'a' at row 2 drop table t1; set SQL_WARNINGS=0; drop temporary table if exists not_exists; @@ -31,10 +42,78 @@ select @@warning_count; @@warning_count 0 drop table t1; +create table t1(a tinyint, b int not null, c date, d char(5)); +load data infile '../../std_data/warnings_loaddata.dat' into table t1 fields terminated by ','; +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'b' at row 2 +Warning 1263 Data truncated for column 'd' at row 3 +Warning 1263 Data truncated for column 'c' at row 4 +Warning 1259 Record count is fewer than the column count at row 5 +Warning 1263 Data truncated for column 'b' at row 6 +Warning 1260 Record count is more than the column count at row 7 +Warning 1262 Data truncated, out of range for column 'a' at row 8 +select @@warning_count; +@@warning_count +7 +drop table t1; +create table t1(a tinyint NOT NULL, b tinyint unsigned, c char(5)); +insert into t1 values(NULL,100,'mysql'),(10,-1,'mysql ab'),(500,256,'open source'),(20,NULL,'test'); +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'a' at row 1 +Warning 1262 Data truncated, out of range for column 'b' at row 2 +Warning 1263 Data truncated for column 'c' at row 2 +Warning 1262 Data truncated, out of range for column 'a' at row 3 +Warning 1262 Data truncated, out of range for column 'b' at row 3 +Warning 1263 Data truncated for column 'c' at row 3 +alter table t1 modify c char(4); +Warnings: +Warning 1263 Data truncated for column 'c' at row 1 +Warning 1263 Data truncated for column 'c' at row 2 +alter table t1 add d char(2); +update t1 set a=NULL where a=10; +Warnings: +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'a' at row 2 +update t1 set c='mysql ab' where c='test'; +Warnings: +Warning 1263 Data truncated for column 'c' at row 4 +update t1 set d=c; +Warnings: +Warning 1263 Data truncated for column 'd' at row 1 +Warning 1263 Data truncated for column 'd' at row 2 +Warning 1263 Data truncated for column 'd' at row 3 +Warning 1263 Data truncated for column 'd' at row 4 +create table t2(a tinyint NOT NULL, b char(3)); +insert into t2 select b,c from t1; +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warning 1263 Data truncated for column 'b' at row 2 +Warning 1263 Data truncated for column 'b' at row 3 +Warning 1261 Data truncated, NULL supplied to NOT NULL column 'a' at row 4 +Warning 1263 Data truncated for column 'b' at row 4 +drop table t1, t2; +create table t1(a char(10)); +alter table t1 add b char; +set max_error_count=10; +update t1 set b=a; +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 +Warning 1263 Data truncated for column 'b' at row 2 +Warning 1263 Data truncated for column 'b' at row 3 +Warning 1263 Data truncated for column 'b' at row 4 +Warning 1263 Data truncated for column 'b' at row 5 +Warning 1263 Data truncated for column 'b' at row 6 +Warning 1263 Data truncated for column 'b' at row 7 +Warning 1263 Data truncated for column 'b' at row 8 +Warning 1263 Data truncated for column 'b' at row 9 +Warning 1263 Data truncated for column 'b' at row 10 +select @@warning_count; +@@warning_count +50 +drop table t1; create table t1 (id int) type=isam; Warnings: -Warning 1259 Using storage engine MYISAM for table 't1' +Warning 1264 Using storage engine MYISAM for table 't1' alter table t1 type=isam; Warnings: -Warning 1259 Using storage engine MYISAM for table 't1' +Warning 1264 Using storage engine MYISAM for table 't1' drop table t1; diff --git a/mysql-test/std_data/loaddata1.dat b/mysql-test/std_data/loaddata1.dat new file mode 100644 index 00000000000..c9e8549b211 --- /dev/null +++ b/mysql-test/std_data/loaddata1.dat @@ -0,0 +1,3 @@ +,\N,NULL,, +00,0,000000,, +2003-03-03, 20030303,030303,\N diff --git a/mysql-test/std_data/warnings_loaddata.dat b/mysql-test/std_data/warnings_loaddata.dat new file mode 100644 index 00000000000..e645de775ab --- /dev/null +++ b/mysql-test/std_data/warnings_loaddata.dat @@ -0,0 +1,8 @@ +10,20,2003-04-21,mysql +20,\N,2003-04-22,MySQL +30,40,2003-04-23,MySQL is Open Source Database +40,50,monty,30 +50,60,2003-04-24 +60,67 abc,2003-04-25,mysql +70,80,2003-04-26,mysql,open,source +500,90,2003-04-27,mysql diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 64b657f1146..fc22bc85aee 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -88,6 +88,7 @@ create table t1 (n1 int not null, n2 int, n3 int, n4 float, key (n3, n4, n1, n2), key (n4, n1, n2, n3) ); alter table t1 disable keys; +show keys from t1; #let $1=10000; let $1=10; while ($1) @@ -96,6 +97,7 @@ while ($1) dec $1; } alter table t1 enable keys; +show keys from t1; drop table t1; # @@ -117,3 +119,19 @@ alter table t1 rename t2; alter table t2 rename t1, add c char(10) comment "no comment"; show columns from t1; drop table t1; + +# implicit analyze + +create table t1 (a int, b int); +let $1=100; +while ($1) +{ + eval insert into t1 values(1,$1), (2,$1), (3, $1); + dec $1; +} +alter table t1 add unique (a,b), add key (b); +show keys from t1; +analyze table t1; +show keys from t1; +drop table t1; + diff --git a/mysql-test/t/ansi-master.opt b/mysql-test/t/ansi-master.opt new file mode 100644 index 00000000000..6bf7a4f30e2 --- /dev/null +++ b/mysql-test/t/ansi-master.opt @@ -0,0 +1 @@ +--ansi diff --git a/mysql-test/t/ansi.test b/mysql-test/t/ansi.test new file mode 100644 index 00000000000..da82b7a9e31 --- /dev/null +++ b/mysql-test/t/ansi.test @@ -0,0 +1,19 @@ +# +# Test of ansi mode +# + +--disable_warnings +drop table if exists t1; +--enable_warnings + +# Test some functions that works different in ansi mode + +SELECT 'A' || 'B'; + +# Test GROUP BY behaviour + +CREATE TABLE t1 (id INT, id2 int); +SELECT id,NULL,1,1.1,'a' FROM t1 GROUP BY id; +--error 1055 +SELECT id FROM t1 GROUP BY id2; +drop table t1; diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 8703a6b739d..8241d491465 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -14,6 +14,16 @@ select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME); select cast("1:2:3" as TIME); # +# Character set convertion +# +set names binary; +select cast(_latin1'test' as char character set latin2); +select cast(_koi8r'ÔÅÓÔ' as char character set cp1251); +create table t1 select cast(_koi8r'ÔÅÓÔ' as char character set cp1251) as t; +show create table t1; +drop table t1; + +# # The following should be fixed in 4.1 # diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index cda9307804b..9bc37a0864d 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -27,11 +27,9 @@ drop table if exists t1,t2; !$1167 create table t1 (b char(0) not null, index(b)); create table t1 (a int not null auto_increment,primary key (a)) type=heap; !$1163 create table t1 (a int not null,b text) type=heap; -!$1171 create table t1 (a int ,primary key(a)) type=heap; drop table if exists t1; !$1075 create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) type=heap; -!$1171 create table t1 (ordid int(8), primary key (ordid)); -- error 1044,1 create table not_existing_database.test (a int); @@ -124,6 +122,41 @@ drop table t1; create table t1 select if('2002'='2002','Y','N'); select * from t1; drop table if exists t1; + +# +# Test default table type +# +SET SESSION table_type="heap"; +SELECT @@table_type; +CREATE TABLE t1 (a int not null); +show create table t1; +drop table t1; +# Test what happens when using a non existing table type +SET SESSION table_type="gemini"; +SELECT @@table_type; +CREATE TABLE t1 (a int not null); +show create table t1; +SET SESSION table_type=default; +drop table t1; + + +# +# ISO requires that primary keys are implicitly NOT NULL +# +create table t1 ( k1 varchar(2), k2 int, primary key(k1,k2)); +insert into t1 values ("a", 1), ("b", 2); +--error 1048 +insert into t1 values ("c", NULL); +--error 1048 +insert into t1 values (NULL, 3); +--error 1048 +insert into t1 values (NULL, NULL); +drop table t1; + +# +# Test create with foreign keys +# + create table t1 (a int, key(a)); create table t2 (b int, foreign key(b) references t1(a), key(b)); drop table if exists t1,t2; diff --git a/mysql-test/t/ctype_collate.test b/mysql-test/t/ctype_collate.test index 0b32c3ccf88..0cf531156a9 100644 --- a/mysql-test/t/ctype_collate.test +++ b/mysql-test/t/ctype_collate.test @@ -9,7 +9,7 @@ CREATE TABLE t1 ( --error 1251 CREATE TABLE t2 ( - latin1_f CHAR(32) CHARACTER SET latin1 COLLATE koi8r NOT NULL + latin1_f CHAR(32) CHARACTER SET latin1 COLLATE koi8r_general_ci NOT NULL ); @@ -57,39 +57,39 @@ INSERT INTO t1 (latin1_f) VALUES (_latin1'z'); -- ORDER BY SELECT latin1_f FROM t1 ORDER BY latin1_f; -SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1; +SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1_swedish_ci; SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1_german2_ci; SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1_general_ci; SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE latin1_bin; --error 1251 -SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE koi8r; +SELECT latin1_f FROM t1 ORDER BY latin1_f COLLATE koi8r_general_ci; --SELECT latin1_f COLLATE koi8r FROM t1 ; -- AS + ORDER BY -SELECT latin1_f COLLATE latin1 AS latin1_f_as FROM t1 ORDER BY latin1_f_as; +SELECT latin1_f COLLATE latin1_swedish_ci AS latin1_f_as FROM t1 ORDER BY latin1_f_as; SELECT latin1_f COLLATE latin1_german2_ci AS latin1_f_as FROM t1 ORDER BY latin1_f_as; SELECT latin1_f COLLATE latin1_general_ci AS latin1_f_as FROM t1 ORDER BY latin1_f_as; SELECT latin1_f COLLATE latin1_bin AS latin1_f_as FROM t1 ORDER BY latin1_f_as; --error 1251 -SELECT latin1_f COLLATE koi8r AS latin1_f_as FROM t1 ORDER BY latin1_f_as; +SELECT latin1_f COLLATE koi8r_general_ci AS latin1_f_as FROM t1 ORDER BY latin1_f_as; -- GROUP BY SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f; -SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1; +SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1_swedish_ci; SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1_german2_ci; SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1_general_ci; SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE latin1_bin; --error 1251 -SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE koi8r; +SELECT latin1_f,count(*) FROM t1 GROUP BY latin1_f COLLATE koi8r_general_ci; -- DISTINCT SELECT DISTINCT latin1_f FROM t1; -SELECT DISTINCT latin1_f COLLATE latin1 FROM t1; +SELECT DISTINCT latin1_f COLLATE latin1_swedish_ci FROM t1; SELECT DISTINCT latin1_f COLLATE latin1_german2_ci FROM t1; SELECT DISTINCT latin1_f COLLATE latin1_general_ci FROM t1; SELECT DISTINCT latin1_f COLLATE latin1_bin FROM t1; @@ -127,35 +127,19 @@ ALTER TABLE t1 CHARACTER SET latin1 COLLATE latin1_bin; SHOW CREATE TABLE t1; SHOW FIELDS FROM t1; +# +# Check SET CHARACTER SET +# + SET CHARACTER SET 'latin1'; -SHOW VARIABLES LIKE 'collation_client'; -SET CHARACTER SET latin1; -SHOW VARIABLES LIKE 'collation_client'; -SHOW VARIABLES LIKE 'collation_client'; -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -SET CHARACTER SET latin1 COLLATE latin1_bin; -SHOW VARIABLES LIKE 'collation_client'; -SET CHARACTER SET LATIN1 COLLATE Latin1_Bin; -SHOW VARIABLES LIKE 'collation_client'; -SET CHARACTER SET 'latin1' COLLATE 'latin1_bin'; -SHOW VARIABLES LIKE 'collation_client'; +SHOW VARIABLES LIKE 'character_set_client'; SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; + SET CHARACTER SET koi8r; SHOW VARIABLES LIKE 'collation_client'; SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -SET CHARACTER SET koi8r COLLATE koi8r_bin; -SHOW VARIABLES LIKE 'collation_client'; -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -SET CHARACTER SET koi8r COLLATE DEFAULT; -SHOW VARIABLES LIKE 'collation_client'; -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; -SET CHARACTER SET DEFAULT; -SHOW VARIABLES LIKE 'collation_client'; -SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; ---error 1251 -SET CHARACTER SET latin1 COLLATE koi8r; + --error 1115 SET CHARACTER SET 'DEFAULT'; - DROP TABLE t1; diff --git a/mysql-test/t/ctype_latin1_de-master.opt b/mysql-test/t/ctype_latin1_de-master.opt index 62f864d501d..79fdb1c63dc 100644 --- a/mysql-test/t/ctype_latin1_de-master.opt +++ b/mysql-test/t/ctype_latin1_de-master.opt @@ -1 +1 @@ ---default-character-set=latin1_german2_ci +--default-character-set=latin1 --default-collation=latin1_german2_ci diff --git a/mysql-test/t/ctype_latin1_de.test b/mysql-test/t/ctype_latin1_de.test index e0591913f68..b63af87601b 100644 --- a/mysql-test/t/ctype_latin1_de.test +++ b/mysql-test/t/ctype_latin1_de.test @@ -47,3 +47,26 @@ select * from t1 where a like "test%"; select * from t1 where a like "te_t"; select * from t1 where match a against ("te*" in boolean mode)+0; drop table t1; + +# +# Test bug report #152 (problem with index on latin1_de) +# + +create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word)); +insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); +update t1 set word2=word; +select word, word=0xdf as t from t1 having t > 0; +select word, word=cast(0xdf AS CHAR) as t from t1 having t > 0; +select * from t1 where word=0xDF; +select * from t1 where word=CAST(0xDF as CHAR); +select * from t1 where word2=0xDF; +select * from t1 where word2=CAST(0xDF as CHAR); +select * from t1 where word='ae'; +select * from t1 where word= 0xe4 or word=CAST(0xe4 as CHAR); +select * from t1 where word between 0xDF and 0xDF; +select * from t1 where word between CAST(0xDF AS CHAR) and CAST(0xDF AS CHAR); +select * from t1 where word like 'ae'; +select * from t1 where word like 'AE'; +select * from t1 where word like 0xDF; +select * from t1 where word like CAST(0xDF as CHAR); +drop table t1; diff --git a/mysql-test/t/ctype_many.test b/mysql-test/t/ctype_many.test index 8378ef35685..66732520f4d 100644 --- a/mysql-test/t/ctype_many.test +++ b/mysql-test/t/ctype_many.test @@ -1,3 +1,5 @@ +-- source include/have_ucs2.inc + --disable_warnings DROP TABLE IF EXISTS t1; --enable_warnings @@ -167,7 +169,10 @@ ORDER BY t12.utf8_f,t11.comment,t12.comment; SET CHARACTER SET utf8; ALTER TABLE t1 ADD ucs2_f CHAR(32) CHARACTER SET ucs2; + +--disable_warnings ALTER TABLE t1 CHANGE ucs2_f ucs2_f CHAR(32) UNICODE NOT NULL; +--enable_warnings INSERT INTO t1 (ucs2_f,comment) VALUES (0x0391,'GREEK CAPIT ALPHA'); INSERT INTO t1 (ucs2_f,comment) VALUES (0x0392,'GREEK CAPIT BETA'); diff --git a/mysql-test/t/ctype_recoding.test b/mysql-test/t/ctype_recoding.test index 0330bbd23b4..68526806166 100644 --- a/mysql-test/t/ctype_recoding.test +++ b/mysql-test/t/ctype_recoding.test @@ -26,3 +26,4 @@ SHOW FIELDS FROM таблица; SET CHARACTER SET koi8r; DROP TABLE ÔÁÂÌÉÃÁ; +SET CHARACTER SET default; diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test new file mode 100644 index 00000000000..e41caf55948 --- /dev/null +++ b/mysql-test/t/ctype_ujis.test @@ -0,0 +1,17 @@ +-- source include/have_ujis.inc + +# +# Tests with the ujis character set +# +--disable_warnings +drop table if exists t1; +--enable_warnings + +# +# Test problem with LEFT() +# + +create table t1 (c text character set ujis); +insert into t1 values (0xa4a2),(0xa4a3); +select hex(left(c,1)) from t1 group by c; +drop table t1; diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index 91216ff9c3a..f1f751d728b 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -64,4 +64,10 @@ select * from t1 where misc > 5 and bool is null; delete from t1 where misc > 5 and bool is null; select * from t1 where misc > 5 and bool is null; +select count(*) from t1; +delete from t1 where 1 > 2; +select count(*) from t1; +delete from t1 where 3 > 2; +select count(*) from t1; + drop table t1; diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test index 214236268fa..40ac7f905c7 100644 --- a/mysql-test/t/fulltext.test +++ b/mysql-test/t/fulltext.test @@ -175,3 +175,14 @@ repair table t1; select * from t1 where match (a) against ('aaaa'); drop table t1; +# +# bug 283 by jocelyn fournier <joc@presence-pc.com> +# FULLTEXT index on a TEXT filed converted to a CHAR field doesn't work anymore +# + +create table t1 ( ref_mag text not null, fulltext (ref_mag)); +insert into t1 values ('test'); +select ref_mag from t1 where match ref_mag against ('+test' in boolean mode); +alter table t1 change ref_mag ref_mag char (255) not null; +select ref_mag from t1 where match ref_mag against ('+test' in boolean mode); +drop table t1; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index c78509d3869..aca9530ffc3 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -326,6 +326,26 @@ explain select min(a4) from t1 where (a4 + 0.01) between 0.07 and 0.08; explain select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME'; +drop table t1, t2; -# Clean up -drop table if exists t1, t2;
\ No newline at end of file + +# +# Test of group function and NULL values +# + +CREATE TABLE t1 (a int, b int); +select count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1; +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +insert into t1 values (1,null); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +insert into t1 values (1,null); +insert into t1 values (2,null); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +insert into t1 values (2,1); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +insert into t1 values (3,1); +select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +drop table t1; diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index d48b17e87af..be64c170fa1 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -7,3 +7,8 @@ select format(1.5555,0),format(123.5555,1),format(1234.5555,2),format(12345.5555 select inet_ntoa(inet_aton("255.255.255.255.255.255.255.255")); select inet_aton("255.255.255.255.255"),inet_aton("255.255.1.255"),inet_aton("0.1.255"); select inet_ntoa(1099511627775),inet_ntoa(4294902271),inet_ntoa(511); + +# +# Test for core dump with nan +# +select length(format('nan', 2)) > 0; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 96d5b17abd7..43530aa640d 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -132,3 +132,26 @@ CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id ( INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf'); SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password"); DROP TABLE t1; + +# +# Test collation and coercibility +# +select collation(lcase(_latin2'a')), coercibility(lcase(_latin2'a')); +select collation(ucase(_latin2'a')), coercibility(ucase(_latin2'a')); +select collation(left(_latin2'a',1)), coercibility(left(_latin2'a',1)); +select collation(right(_latin2'a',1)), coercibility(right(_latin2'a',1)); +select collation(substring(_latin2'a',1,1)), coercibility(substring(_latin2'a',1,1)); +select collation(concat(_latin2'a',_latin2'b')), coercibility(concat(_latin2'a',_latin2'b')); +select collation(concat_ws(_latin2'a',_latin2'b')), coercibility(concat_ws(_latin2'a',_latin2'b')); +create table t1 +select + left(_latin2'a',1), + right(_latin2'a',1), + lcase(_latin2'a'), + ucase(_latin2'a'), + substring(_latin2'a',1,1), + concat(_latin2'a',_latin2'b'), + concat_ws(_latin2'a',_latin2'b'); + +show create table t1; +drop table t1; diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test index db366e3ab49..41b776719dc 100644 --- a/mysql-test/t/func_system.test +++ b/mysql-test/t/func_system.test @@ -2,6 +2,24 @@ # system functions # -select database(),user() like "%@%"; +select database(); +select charset(database()); +select database() = "test"; +select database() = _utf8"test"; +select database() = _latin1"test"; + +select user() like "%@%"; +select user() like _utf8"%@%"; +select user() like _latin1"%@%"; +select charset(user()); + +select version()>="3.23.29"; select version()>=_utf8"3.23.29"; +select version()>=_latin1"3.23.29"; +select charset(version()); + +create table t1 select database(), user(), version(); +show create table t1; +drop table t1; + select TRUE,FALSE,NULL; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 912bed1955c..d99c7a87f88 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -44,12 +44,15 @@ CREATE TABLE t2 ( INSERT INTO t2 VALUES (1,'name','pass','mail','Y','v','n','adr','1','1','1'); INSERT INTO t2 VALUES (2,'name','pass','mail','Y','v','n','adr','1','1','1'); INSERT INTO t2 VALUES (3,'name','pass','mail','Y','v','n','adr','1','1','1'); +INSERT INTO t2 VALUES (4,'name','pass','mail','Y','v','n','adr','1','1','1'); +INSERT INTO t2 VALUES (5,'name','pass','mail','Y','v','n','adr','1','1','1'); SELECT t2.userid, MIN(t1.score) FROM t1, t2 WHERE t1.userID=t2.userID GROUP BY t2.userid; SELECT t2.userid, MIN(t1.score) FROM t1, t2 WHERE t1.userID=t2.userID GROUP BY t2.userid ORDER BY NULL; SELECT t2.userid, MIN(t1.score) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid; SELECT t2.userid, MIN(t1.score+0.0) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid; SELECT t2.userid, MIN(t1.score+0.0) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid ORDER BY NULL; +EXPLAIN SELECT t2.userid, MIN(t1.score+0.0) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid ORDER BY NULL; drop table t1,t2; # @@ -246,7 +249,7 @@ CREATE TABLE t1 ( key (score) ); -INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3); +INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3),(6,3,3),(7,3,3); explain select userid,count(*) from t1 group by userid desc; explain select userid,count(*) from t1 group by userid desc order by null; select userid,count(*) from t1 group by userid desc; @@ -265,8 +268,6 @@ explain select sql_big_result score,count(*) from t1 group by score desc order b select sql_big_result score,count(*) from t1 group by score desc; drop table t1; -# - # not purely group_by bug, but group_by is involved... create table t1 (a date default null, b date default null); @@ -275,7 +276,6 @@ select a,min(b) c,count(distinct rand()) from t1 group by a having c<a + interva drop table t1; # Compare with hash keys -# CREATE TABLE t1 (a char(1)); INSERT INTO t1 VALUES ('A'),('B'),('A'),('B'),('A'),('B'),(NULL),('a'),('b'),(NULL),('A'),('B'),(NULL); @@ -410,15 +410,7 @@ drop table t1,t2; # create table t1 (a int, b int); -insert into t1 values (1, 4); -insert into t1 values (10, 40); -insert into t1 values (1, 4); -insert into t1 values (10, 43); -insert into t1 values (1, 4); -insert into t1 values (10, 41); -insert into t1 values (1, 4); -insert into t1 values (10, 43); -insert into t1 values (1, 4); +insert into t1 values (1, 4),(10, 40),(1, 4),(10, 43),(1, 4),(10, 41),(1, 4),(10, 43),(1, 4); select a, MAX(b), INTERVAL (MAX(b), 1,3,10,30,39,40,50,60,100,1000) from t1 group by a; select a, MAX(b), CASE MAX(b) when 4 then 4 when 43 then 43 else 0 end from t1 group by a; select a, MAX(b), FIELD(MAX(b), '43', '4', '5') from t1 group by a; diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 4bd56400f98..7d5fbee011f 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -64,3 +64,13 @@ select Fld1, max(Fld2) from t1 group by Fld1 having avg(Fld2) is not null; select Fld1, max(Fld2) from t1 group by Fld1 having std(Fld2) is not null; select Fld1, max(Fld2) from t1 group by Fld1 having variance(Fld2) is not null; drop table t1; + +# +# Test problem with count(distinct) in having +# +create table t1 (id int not null, qty int not null); +insert into t1 values (1,2),(1,3),(2,4),(2,5); +select id, sum(qty) as sqty from t1 group by id having sqty>2; +select sum(qty) as sqty from t1 group by id having count(id) > 0; +select sum(qty) as sqty from t1 group by id having count(distinct id) > 0; +drop table t1; diff --git a/mysql-test/t/help.test b/mysql-test/t/help.test index c36b670c6b3..82312340336 100644 --- a/mysql-test/t/help.test +++ b/mysql-test/t/help.test @@ -1,50 +1,115 @@ -- source include/have_innodb.inc -truncate mysql.help_topic; -truncate mysql.help_category; -truncate mysql.help_relation; - -insert into mysql.help_topic(name,description,example)values('impossible_function_1','description of \n impossible_function1','example of \n impossible_function1'); -SELECT @topic1_id:=LAST_INSERT_ID(); -insert into mysql.help_topic(name,description,example)values('impossible_function_2','description of \n impossible_function2','example of \n impossible_function2'); -SELECT @topic2_id:=LAST_INSERT_ID(); -insert into mysql.help_topic(name,description,example)values('impossible_function_3','description of \n impossible_function3','example of \n impossible_function3'); -SELECT @topic3_id:=LAST_INSERT_ID(); - -insert into mysql.help_category(name)values('impossible_category_1'); -SELECT @category1_id:=LAST_INSERT_ID(); -insert into mysql.help_category(name)values('impossible_category_2'); -SELECT @category2_id:=LAST_INSERT_ID(); - -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category1_id,@topic1_id); -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category1_id,@topic2_id); -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category2_id,@topic2_id); -insert into mysql.help_relation(help_category_id,help_topic_id)values(@category2_id,@topic3_id); +# category: topic: keyword: +# +# impossible_category_1 +# impossible_function_1 +# impossible_function_5 +# impossible_function_2 +# impossible_function_1 +# impossible_category_2 +# impossible_function_3 +# impossible_function_6 +# impossible_function_4 +# impossible_function_6 +# impossible_category_3 +# impossible_function_7 +insert into mysql.help_category(help_category_id,name)values(1,'impossible_category_1'); +select @category1_id:= 1; +insert into mysql.help_category(help_category_id,name)values(2,'impossible_category_2'); +select @category2_id:= 2; +insert into mysql.help_category(help_category_id,name,parent_category_id)values(3,'impossible_category_3',@category2_id); +select @category3_id:= 3; + +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(1,'impossible_function_1',@category1_id,'description of \n impossible_function1\n','example of \n impossible_function1'); +select @topic1_id:= 1; +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(2,'impossible_function_2',@category1_id,'description of \n impossible_function2\n','example of \n impossible_function2'); +select @topic2_id:= 2; +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(3,'impossible_function_3',@category2_id,'description of \n impossible_function3\n','example of \n impossible_function3'); +select @topic3_id:= 3; +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(4,'impossible_function_4',@category2_id,'description of \n impossible_function4\n','example of \n impossible_function4'); +select @topic4_id:= 4; +insert into mysql.help_topic(help_topic_id,name,help_category_id,description,example)values(5,'impossible_function_7',@category3_id,'description of \n impossible_function5\n','example of \n impossible_function7'); +select @topic5_id:= 5; + +insert into mysql.help_keyword(help_keyword_id,name)values(1,'impossible_function_1'); +select @keyword1_id:= 1; +insert into mysql.help_keyword(help_keyword_id,name)values(2,'impossible_function_5'); +select @keyword2_id:= 2; +insert into mysql.help_keyword(help_keyword_id,name)values(3,'impossible_function_6'); +select @keyword3_id:= 3; + +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword1_id,@topic2_id); +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword2_id,@topic1_id); +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword3_id,@topic3_id); +insert into mysql.help_relation(help_keyword_id,help_topic_id)values(@keyword3_id,@topic4_id); + +############## help 'function_of_my_dream'; help '%possible_f%'; help 'impossible_func%'; help 'impossible_category%'; help 'impossible_%'; + +help '%function_1'; help '%function_2'; +help '%function_3'; +help '%function_4'; +help '%function_5'; +help '%function_6'; +help '%function_7'; + help '%category_2'; help 'impossible_function_1'; help 'impossible_category_1'; +############## +alter table mysql.help_relation type=innodb; +alter table mysql.help_keyword type=innodb; alter table mysql.help_topic type=innodb; alter table mysql.help_category type=innodb; -alter table mysql.help_relation type=innodb; +############## help 'function_of_my_dream'; -help '%ble_f%'; +help '%possible_f%'; help 'impossible_func%'; help 'impossible_category%'; help 'impossible_%'; + +help '%function_1'; help '%function_2'; +help '%function_3'; +help '%function_4'; +help '%function_5'; +help '%function_6'; +help '%function_7'; + help '%category_2'; help 'impossible_function_1'; help 'impossible_category_1'; +############## +alter table mysql.help_relation type=myisam; +alter table mysql.help_keyword type=myisam; alter table mysql.help_topic type=myisam; alter table mysql.help_category type=myisam; -alter table mysql.help_relation type=myisam; + +delete from mysql.help_topic where help_topic_id=@topic1_id; +delete from mysql.help_topic where help_topic_id=@topic2_id; +delete from mysql.help_topic where help_topic_id=@topic3_id; +delete from mysql.help_topic where help_topic_id=@topic4_id; +delete from mysql.help_topic where help_topic_id=@topic5_id; + +delete from mysql.help_category where help_category_id=@category3_id; +delete from mysql.help_category where help_category_id=@category2_id; +delete from mysql.help_category where help_category_id=@category1_id; + +delete from mysql.help_keyword where help_keyword_id=@keyword1_id; +delete from mysql.help_keyword where help_keyword_id=@keyword2_id; +delete from mysql.help_keyword where help_keyword_id=@keyword3_id; + +delete from mysql.help_relation where help_keyword_id=@keyword1_id and help_topic_id=@topic2_id; +delete from mysql.help_relation where help_keyword_id=@keyword2_id and help_topic_id=@topic1_id; +delete from mysql.help_relation where help_keyword_id=@keyword3_id and help_topic_id=@topic3_id; +delete from mysql.help_relation where help_keyword_id=@keyword3_id and help_topic_id=@topic4_id; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index bf1756ede5c..3736f4a2ddc 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -45,12 +45,9 @@ update ignore t1 set id=id+1; # This will change all rows select * from t1; update ignore t1 set id=1023 where id=1010; select * from t1 where parent_id=102; ---replace_result 12 # 6 # -explain select level from t1 where level=1; ---replace_result 12 # 6 # -explain select level,id from t1 where level=1; ---replace_result 12 # 6 # 5 # -explain select level,id,parent_id from t1 where level=1; +# explain select level from t1 where level=1; +# explain select level,id from t1 where level=1; +# explain select level,id,parent_id from t1 where level=1; select level,id from t1 where level=1; select level,id,parent_id from t1 where level=1; optimize table t1; @@ -348,7 +345,7 @@ update ignore t1 set id=id+1; # This will change all rows select * from t1; update ignore t1 set id=1023 where id=1010; select * from t1 where parent_id=102; -explain select level from t1 where level=1; +# explain select level from t1 where level=1; select level,id from t1 where level=1; select level,id,parent_id from t1 where level=1; select level,id from t1 where level=1 order by id; @@ -784,7 +781,7 @@ drop table t1; CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) type=innodb; CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) type=innodb; -INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12); INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); # Full join, without key @@ -800,11 +797,76 @@ update t1,t2 set t1.b=t1.b+10 where t1.b=2; select * from t1; # Range key (in t1) -update t1,t2 set t1.b=t1.b+2,t2.b=t1.b where t1.b between 3 and 5; +update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100; select * from t1; select * from t2; drop table t1,t2; +CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) TYPE=MyISAM; +CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) TYPE=InnoDB; +SET AUTOCOMMIT=0; +INSERT INTO t1 ( B_ID ) VALUES ( 1 ); +INSERT INTO t2 ( NEXT_T ) VALUES ( 1 ); +ROLLBACK; +SELECT * FROM t1; +drop table t1,t2; +create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) type = innodb; +insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2); +select distinct parent,child from t1 order by parent; +drop table t1; + +# +# Test that MySQL priorities clustered indexes +# +create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) type=innodb; +create table t2 (a int not null auto_increment primary key, b int); +insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null); +insert into t2 (a) select b from t1; +insert into t1 (b) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +insert into t2 (a) select b from t1; +insert into t1 (a) select b from t2; +select count(*) from t1; +explain select * from t1 where c between 1 and 10000; +update t1 set c=a; +explain select * from t1 where c between 1 and 10000; +drop table t1,t2; + +# +# Test of UPDATE ... ORDER BY +# + +create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) type=innodb; + +insert into t1 (id) values (null),(null),(null),(null),(null); +update t1 set fk=69 where fk is null order by id limit 1; +SELECT * from t1; +drop table t1; + +create table t1 (a int not null, b int not null, key (a)); +insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3); +SET @tmp=0; +update t1 set b=(@tmp:=@tmp+1) order by a; +update t1 set b=99 where a=1 order by b asc limit 1; +update t1 set b=100 where a=1 order by b desc limit 2; +update t1 set a=a+10+b where a=1 order by b; +select * from t1 order by a,b; +drop table t1; + + CREATE TABLE t1 (col1 int(1))TYPE=InnoDB; CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP(+0),INDEX stamp_idx (stamp))TYPE=InnoDB; diff --git a/mysql-test/t/innodb_handler.test b/mysql-test/t/innodb_handler.test index 32c8741577c..cf6ac9870ce 100644 --- a/mysql-test/t/innodb_handler.test +++ b/mysql-test/t/innodb_handler.test @@ -75,5 +75,11 @@ alter table t1 type=innodb; --error 1109 handler t2 read first; -drop table if exists t1; +drop table t1; +CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY (no1,no2)) TYPE=InnoDB; +INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2); +HANDLER t1 OPEN; +HANDLER t1 READ `primary` = (1, 1000); +HANDLER t1 READ `primary` PREV; +DROP TABLE t1; diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test index 5fd96d6687c..882aec1006a 100644 --- a/mysql-test/t/join.test +++ b/mysql-test/t/join.test @@ -272,3 +272,49 @@ INSERT INTO t2 VALUES ('rivercats','cust',20); SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND lr.siteid = 'rivercats'; SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE lr.siteid = 'rivercats' AND emp.emp_id = 'psmith'; drop table t1,t2; + +# +# Problem with internal list handling when reducing WHERE +# + +CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, Value1 VARCHAR(255)); +CREATE TABLE t2 (ID INTEGER NOT NULL PRIMARY KEY, Value2 VARCHAR(255)); +INSERT INTO t1 VALUES (1, 'A'); +INSERT INTO t2 VALUES (1, 'B'); + +SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND (Value1 = 'A' AND Value2 <> 'B'); +SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND Value1 = 'A' AND Value2 <> 'B'; +SELECT * FROM t1 NATURAL JOIN t2 WHERE (Value1 = 'A' AND Value2 <> 'B') AND 1; +drop table t1,t2; + +# +# Test combination of join methods +# + +create table t1 (i int); +create table t2 (i int); +create table t3 (i int); +insert into t1 values(1),(2); +insert into t2 values(2),(3); +insert into t3 values (2),(4); + +select * from t1 natural left join t2; +select * from t1 left join t2 on (t1.i=t2.i); +select * from t1 natural left join t2 natural left join t3; +select * from t1 left join t2 on (t1.i=t2.i) left join t3 on (t2.i=t3.i); + +select * from t3 natural right join t2; +select * from t3 right join t2 on (t3.i=t2.i); +select * from t3 natural right join t2 natural right join t1; +select * from t3 right join t2 on (t3.i=t2.i) right join t1 on (t2.i=t1.i); + +select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i; +select * from t1,t2 left join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i; +select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i; +select t1.i,t2.i,t3.i from t2 left join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i; + +select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i; +select * from t1,t2 right join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i; +select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i; +select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i; +drop table t1,t2,t3; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index c57fb8273fe..df7e5b1524d 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -249,7 +249,7 @@ drop table t1,t2; create table t1 (id int not null, str char(10), index(str)); insert into t1 values (1, null), (2, null), (3, "foo"), (4, "bar"); -select * from t1 where str is not null; +select * from t1 where str is not null order by id; select * from t1 where str is null; drop table t1; @@ -417,3 +417,12 @@ explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; select * from t2 left join t1 ignore index(primary) on t1.fooID = t2.fooID and t1.fooID = 30; drop table t1,t2; + +create table t1 (i int); +create table t2 (i int); +create table t3 (i int); +insert into t1 values(1),(2); +insert into t2 values(2),(3); +insert into t3 values(2),(4); +select * from t1 natural left join t2 natural left join t3; +drop table t1,t2,t3; diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 4fd8cc86dd5..de97c639812 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -57,12 +57,12 @@ INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); drop table t1; # -# problem med primary key +# No longer a problem with primary key # CREATE TABLE t1 (program enum('signup','unique','sliding') not null, type enum('basic','sliding','signup'), sites set('mt'), PRIMARY KEY (program)); -# The following should give an error for wrong primary key -!$1171 ALTER TABLE t1 modify program enum('signup','unique','sliding'); +# This no longer give an error for wrong primary key +ALTER TABLE t1 modify program enum('signup','unique','sliding'); drop table t1; # diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test new file mode 100644 index 00000000000..d7e84590dc0 --- /dev/null +++ b/mysql-test/t/loaddata.test @@ -0,0 +1,13 @@ +# +# Some simple test of load data +# + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 (a date, b date, c date not null, d date); +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ','; +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; +SELECT * from t1; +drop table t1; diff --git a/mysql-test/t/multi_update-master.opt b/mysql-test/t/multi_update-master.opt new file mode 100644 index 00000000000..9f1a29461ff --- /dev/null +++ b/mysql-test/t/multi_update-master.opt @@ -0,0 +1 @@ +--set-variable=tmp_table_size=1024 diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index 390dd58d806..8e560cab455 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -255,8 +255,16 @@ update t1,t2 set t1.b=t1.b+10 where t1.b=2; select * from t1; # Range key (in t1) -update t1,t2 set t1.b=t1.b+2,t2.b=t1.b where t1.b between 3 and 5; +update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t2.a=t1.a-100; select * from t1; select * from t2; drop table t1,t2; +CREATE TABLE t3 ( KEY1 varchar(50) NOT NULL default '', PARAM_CORR_DISTANCE_RUSH double default NULL, PARAM_CORR_DISTANCE_GEM double default NULL, PARAM_AVG_TARE double default NULL, PARAM_AVG_NB_DAYS double default NULL, PARAM_DEFAULT_PROP_GEM_SRVC varchar(50) default NULL, PARAM_DEFAULT_PROP_GEM_NO_ETIK varchar(50) default NULL, PARAM_SCENARIO_COSTS varchar(50) default NULL, PARAM_DEFAULT_WAGON_COST double default NULL, tmp int(11) default NULL, PRIMARY KEY (KEY1)) TYPE=MyISAM; +INSERT INTO t3 VALUES ('A',1,1,22,3.2,'R','R','BASE2',0.24,NULL); +create table t1 (A varchar(1)); +insert into t1 values ("A") ,("B"),("C"),("D"); +create table t2(Z varchar(15)); +insert into t2(Z) select concat(a.a,b.a,c.a,d.a) from t1 as a, t1 as b, t1 as c, t1 as d; +update t2,t3 set Z =param_scenario_costs; +drop table t1,t2,t3; diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 8e1f304a5a5..702feedc3ce 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -334,9 +334,21 @@ SELECT titre,t1.numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,des drop table t1,t2; # -# Test of test_if_subkey() function +# Test order by with NULL values # +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1, 2); +INSERT INTO t1 VALUES (3, 4); +INSERT INTO t1 VALUES (5, NULL); +SELECT * FROM t1 ORDER BY b; +SELECT * FROM t1 ORDER BY b DESC; +SELECT * FROM t1 ORDER BY (a + b); +SELECT * FROM t1 ORDER BY (a + b) DESC; +DROP TABLE t1; +# +# Test of test_if_subkey() function +# CREATE TABLE t1 ( FieldKey varchar(36) NOT NULL default '', LongVal bigint(20) default NULL, @@ -345,7 +357,7 @@ CREATE TABLE t1 ( KEY LongField (FieldKey,LongVal), KEY StringField (FieldKey,StringVal(32)) ); -INSERT INTO t1 VALUES ('0',3,'0'),('0',2,'1'),('0',1,'2'),('1',2,'1'),('1',1,'3'), ('1',0,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('3',2,'1'),('3',1,'2'),('3','3','3'); +INSERT INTO t1 VALUES ('0',3,'0'),('0',2,'1'),('0',1,'2'),('1',2,'1'),('1',1,'3'), ('1',0,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('2',3,'0'),('2',2,'1'),('2',1,'2'),('3',2,'1'),('3',1,'2'),('3','3','3'); EXPLAIN SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal; SELECT * FROM t1 WHERE FieldKey = '1' ORDER BY LongVal; EXPLAIN SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY LongVal; diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index 56eda7fa104..1078d19533c 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -147,9 +147,10 @@ create table t1 (a int not null); insert into t1 values (1),(2),(3); select * from t1; show status like "Qcache_queries_in_cache"; -select sql_cache * from t1; +select sql_cache * from t1 union select * from t1; set query_cache_type=2; -select sql_cache * from t1; +select sql_cache * from t1 union select * from t1; +select * from t1 union select sql_cache * from t1; show status like "Qcache_hits"; show status like "Qcache_queries_in_cache"; set query_cache_type=on; @@ -429,7 +430,6 @@ select * from t1 where id=2; # # Load data invalidation test # - create table t1 (word char(20) not null); select * from t1; show status like "Qcache_queries_in_cache"; @@ -440,7 +440,6 @@ drop table t1; # # INTO OUTFILE/DUMPFILE test # - create table t1 (a int); insert into t1 values (1),(2),(3); show status like "Qcache_queries_in_cache"; @@ -448,3 +447,16 @@ select * from t1 into outfile "query_caceh.out.file"; select * from t1 limit 1 into dumpfile "query_cache.dump.file"; show status like "Qcache_queries_in_cache"; drop table t1; + +# +# test of SQL_SELECT_LIMIT +# +create table t1 (a int); +insert into t1 values (1),(2); +show status like "Qcache_queries_in_cache"; +select * from t1; +SET OPTION SQL_SELECT_LIMIT=1; +select * from t1; +show status like "Qcache_queries_in_cache"; +SET OPTION SQL_SELECT_LIMIT=DEFAULT; +drop table t1; diff --git a/mysql-test/t/raid.test b/mysql-test/t/raid.test index 38c740201bc..235add63c22 100644 --- a/mysql-test/t/raid.test +++ b/mysql-test/t/raid.test @@ -9,6 +9,14 @@ show variables like "have_raid"; DROP TABLE IF EXISTS t1,t2; --enable_warnings +# +# Test dropping database with raid tables +# + +create database test_$1; +create table test_$1.r1 (i int) raid_type=1; +drop database test_$1; + CREATE TABLE t1 ( id int unsigned not null auto_increment primary key, c char(255) not null diff --git a/mysql-test/t/repair.test b/mysql-test/t/repair.test index bdc5a57a07c..2657f91cd02 100644 --- a/mysql-test/t/repair.test +++ b/mysql-test/t/repair.test @@ -8,4 +8,15 @@ drop table if exists t1; create table t1 SELECT 1,"table 1"; repair table t1 use_frm; -drop table if exists t1; +alter table t1 TYPE=HEAP; +repair table t1 use_frm; +drop table t1; + +# non-existent table +repair table t1 use_frm; + +# +# Create test table for repair2 +# The following must be last in this file + +create table t1 type=myisam SELECT 1,"table 1"; diff --git a/mysql-test/t/repair_part2-master.sh b/mysql-test/t/repair_part2-master.sh new file mode 100644 index 00000000000..964bde06c18 --- /dev/null +++ b/mysql-test/t/repair_part2-master.sh @@ -0,0 +1 @@ +echo "1" > $MYSQL_TEST_DIR/var/master-data/test/t1.MYI diff --git a/mysql-test/t/repair_part2.test b/mysql-test/t/repair_part2.test new file mode 100644 index 00000000000..8c27e382dff --- /dev/null +++ b/mysql-test/t/repair_part2.test @@ -0,0 +1,7 @@ +# +# This test starts with a crashed t1.MYI file left over from repair.test +# + +repair table t1; +repair table t1 use_frm; +drop table t1; diff --git a/mysql-test/t/rpl_flush_tables.test b/mysql-test/t/rpl_flush_tables.test index 88a80911d89..67720343e83 100644 --- a/mysql-test/t/rpl_flush_tables.test +++ b/mysql-test/t/rpl_flush_tables.test @@ -5,7 +5,6 @@ # source include/master-slave.inc; -let $VERSION=`select version()`; create table t1 (a int); insert into t1 values (10); create table t2 (a int); @@ -18,14 +17,14 @@ rename table t1 to t5, t2 to t1; # first don't write it to the binlog, to test the NO_WRITE_TO_BINLOG keyword. flush no_write_to_binlog tables; # Check that it's not in the binlog. ---replace_result $VERSION VERSION +--replace_result $SERVER_VERSION SERVER_VERSION show binlog events; # Check that the master is not confused. select * from t3; # This FLUSH should go into the binlog to not confuse the slave. flush tables; # Check that it's in the binlog. ---replace_result $VERSION VERSION +--replace_result $SERVER_VERSION SERVER_VERSION show binlog events; save_master_pos; connection slave; diff --git a/mysql-test/t/rpl_relayrotate.test b/mysql-test/t/rpl_relayrotate.test index 4c330b8c9a2..09cf7cbb741 100644 --- a/mysql-test/t/rpl_relayrotate.test +++ b/mysql-test/t/rpl_relayrotate.test @@ -56,6 +56,14 @@ start slave; # Detect this with timeout. select master_pos_wait('master-bin.001',3000,120)=-1; select * from t1 where a=8000; -# Note that the simple fact to have less than around 30 slave's binlogs -# (the slave is started with --log-slave-updates) is already -# a proof that the transaction was not properly resumed. + +# The following DROP is a very important cleaning task: +# imagine the next test is run with --skip-innodb: it will do +# DROP TABLE IF EXISTS t1; but this will delete the frm and leave +# some data in the InnoDB datafile (because at that time mysqld +# does not know about InnoDB : --skip-innodb). So if later in the +# test suite a test wants to create an InnoDB table called t1, it +# will fail with +# InnoDB: Error: table t1 already exists in InnoDB internal +# InnoDB: data dictionary. Have you deleted the .frm file etc +drop table t1; diff --git a/mysql-test/t/select_safe.test b/mysql-test/t/select_safe.test index cd8bce6369c..be25c7c05d1 100644 --- a/mysql-test/t/select_safe.test +++ b/mysql-test/t/select_safe.test @@ -7,7 +7,7 @@ drop table if exists t1; --enable_warnings SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=4, SQL_MAX_JOIN_SIZE=9; -create table t1 (a int primary key, b char(20)); +create table t1 (a int auto_increment primary key, b char(20)); insert into t1 values(1,"test"); SELECT SQL_BUFFER_RESULT * from t1; update t1 set b="a" where a=1; @@ -18,18 +18,40 @@ update t1 set b="a" where a=1; select 1 from t1,t1 as t2,t1 as t3,t1 as t4; # The following should give errors: -!$1175 update t1 set b="a"; -!$1175 update t1 set b="a" where b="test"; -!$1175 delete from t1; -!$1175 delete from t1 where b="test"; -!$1175 delete from t1 where a+0=1; -!$1104 select 1 from t1,t1 as t2,t1 as t3,t1 as t4,t1 as t5; +--error 1175 +update t1 set b="a"; +--error 1175 +update t1 set b="a" where b="test"; +--error 1175 +delete from t1; +--error 1175 +delete from t1 where b="test"; +--error 1175 +delete from t1 where a+0=1; +--error 1104 +select 1 from t1,t1 as t2,t1 as t3,t1 as t4,t1 as t5; # The following should be ok: update t1 set b="a" limit 1; update t1 set b="a" where b="b" limit 2; delete from t1 where b="test" limit 1; delete from t1 where a+0=1 limit 2; + +# Test SQL_BIG_SELECTS + +SET MAX_JOIN_SIZE=2; +SELECT @@MAX_JOIN_SIZE, @@SQL_BIG_SELECTS; +insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"); +--error 1104 +SELECT * from t1; +SET SQL_BIG_SELECTS=1; +SELECT * from t1; +SET MAX_JOIN_SIZE=2; +--error 1104 +SELECT * from t1; +SET MAX_JOIN_SIZE=DEFAULT; +SELECT * from t1; + drop table t1; SET SQL_SAFE_UPDATES=0,SQL_SELECT_LIMIT=DEFAULT, SQL_MAX_JOIN_SIZE=DEFAULT; diff --git a/mysql-test/t/status.test b/mysql-test/t/status.test index 90d7f814359..30edcc79d9e 100644 --- a/mysql-test/t/status.test +++ b/mysql-test/t/status.test @@ -4,7 +4,7 @@ # This would work if mysqltest run would be threaded and handle each # connection in a separate thread. # --- source include/not_embedded.inc +--source include/not_embedded.inc connect (con1,localhost,root,,); connect (con2,localhost,root,,); diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 8e8a3dfe1d4..e47409046cd 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -351,7 +351,7 @@ INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2; select * from t1; -- error 1093 INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2; -INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2)); +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); -- sleep 1 select * from t1; drop table t1, t2, t3; @@ -396,6 +396,8 @@ SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3); SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2); -- error 1093 INSERT INTO t2 VALUES ((SELECT * FROM t2)); +-- error 1093 +INSERT INTO t2 VALUES ((SELECT id FROM t2)); SELECT * FROM t2; CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) TYPE=MyISAM CHARSET=latin1; INSERT INTO t1 values (1),(1); @@ -714,3 +716,17 @@ create table t1 (id int not null auto_increment primary key, salary int, key(sal insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000); explain SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1); drop table t1; + +CREATE TABLE t1 ( + ID int(10) unsigned NOT NULL auto_increment, + SUB_ID int(3) unsigned NOT NULL default '0', + REF_ID int(10) unsigned default NULL, + REF_SUB int(3) unsigned default '0', + PRIMARY KEY (ID,SUB_ID), + UNIQUE KEY t1_PK (ID,SUB_ID), + KEY t1_FK (REF_ID,REF_SUB), + KEY t1_REFID (REF_ID) +) TYPE=MyISAM CHARSET=cp1251; +INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); +SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); +DROP TABLE t1; diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test index 053d0517904..8653c06a644 100644 --- a/mysql-test/t/type_decimal.test +++ b/mysql-test/t/type_decimal.test @@ -233,3 +233,13 @@ insert into t1 values("1e4294967297"); select * from t1; drop table t1; +# +# Test of wrong decimal type +# + +--error 1074 +CREATE TABLE t1 (a_dec DECIMAL(-1,0)); +--error 1074 +CREATE TABLE t1 (a_dec DECIMAL(-2,1)); +--error 1074 +CREATE TABLE t1 (a_dec DECIMAL(-1,1)); diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index 70e770cd2d3..6d857a4b40f 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1,t2,t3; +drop table if exists t1,t2,t3,t4,t5,t6; --enable_warnings CREATE TABLE t1 (a int not null, b char (10) not null); @@ -19,7 +19,7 @@ select 0,'#' union select a,b from t1 union all select a,b from t2 union select select a,b from t1 union select a,b from t1; select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 group by b; -#test alternate syntax for unions +# Test alternate syntax for unions (select a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 4; (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1); (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; @@ -27,7 +27,7 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b; explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; #(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; -select found_rows(); +#select found_rows(); # # Test some error conditions with UNION @@ -73,6 +73,19 @@ replace into t3 select a,b as c from t1 union all select a,b from t2; drop table t1,t2,t3; # +# Test some unions without tables +# +--error 1096 +select * union select 1; +select 1 as a,(select a union select a); +--error 1054 +(select 1) union (select 2) order by 0; +SELECT @a:=1 UNION SELECT @a:=@a+1; +--error 1054 +(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a); +(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2); + +# # Test bug reported by joc@presence-pc.com # @@ -104,12 +117,67 @@ set SQL_SELECT_LIMIT=2; set SQL_SELECT_LIMIT=DEFAULT; drop table t1,t2; ---error 1096 -select * union select 1; -select 1 as a,(select a union select a); ---disable_warnings -drop table if exists t1,t2; ---enable_warnings +# +# Test error with left join +# + +CREATE TABLE t1 ( + cid smallint(5) unsigned NOT NULL default '0', + cv varchar(250) NOT NULL default '', + PRIMARY KEY (cid), + UNIQUE KEY cv (cv) +) ; +INSERT INTO t1 VALUES (8,'dummy'); +CREATE TABLE t2 ( + cid bigint(20) unsigned NOT NULL auto_increment, + cap varchar(255) NOT NULL default '', + PRIMARY KEY (cid), + KEY cap (cap) +) ; +CREATE TABLE t3 ( + gid bigint(20) unsigned NOT NULL auto_increment, + gn varchar(255) NOT NULL default '', + must tinyint(4) default NULL, + PRIMARY KEY (gid), + KEY gn (gn) +) ; +INSERT INTO t3 VALUES (1,'V1',NULL); +CREATE TABLE t4 ( + uid bigint(20) unsigned NOT NULL default '0', + gid bigint(20) unsigned default NULL, + rid bigint(20) unsigned default NULL, + cid bigint(20) unsigned default NULL, + UNIQUE KEY m (uid,gid,rid,cid), + KEY uid (uid), + KEY rid (rid), + KEY cid (cid), + KEY container (gid,rid,cid) +) ; +INSERT INTO t4 VALUES (1,1,NULL,NULL); +CREATE TABLE t5 ( + rid bigint(20) unsigned NOT NULL auto_increment, + rl varchar(255) NOT NULL default '', + PRIMARY KEY (rid), + KEY rl (rl) +) ; +CREATE TABLE t6 ( + uid bigint(20) unsigned NOT NULL auto_increment, + un varchar(250) NOT NULL default '', + uc smallint(5) unsigned NOT NULL default '0', + PRIMARY KEY (uid), + UNIQUE KEY nc (un,uc), + KEY un (un) +) ; +INSERT INTO t6 VALUES (1,'test',8); + +SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test"; +SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test"; +(SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test") UNION (SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test"); +drop table t1,t2,t3,t4,t5,t6; + +# +# Test for another bug with UNION and LEFT JOIN +# CREATE TABLE t1 ( id int(3) unsigned default '0') TYPE=MyISAM; INSERT INTO t1 (id) VALUES("1"); CREATE TABLE t2 ( id int(3) unsigned default '0', id_master int(5) default '0', text1 varchar(5) default NULL, text2 varchar(5) default NULL) TYPE=MyISAM; @@ -124,7 +192,6 @@ INSERT INTO t2 (id, id_master, text1, text2) VALUES("4", "1", SELECT 1 AS id_master, 1 AS id, NULL AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master; SELECT 1 AS id_master, 1 AS id, 'ABCDE' AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master; drop table if exists t1,t2; -(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2); # # Test of bug when using the same table multiple times @@ -142,9 +209,3 @@ explain (select * from t1 where a=1) union (select * from t2 where a=1); explain (select * from t1 where a=1 and b=10) union (select t1.a,t2.a from t1,t2 where t1.a=t2.a); explain (select * from t1 where a=1) union (select * from t1 where b=1); drop table t1,t2; ---error 1054 -(select 1) union (select 2) order by 0; - -SELECT @a:=1 UNION SELECT @a:=@a+1; ---error 1054 -(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a); diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test index 6a7eac41a96..485af981fb4 100644 --- a/mysql-test/t/update.test +++ b/mysql-test/t/update.test @@ -84,12 +84,48 @@ drop table t1; # Test of ORDER BY # -create table t1 (a int not null, b int not null); -insert into t1 values (1,1),(1,2),(1,3); -update t1 set b=4 where a=1 order by b asc limit 1; -update t1 set b=4 where a=1 order by b desc limit 1; +create table t1 (a int not null, b int not null, key (a)); +insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3); +SET @tmp=0; +update t1 set b=(@tmp:=@tmp+1) order by a; +update t1 set b=99 where a=1 order by b asc limit 1; +select * from t1 order by a,b; +update t1 set b=100 where a=1 order by b desc limit 2; +update t1 set a=a+10+b where a=1 order by b; +select * from t1 order by a,b; create table t2 (a int not null, b int not null); insert into t2 values (1,1),(1,2),(1,3); -select * from t1; update t1 set b=(select distinct 1 from (select * from t2) a); drop table t1,t2; + +# +# Test with limit (Bug #393) +# + +CREATE TABLE t1 ( + `id_param` smallint(3) unsigned NOT NULL default '0', + `nom_option` char(40) NOT NULL default '', + `valid` tinyint(1) NOT NULL default '0', + KEY `id_param` (`id_param`,`nom_option`) + ) TYPE=MyISAM; + +INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1); + +UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1; +select * from t1; +drop table t1; + +# +# Multi table update test from bugs +# + +create table t1 (F1 VARCHAR(30), F2 VARCHAR(30), F3 VARCHAR(30), cnt int, groupid int, KEY groupid_index (groupid)); + +insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6), +('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2), +('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4), +('2','2','0',1,7); + +delete from t1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3); +select * from t1; +drop table t1; diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index d1c8df64be2..7d4b25df0eb 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -72,10 +72,10 @@ show local variables like 'table_type'; show global variables like 'table_type'; set GLOBAL query_cache_size=100000; -set myisam_max_sort_file_size=10000, GLOBAL myisam_max_sort_file_size=20000; -show variables like 'myisam_max_sort_file_size'; +set GLOBAL myisam_max_sort_file_size=2000000; show global variables like 'myisam_max_sort_file_size'; -set myisam_max_sort_file_size=default; +set GLOBAL myisam_max_sort_file_size=default; +--replace_result 2147483647 FILE_SIZE 9223372036854775807 FILE_SIZE show variables like 'myisam_max_sort_file_size'; set global net_retry_count=10, session net_retry_count=10; @@ -92,7 +92,7 @@ set net_buffer_length=2000000000; show variables like 'net_buffer_length'; set character set cp1251_koi8; -show variables like "collation_client"; +show variables like "character_set_client"; select @@timestamp>0; set @@rand_seed1=10000000,@@rand_seed2=1000000; @@ -119,7 +119,7 @@ set SESSION query_cache_size=10000; --error 1230 set GLOBAL table_type=DEFAULT; --error 1115 -set collation_client=UNKNOWN_CHARACTER_SET; +set character_set_client=UNKNOWN_CHARACTER_SET; --error 1228 set global autocommit=1; --error 1228 @@ -132,6 +132,10 @@ set @@concurrent_insert=1; set @@global.sql_auto_is_null=1; --error 1228 select @@global.sql_auto_is_null; +--error 1229 +set myisam_max_sort_file_size=100; +--error 1229 +set myisam_max_extra_sort_file_size=100; # Test setting all variables @@ -176,9 +180,9 @@ set max_tmp_tables=100; set global max_user_connections=100; select @@max_user_connections; set global max_write_lock_count=100; -set myisam_max_extra_sort_file_size=100; +set global myisam_max_extra_sort_file_size=100; select @@myisam_max_extra_sort_file_size; -set myisam_max_sort_file_size=100; +set global myisam_max_sort_file_size=100; set myisam_sort_buffer_size=100; set net_buffer_length=100; set net_read_timeout=100; @@ -236,3 +240,10 @@ check table t1,t2; select max(a) +1, max(a) +2 into @xx,@yy from t1; drop table t1,t2; +# +# error conditions +# + +--error 1193 +select @@xxxxxxxxxx; +select 1; diff --git a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test index ab8c0b99ca5..6374fbf83ac 100644 --- a/mysql-test/t/warnings.test +++ b/mysql-test/t/warnings.test @@ -2,7 +2,7 @@ # Test some warnings # --disable-warnings -drop table if exists t1; +drop table if exists t1, t2; --enable-warnings create table t1 (a int); @@ -17,6 +17,7 @@ set SQL_WARNINGS=0; # # Test other warnings +# drop temporary table if exists not_exists; drop table if exists not_exists_table; @@ -28,6 +29,52 @@ create table if not exists t1(id int); select @@warning_count; drop table t1; +# +# Test warnings for LOAD DATA INFILE +# + +create table t1(a tinyint, b int not null, c date, d char(5)); +load data infile '../../std_data/warnings_loaddata.dat' into table t1 fields terminated by ','; +select @@warning_count; +drop table t1; + +# +# Warnings from basic INSERT, UPDATE and ALTER commands +# + +create table t1(a tinyint NOT NULL, b tinyint unsigned, c char(5)); +insert into t1 values(NULL,100,'mysql'),(10,-1,'mysql ab'),(500,256,'open source'),(20,NULL,'test'); +alter table t1 modify c char(4); +alter table t1 add d char(2); +update t1 set a=NULL where a=10; +update t1 set c='mysql ab' where c='test'; +update t1 set d=c; +create table t2(a tinyint NOT NULL, b char(3)); +insert into t2 select b,c from t1; +drop table t1, t2; + +# +# Test for max_error_count +# + +create table t1(a char(10)); +let $1=50; +disable_query_log; +while ($1) +{ + eval insert into t1 values('mysql ab'); + dec $1; +} +enable_query_log; +alter table t1 add b char; +set max_error_count=10; +update t1 set b=a; +select @@warning_count; + +# +# Test for handler type +# +drop table t1; create table t1 (id int) type=isam; alter table t1 type=isam; drop table t1; diff --git a/mysys/charset.c b/mysys/charset.c index 097c35caa56..ad0468a5087 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -120,45 +120,15 @@ static void simple_cs_init_functions(CHARSET_INFO *cs) if (cs->state & MY_CS_BINSORT) { - CHARSET_INFO *b= &my_charset_bin; - cs->strnxfrm = b->strnxfrm; - cs->like_range = b->like_range; - cs->wildcmp = b->wildcmp; - cs->strnncoll = b->strnncoll; - cs->strnncollsp = b->strnncollsp; - cs->strcasecmp = b->strcasecmp; - cs->hash_sort = b->hash_sort; + cs->coll= &my_collation_bin_handler; } else { - cs->strnxfrm = my_strnxfrm_simple; - cs->like_range = my_like_range_simple; - cs->wildcmp = my_wildcmp_8bit; - cs->strnncoll = my_strnncoll_simple; - cs->strnncollsp = my_strnncollsp_simple; - cs->strcasecmp = my_strcasecmp_8bit; - cs->hash_sort = my_hash_sort_simple; + cs->coll= &my_collation_8bit_simple_ci_handler; } - cs->caseup_str = my_caseup_str_8bit; - cs->casedn_str = my_casedn_str_8bit; - cs->caseup = my_caseup_8bit; - cs->casedn = my_casedn_8bit; - cs->mb_wc = my_mb_wc_8bit; - cs->wc_mb = my_wc_mb_8bit; - cs->snprintf = my_snprintf_8bit; - cs->long10_to_str= my_long10_to_str_8bit; - cs->longlong10_to_str= my_longlong10_to_str_8bit; - cs->fill = my_fill_8bit; - cs->strntol = my_strntol_8bit; - cs->strntoul = my_strntoul_8bit; - cs->strntoll = my_strntoll_8bit; - cs->strntoull = my_strntoull_8bit; - cs->strntod = my_strntod_8bit; - cs->scan = my_scan_8bit; + cs->cset= &my_charset_8bit_handler; cs->mbmaxlen = 1; - cs->numchars = my_numchars_8bit; - cs->charpos = my_charpos_8bit; } @@ -313,6 +283,8 @@ static int add_collation(CHARSET_INFO *cs) { if (!all_charsets[cs->number]) { + if (cs->state & MY_CS_COMPILED) + goto clear; if (!(all_charsets[cs->number]= (CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),MYF(0)))) return MY_XML_ERROR; @@ -327,10 +299,10 @@ static int add_collation(CHARSET_INFO *cs) if (!(all_charsets[cs->number]->state & MY_CS_COMPILED)) { + simple_cs_init_functions(all_charsets[cs->number]); simple_cs_copy_data(all_charsets[cs->number],cs); if (simple_cs_is_full(all_charsets[cs->number])) { - simple_cs_init_functions(all_charsets[cs->number]); all_charsets[cs->number]->state |= MY_CS_LOADED; } } @@ -341,6 +313,7 @@ static int add_collation(CHARSET_INFO *cs) if (cs->comment) dst->comment= my_once_strdup(cs->comment,MYF(MY_WME)); } +clear: cs->number= 0; cs->primary_number= 0; cs->binary_number= 0; @@ -423,56 +396,63 @@ static my_bool init_compiled_charsets(myf flags __attribute__((unused))) { CHARSET_INFO *cs; - MY_ADD_CHARSET(&my_charset_latin1); - MY_ADD_CHARSET(&my_charset_bin); + + MY_ADD_CHARSET(&my_charset_latin1); + MY_ADD_CHARSET(&my_charset_latin1_bin); + MY_ADD_CHARSET(&my_charset_latin1_german2_ci); #ifdef HAVE_CHARSET_big5 - MY_ADD_CHARSET(&my_charset_big5); + MY_ADD_CHARSET(&my_charset_big5_chinese_ci); + MY_ADD_CHARSET(&my_charset_big5_bin); #endif -#ifdef HAVE_CHARSET_czech - MY_ADD_CHARSET(&my_charset_czech); +#ifdef HAVE_CHARSET_cp1250 + MY_ADD_CHARSET(&my_charset_cp1250_czech_ci); #endif -#ifdef HAVE_CHARSET_euc_kr - MY_ADD_CHARSET(&my_charset_euc_kr); +#ifdef HAVE_CHARSET_latin2 + MY_ADD_CHARSET(&my_charset_latin2_czech_ci); #endif -#ifdef HAVE_CHARSET_gb2312 - MY_ADD_CHARSET(&my_charset_gb2312); +#ifdef HAVE_CHARSET_euckr + MY_ADD_CHARSET(&my_charset_euckr_korean_ci); + MY_ADD_CHARSET(&my_charset_euckr_bin); #endif -#ifdef HAVE_CHARSET_gbk - MY_ADD_CHARSET(&my_charset_gbk); +#ifdef HAVE_CHARSET_gb2312 + MY_ADD_CHARSET(&my_charset_gb2312_chinese_ci); + MY_ADD_CHARSET(&my_charset_gb2312_bin); #endif -#ifdef HAVE_CHARSET_latin1_de - MY_ADD_CHARSET(&my_charset_latin1_de); +#ifdef HAVE_CHARSET_gbk + MY_ADD_CHARSET(&my_charset_gbk_chinese_ci); + MY_ADD_CHARSET(&my_charset_gbk_bin); #endif #ifdef HAVE_CHARSET_sjis - MY_ADD_CHARSET(&my_charset_sjis); + MY_ADD_CHARSET(&my_charset_sjis_japanese_ci); + MY_ADD_CHARSET(&my_charset_sjis_bin); #endif #ifdef HAVE_CHARSET_tis620 - MY_ADD_CHARSET(&my_charset_tis620); + MY_ADD_CHARSET(&my_charset_tis620_thai_ci); + MY_ADD_CHARSET(&my_charset_tis620_bin); #endif #ifdef HAVE_CHARSET_ucs2 - MY_ADD_CHARSET(&my_charset_ucs2); + MY_ADD_CHARSET(&my_charset_ucs2_general_ci); + MY_ADD_CHARSET(&my_charset_ucs2_bin); #endif #ifdef HAVE_CHARSET_ujis - MY_ADD_CHARSET(&my_charset_ujis); + MY_ADD_CHARSET(&my_charset_ujis_japanese_ci); + MY_ADD_CHARSET(&my_charset_ujis_bin); #endif #ifdef HAVE_CHARSET_utf8 - MY_ADD_CHARSET(&my_charset_utf8); -#endif - -#ifdef HAVE_CHARSET_win1250ch - MY_ADD_CHARSET(&my_charset_win1250ch); + MY_ADD_CHARSET(&my_charset_utf8_general_ci); + MY_ADD_CHARSET(&my_charset_utf8_bin); #endif /* Copy compiled charsets */ @@ -533,12 +513,6 @@ void free_charsets(void) } -static void get_charset_conf_name(const char *cs_name, char *buf) -{ - strxmov(get_charsets_dir(buf), cs_name, ".conf", NullS); -} - - uint get_charset_number(const char *charset_name) { CHARSET_INFO **cs; @@ -548,9 +522,7 @@ uint get_charset_number(const char *charset_name) for (cs= all_charsets; cs < all_charsets+255; ++cs) { if ( cs[0] && cs[0]->name && - (!my_strcasecmp(&my_charset_latin1, cs[0]->name, charset_name) || - (!my_strcasecmp(&my_charset_latin1, cs[0]->csname, charset_name) && - (cs[0]->state & MY_CS_PRIMARY)))) + !my_strcasecmp(&my_charset_latin1, cs[0]->name, charset_name)) return cs[0]->number; } return 0; /* this mimics find_type() */ @@ -663,95 +635,3 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name, return cs; } - - -/* Only append name if it doesn't exist from before */ - -static my_bool charset_in_string(const char *name, DYNAMIC_STRING *s) -{ - uint length= (uint) strlen(name); - const char *pos; - for (pos=s->str ; (pos=strstr(pos,name)) ; pos++) - { - if (! pos[length] || pos[length] == ' ') - return TRUE; /* Already existed */ - } - return FALSE; -} - - -static void charset_append(DYNAMIC_STRING *s, const char *name) -{ - if (!charset_in_string(name, s)) - { - dynstr_append(s, name); - dynstr_append(s, " "); - } -} - - -/* Returns a dynamically-allocated string listing the character sets - requested. The caller is responsible for freeing the memory. */ - -char *list_charsets(myf want_flags) -{ - DYNAMIC_STRING s; - char *p; - - (void)init_available_charsets(MYF(0)); - init_dynamic_string(&s, NullS, 256, 1024); - - if (want_flags & MY_CS_COMPILED) - { - CHARSET_INFO **cs; - for (cs= all_charsets; cs < all_charsets+255; cs++) - { - if (cs[0]) - { - dynstr_append(&s, cs[0]->name); - dynstr_append(&s, " "); - } - } - } - - if (want_flags & MY_CS_CONFIG) - { - CHARSET_INFO **cs; - char buf[FN_REFLEN]; - MY_STAT status; - - for (cs=all_charsets; cs < all_charsets+255; cs++) - { - if (!cs[0] || !cs[0]->name || charset_in_string(cs[0]->name, &s)) - continue; - get_charset_conf_name(cs[0]->name, buf); - if (!my_stat(buf, &status, MYF(0))) - continue; /* conf file doesn't exist */ - dynstr_append(&s, cs[0]->name); - dynstr_append(&s, " "); - } - } - - if (want_flags & (MY_CS_INDEX|MY_CS_LOADED)) - { - CHARSET_INFO **cs; - for (cs= all_charsets; cs < all_charsets + 255; cs++) - if (cs[0] && cs[0]->name && (cs[0]->state & want_flags) ) - charset_append(&s, cs[0]->name); - } - - if (s.length) - { - s.str[s.length - 1]= '\0'; /* chop trailing space */ - p= my_strdup(s.str, MYF(MY_WME)); - } - else - { - p= my_strdup("", MYF(MY_WME)); - } - dynstr_free(&s); - - return p; -} - - diff --git a/mysys/default.c b/mysys/default.c index 9fedfd795a5..bbf429eb920 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -174,8 +174,6 @@ void load_defaults(const char *conf_file, const char **groups, res= (char**) (ptr+sizeof(alloc)); /* copy name + found arguments + command line arguments to new array */ - res[0]=*argc ? argv[0][0] : ""; - memcpy((gptr) (res+1), args.buffer, args.elements*sizeof(char*)); /* Skipp --defaults-file and --defaults-extra-file */ (*argc)-= args_used; @@ -251,7 +249,13 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, MY_STAT stat_info; if (!my_stat(name,&stat_info,MYF(0))) return 0; - if (stat_info.st_mode & S_IWOTH) /* ignore world-writeable files */ + /* + Ignore world-writable regular files. + This is mainly done to protect us to not read a file created by + the mysqld server, but the check is still valid in most context. + */ + if ((stat_info.st_mode & S_IWOTH) && + (stat_info.st_mode & S_IFMT) == S_IFREG) { fprintf(stderr, "warning: World-writeable config file %s is ignored\n", name); diff --git a/mysys/hash.c b/mysys/hash.c index 9169613c39f..0b2dbc484bc 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -36,7 +36,7 @@ static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length); static uint calc_hash(HASH *hash,const byte *key,uint length) { ulong nr1=1, nr2=4; - hash->charset->hash_sort(hash->charset,key,length,&nr1,&nr2); + hash->charset->coll->hash_sort(hash->charset,key,length,&nr1,&nr2); return nr1; } diff --git a/mysys/mf_path.c b/mysys/mf_path.c index 23eadd2acce..1ecd5fbb2b1 100644 --- a/mysys/mf_path.c +++ b/mysys/mf_path.c @@ -77,6 +77,9 @@ my_string my_path(my_string to, const char *progname, #define F_OK 0 #define PATH_SEP ';' #define PROGRAM_EXTENSION ".exe" +#elif defined(__NETWARE__) +#define PATH_SEP ';' +#define PROGRAM_EXTENSION ".nlm" #else #define PATH_SEP ':' #endif diff --git a/mysys/my_bit.c b/mysys/my_bit.c index 0ff487afe03..55dd72f5f76 100644 --- a/mysys/my_bit.c +++ b/mysys/my_bit.c @@ -29,3 +29,45 @@ uint my_bit_log2(ulong value) for (bit=0 ; value > 1 ; value>>=1, bit++) ; return bit; } + +static char nbits[256] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; + +uint my_count_bits(ulonglong v) +{ +#if SIZEOF_LONG_LONG > 4 + /* The following code is a bit faster on 16 bit machines than if we would + only shift v */ + ulong v2=(ulong) (v >> 32); + return (uint) (uchar) (nbits[(uchar) v] + + nbits[(uchar) (v >> 8)] + + nbits[(uchar) (v >> 16)] + + nbits[(uchar) (v >> 24)] + + nbits[(uchar) (v2)] + + nbits[(uchar) (v2 >> 8)] + + nbits[(uchar) (v2 >> 16)] + + nbits[(uchar) (v2 >> 24)]); +#else + return (uint) (uchar) (nbits[(uchar) v] + + nbits[(uchar) (v >> 8)] + + nbits[(uchar) (v >> 16)] + + nbits[(uchar) (v >> 24)]); +#endif +} + diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index 1eb15d92bc9..4f472f61593 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -90,6 +90,29 @@ void *my_pthread_getspecific_imp(pthread_key_t key) } #endif +#ifdef __NETWARE__ +/* +don't kill the LibC Reaper thread or the main thread +*/ +#include <nks/thread.h> +#undef pthread_exit +void my_pthread_exit(void *status) +{ + NXThreadId_t tid = NXThreadGetId(); + NXContext_t ctx; + char name[PATH_MAX] = ""; + + NXThreadGetContext(tid, &ctx); + NXContextGetName(ctx, name, PATH_MAX); + + // "MYSQLD.NLM's LibC Reaper" or "MYSQLD.NLM's main thread" + // with a debug build of LibC the reaper can have different names + if (!strindex(name, "\'s")) + { + pthread_exit(status); + } +} +#endif /* Some functions for RTS threads, AIX, Siemens Unix and UnixWare 7 (and DEC OSF/1 3.2 too) */ diff --git a/mysys/my_seek.c b/mysys/my_seek.c index 177a5cee953..ec24a26b3d9 100644 --- a/mysys/my_seek.c +++ b/mysys/my_seek.c @@ -15,6 +15,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mysys_priv.h" +#include <assert.h> /* Seek to position in file */ /*ARGSUSED*/ @@ -27,6 +28,8 @@ my_off_t my_seek(File fd, my_off_t pos, int whence, DBUG_PRINT("my",("Fd: %d Hpos: %lu Pos: %lu Whence: %d MyFlags: %d", fd, (ulong) (((ulonglong) pos) >> 32), (ulong) pos, whence, MyFlags)); + DBUG_ASSERT(pos != MY_FILEPOS_ERROR); /* safety check */ + newpos=lseek(fd, pos, whence); if (newpos == (os_off_t) -1) { diff --git a/mysys/my_semaphore.c b/mysys/my_semaphore.c index 2dd224cd99e..aa216cbc289 100644 --- a/mysys/my_semaphore.c +++ b/mysys/my_semaphore.c @@ -23,7 +23,7 @@ #include <my_semaphore.h> #include <errno.h> -#if !defined(__WIN__) && !defined(HAVE_SEMAPHORE_H) +#if !defined(__WIN__) && !defined(HAVE_SEMAPHORE_H) && defined(THREAD) int sem_init(sem_t * sem, int pshared, uint value) { @@ -101,4 +101,4 @@ int sem_getvalue(sem_t * sem, uint *sval) return 0; } -#endif /* !defined(__WIN__) && !defined(HAVE_SEMAPHORE_H) */ +#endif /* !defined(__WIN__) && !defined(HAVE_SEMAPHORE_H) && defined(THREAD) */ diff --git a/mysys/raid.cc b/mysys/raid.cc index d6359dc0f93..0b688464fb3 100644 --- a/mysys/raid.cc +++ b/mysys/raid.cc @@ -157,10 +157,10 @@ extern "C" { DBUG_PRINT("enter",("Fd: %d pos: %lu whence: %d MyFlags: %d", fd, (ulong) pos, whence, MyFlags)); - assert(pos != MY_FILEPOS_ERROR); - if (is_raid(fd)) { + assert(pos != MY_FILEPOS_ERROR); + RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); DBUG_RETURN(raid->Seek(pos,whence,MyFlags)); } diff --git a/netware/BUILD/compile-AUTOTOOLS b/netware/BUILD/compile-AUTOTOOLS index 0688ea5aaca..57213b1b3d0 100755 --- a/netware/BUILD/compile-AUTOTOOLS +++ b/netware/BUILD/compile-AUTOTOOLS @@ -1,5 +1,11 @@ #! /bin/sh +# debug +#set -x + +# stop on errors +set -e + for package in . ./innobase do (cd $package diff --git a/netware/BUILD/compile-linux-tools b/netware/BUILD/compile-linux-tools index 598be96ab66..3590a900338 100755 --- a/netware/BUILD/compile-linux-tools +++ b/netware/BUILD/compile-linux-tools @@ -1,8 +1,11 @@ #! /bin/sh -#debug +# debug #set -x +# stop on errors +set -e + if test ! -r ./sql/mysqld.cc then echo "you must start from the top source directory" diff --git a/netware/BUILD/compile-netware-END b/netware/BUILD/compile-netware-END index beb15fbeda3..e0097484500 100755 --- a/netware/BUILD/compile-netware-END +++ b/netware/BUILD/compile-netware-END @@ -1,5 +1,11 @@ #! /bin/sh +# debug +#set -x + +# stop on errors +set -e + path=`dirname $0` # clean diff --git a/netware/BUILD/compile-netware-START b/netware/BUILD/compile-netware-START index 2941d8868e4..7eef192a907 100755 --- a/netware/BUILD/compile-netware-START +++ b/netware/BUILD/compile-netware-START @@ -1,8 +1,11 @@ #! /bin/sh -#debug +# debug #set -x +# stop on errors +set -e + if test ! -r ./sql/mysqld.cc then echo "you must start from the top source directory" diff --git a/netware/BUILD/compile-netware-all b/netware/BUILD/compile-netware-all index f8dea0f7583..35d275f3b42 100755 --- a/netware/BUILD/compile-netware-all +++ b/netware/BUILD/compile-netware-all @@ -1,5 +1,11 @@ #! /bin/sh +# debug +#set -x + +# stop on errors +set -e + path=`dirname $0` $path/compile-netware-standard diff --git a/netware/BUILD/compile-netware-debug b/netware/BUILD/compile-netware-debug index 2cd292c82fd..e44d64e3074 100755 --- a/netware/BUILD/compile-netware-debug +++ b/netware/BUILD/compile-netware-debug @@ -1,5 +1,11 @@ #! /bin/sh +# debug +#set -x + +# stop on errors +set -e + path=`dirname $0` . $path/compile-netware-START diff --git a/netware/BUILD/compile-netware-standard b/netware/BUILD/compile-netware-standard index c09337b5fe0..12cae1f024e 100755 --- a/netware/BUILD/compile-netware-standard +++ b/netware/BUILD/compile-netware-standard @@ -1,5 +1,12 @@ #! /bin/sh +# debug +#set -x + +# stop on errors +set -e + + path=`dirname $0` . $path/compile-netware-START diff --git a/netware/BUILD/cron-build b/netware/BUILD/cron-build new file mode 100755 index 00000000000..26ccde28e2a --- /dev/null +++ b/netware/BUILD/cron-build @@ -0,0 +1,46 @@ +#! /bin/sh + +# debug +#set -x + +# stop on errors +set -e + +# repository direcotry +repo_dir=`pwd` + +# show usage +show_usage() +{ + cat << EOF + +usage: cron-patch + +EOF + exit 0; +} + +echo "starting build..." + +# check for bk and repo_dir +bk help > /dev/null +repo_dir=`bk root $repo_dir` +cd $repo_dir + +# pull latest code +echo 'y' | bk pull + +# determine version +version=`grep -e "AM_INIT_AUTOMAKE(mysql, .*)" < configure.in | sed -e "s/AM_INIT_AUTOMAKE(mysql, \(.*\))/\1/"` +echo "version: $version" + +# latest revision +rev=`bk changes -e -n -d':REV:' | head -1` +echo "latest revision: $rev" + +# run bootstrap +./netware/BUILD/nwbootstrap --revision=$rev --suffix=$rev --build=all + +echo "done" + + diff --git a/netware/BUILD/crontab b/netware/BUILD/crontab new file mode 100755 index 00000000000..0097f8acaaf --- /dev/null +++ b/netware/BUILD/crontab @@ -0,0 +1,4 @@ +00 23 * * * (export PATH='/usr/local/bin:/usr/bin:/bin'; export DISPLAY=':0'; cd ~/bk/mysqldoc; echo 'y' | bk pull) +00 00 * * * (export PATH='/usr/local/bin:/usr/bin:/bin'; export DISPLAY=':0'; cd ~/bk/mysql-4.0; ./netware/BUILD/cron-build) +00 04 * * * (export PATH='/usr/local/bin:/usr/bin:/bin'; export DISPLAY=':0'; cd ~/bk/mysql-4.1; ./netware/BUILD/cron-build) + diff --git a/netware/BUILD/mwasmnlm b/netware/BUILD/mwasmnlm index c3501112aa5..381f84ec0c8 100755 --- a/netware/BUILD/mwasmnlm +++ b/netware/BUILD/mwasmnlm @@ -1,5 +1,8 @@ #! /bin/sh +# stop on errors +set -e + args=" $*" wine --debugmsg -all -- mwasmnlm $args diff --git a/netware/BUILD/mwccnlm b/netware/BUILD/mwccnlm index 9e989485bd9..cb2d62fe8cf 100755 --- a/netware/BUILD/mwccnlm +++ b/netware/BUILD/mwccnlm @@ -1,5 +1,8 @@ #! /bin/sh +# stop on errors +set -e + # mwccnlm is having a hard time understanding "-I./../include" # convert it to "-I../include" args=" "`echo $* | sed -e 's/-I.\/../-I../g'` diff --git a/netware/BUILD/mwldnlm b/netware/BUILD/mwldnlm index 7ad2872ccbb..28566fc5cb1 100755 --- a/netware/BUILD/mwldnlm +++ b/netware/BUILD/mwldnlm @@ -1,5 +1,8 @@ #! /bin/sh +# stop on errors +set -e + args=" $*" wine --debugmsg -all -- mwldnlm $args diff --git a/netware/BUILD/nwbootstrap b/netware/BUILD/nwbootstrap index 002e19c8e49..5d068e4e4de 100755 --- a/netware/BUILD/nwbootstrap +++ b/netware/BUILD/nwbootstrap @@ -3,11 +3,11 @@ # debug #set -x -path=`dirname $0` - # stop on errors set -e +path=`dirname $0` + # repository direcotry repo_dir=`pwd` @@ -24,6 +24,7 @@ temp_dir="" revision="" rev="" build="" +suffix="" mwenv="" # show usage @@ -81,6 +82,7 @@ for arg do --wine-build-dir=*) wine_build_dir=`echo "$arg" | sed -e "s;--wine-build-dir=;;"` ;; --revision=*) revision=`echo "$arg" | sed -e "s;--revision=;;"` ;; --build=*) build=`echo "$arg" | sed -e "s;--build=;;"` ;; + --suffix=*) suffix=`echo "$arg" | sed -e "s;--suffix=;;"` ;; --doc-dir=*) doc_dir=`echo "$arg" | sed -e "s;--doc-dir=;;"` ;; *) show_usage ;; esac @@ -111,6 +113,12 @@ echo "version: $version" # build target directory target_dir="$build_dir/mysql-$version" +# add suffix +if test $suffix +then + target_dir="$target_dir-$suffix" +fi + # delete any old target if test -d $target_dir.old; then rm -rf $target_dir.old; fi diff --git a/repl-tests/README b/repl-tests/README deleted file mode 100644 index 95611c6538d..00000000000 --- a/repl-tests/README +++ /dev/null @@ -1,12 +0,0 @@ -This directory contains a set of test cases for replication. To get it -to work on your system, install this version of MySQL on the master and on -the slave, configure them according to the Replication HOWTO in the manual, -modify include/master-slave.inc to specify correct connection parameters -for the master and the slave and do - -sh run-all-tests - -If you would like to add your own test case, create a directory -test-your-test-case-name, write your own run.test following the examples -in the other test cases. Note that you can create the files containing -the expected output ( master files) by running mysqltest --record < run.test
\ No newline at end of file diff --git a/repl-tests/include/master-slave.inc b/repl-tests/include/master-slave.inc deleted file mode 100644 index ad2dea1f520..00000000000 --- a/repl-tests/include/master-slave.inc +++ /dev/null @@ -1,2 +0,0 @@ -connect (slave,localhost,root,,test,0,/var/lib/mysql/mysql.sock); -connect (master,sarochka,admin,,test,0,0); diff --git a/repl-tests/run-all-tests b/repl-tests/run-all-tests deleted file mode 100755 index d9f08d8a8fb..00000000000 --- a/repl-tests/run-all-tests +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh - -for d in test-*; do -cd $d -echo -n $d | sed -e s/test-// -echo -n "...." -../../client/mysqltest $@ < run.test -cd .. -done
\ No newline at end of file diff --git a/repl-tests/test-auto-inc/run.test b/repl-tests/test-auto-inc/run.test deleted file mode 100755 index 8405329f458..00000000000 --- a/repl-tests/test-auto-inc/run.test +++ /dev/null @@ -1,10 +0,0 @@ -source ../include/master-slave.inc; -connection master; -drop table if exists x; -create table x(n int auto_increment primary key); -set insert_id = 2000; -insert into x values (NULL),(NULL),(NULL); -connection slave; -sleep 3; -@x.master select * from x; - diff --git a/repl-tests/test-auto-inc/x.master b/repl-tests/test-auto-inc/x.master deleted file mode 100644 index c76fc46ae97..00000000000 --- a/repl-tests/test-auto-inc/x.master +++ /dev/null @@ -1,4 +0,0 @@ -n -2000 -2001 -2002 diff --git a/repl-tests/test-bad-query/run.test b/repl-tests/test-bad-query/run.test deleted file mode 100755 index a86aaf84096..00000000000 --- a/repl-tests/test-bad-query/run.test +++ /dev/null @@ -1,10 +0,0 @@ -source ../include/master-slave.inc; -connection master; -drop table if exists x; -create table x(n int primary key); -!insert into x values (1),(2),(2); -insert into x values (3); -connection slave; -sleep 3; -@x.master select * from x; - diff --git a/repl-tests/test-bad-query/x.master b/repl-tests/test-bad-query/x.master deleted file mode 100644 index c62967af0bb..00000000000 --- a/repl-tests/test-bad-query/x.master +++ /dev/null @@ -1,4 +0,0 @@ -n -1 -2 -3 diff --git a/repl-tests/test-dump/run.test b/repl-tests/test-dump/run.test deleted file mode 100644 index c714186a67b..00000000000 --- a/repl-tests/test-dump/run.test +++ /dev/null @@ -1,25 +0,0 @@ -source ../include/master-slave.inc; -connection slave; -!slave stop; -flush slave; -connection master; -flush master; -connection slave; -slave start; -connection master; -use test; -drop table if exists words; -create table words (word char(20) not null, index(word)); -load data infile '/usr/dict/words' into table words; -drop table if exists words1; -create table words1 (word char(20) not null); -load data infile '/usr/dict/words' into table words1; -sleep 20; -connection slave; -use test; -drop table if exists words; -load table words from master; -drop table if exists words1; -load table words1 from master; -@table-dump-check.master check table words; -@table-dump-select.master select count(*) from words1; diff --git a/repl-tests/test-dump/table-dump-check.master b/repl-tests/test-dump/table-dump-check.master deleted file mode 100644 index 4061fdb4a0d..00000000000 --- a/repl-tests/test-dump/table-dump-check.master +++ /dev/null @@ -1,2 +0,0 @@ -Table Op Msg_type Msg_text -test.words check status OK diff --git a/repl-tests/test-dump/table-dump-select.master b/repl-tests/test-dump/table-dump-select.master deleted file mode 100644 index ae93d31c066..00000000000 --- a/repl-tests/test-dump/table-dump-select.master +++ /dev/null @@ -1,2 +0,0 @@ -count(*) -45402 diff --git a/repl-tests/test-repl-alter/run.test b/repl-tests/test-repl-alter/run.test deleted file mode 100644 index 2e031010d5c..00000000000 --- a/repl-tests/test-repl-alter/run.test +++ /dev/null @@ -1,12 +0,0 @@ -source ../include/master-slave.inc; -connection master; -drop table if exists test; -CREATE TABLE test (name varchar(64), age smallint(3)); -INSERT INTO test SET name='Andy', age=31; -INSERT test SET name='Jacob', age=2; -INSERT into test SET name='Caleb', age=1; -ALTER TABLE test ADD id int(8) ZEROFILL AUTO_INCREMENT PRIMARY KEY; -@test.master select * from test; -connection slave; -sleep 3; -@test.master select * from test; diff --git a/repl-tests/test-repl-alter/test.master b/repl-tests/test-repl-alter/test.master deleted file mode 100644 index 763154b938e..00000000000 --- a/repl-tests/test-repl-alter/test.master +++ /dev/null @@ -1,4 +0,0 @@ -name age id -Andy 31 00000001 -Jacob 2 00000002 -Caleb 1 00000003 diff --git a/repl-tests/test-repl-ts/repl-timestamp.master b/repl-tests/test-repl-ts/repl-timestamp.master deleted file mode 100644 index c3e4a2326d0..00000000000 --- a/repl-tests/test-repl-ts/repl-timestamp.master +++ /dev/null @@ -1,2 +0,0 @@ -unix_timestamp(t) -200006 diff --git a/repl-tests/test-repl-ts/repl-timestamp.master.reject b/repl-tests/test-repl-ts/repl-timestamp.master.reject deleted file mode 100644 index 091b18351ed..00000000000 --- a/repl-tests/test-repl-ts/repl-timestamp.master.reject +++ /dev/null @@ -1,2 +0,0 @@ -unix_timestamp(t) -973999074 diff --git a/repl-tests/test-repl-ts/run.test b/repl-tests/test-repl-ts/run.test deleted file mode 100644 index 0a5224ce02a..00000000000 --- a/repl-tests/test-repl-ts/run.test +++ /dev/null @@ -1,17 +0,0 @@ -#! ../client/mysqltest -# tests if the replicaion preserves timestamp properly - -source ../include/master-slave.inc; -connection master; -set timestamp=200006; -drop table if exists foo; -create table foo(t timestamp not null,a char(1)); -insert into foo ( a) values ('F'); -@repl-timestamp.master select unix_timestamp(t) from foo; -sleep 3; -connection slave; -drop table if exists foo; -load table foo from master; -@repl-timestamp.master select unix_timestamp(t) from foo; - - diff --git a/repl-tests/test-repl/foo-dump-master.master b/repl-tests/test-repl/foo-dump-master.master deleted file mode 100644 index 982e0523cfb..00000000000 --- a/repl-tests/test-repl/foo-dump-master.master +++ /dev/null @@ -1,3 +0,0 @@ -n -1 -2 diff --git a/repl-tests/test-repl/foo-dump-slave.master b/repl-tests/test-repl/foo-dump-slave.master deleted file mode 100644 index 982e0523cfb..00000000000 --- a/repl-tests/test-repl/foo-dump-slave.master +++ /dev/null @@ -1,3 +0,0 @@ -n -1 -2 diff --git a/repl-tests/test-repl/run.test b/repl-tests/test-repl/run.test deleted file mode 100755 index cc93d964efa..00000000000 --- a/repl-tests/test-repl/run.test +++ /dev/null @@ -1,24 +0,0 @@ -source ../include/master-slave.inc; -connection slave; -!slave stop; -connection master; -flush master; -connection slave; -flush slave; -!slave start; -sleep 3; -connection master; -use test; -drop table if exists words; -create table words (word char(20) not null, index(word)); -load data infile '/usr/dict/words' into table words; -drop table if exists foo; -create table foo(n int); -insert into foo values(1),(2); -@foo-dump-master.master select * from foo; -@sum-wlen-master.master select sum(length(word)) from words; -connection slave; -sleep 15; -use test; -@sum-wlen-slave.master select sum(length(word)) from words; -@foo-dump-slave.master select * from foo; diff --git a/repl-tests/test-repl/sum-wlen-master.master b/repl-tests/test-repl/sum-wlen-master.master deleted file mode 100644 index e749ab4840a..00000000000 --- a/repl-tests/test-repl/sum-wlen-master.master +++ /dev/null @@ -1,2 +0,0 @@ -sum(length(word)) -363634 diff --git a/repl-tests/test-repl/sum-wlen-slave.master b/repl-tests/test-repl/sum-wlen-slave.master deleted file mode 100644 index e749ab4840a..00000000000 --- a/repl-tests/test-repl/sum-wlen-slave.master +++ /dev/null @@ -1,2 +0,0 @@ -sum(length(word)) -363634 diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 88f561e0e6d..1134226bfaf 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -32,7 +32,9 @@ bin_SCRIPTS = @server_scripts@ \ mysqldumpslow \ mysql_explain_log \ mysql_tableinfo \ - mysqld_multi + mysqld_multi \ + fill_help_tables \ + mysql_create_system_tables EXTRA_SCRIPTS = make_binary_distribution.sh \ make_win_src_distribution.sh \ @@ -54,14 +56,13 @@ EXTRA_SCRIPTS = make_binary_distribution.sh \ mysqld_multi.sh \ mysql_tableinfo.sh \ mysqld_safe.sh \ - fill_help_tables.sh + fill_help_tables.sh \ + mysql_create_system_tables.sh EXTRA_DIST = $(EXTRA_SCRIPTS) \ mysqlaccess.conf \ mysqlbug -pkgdata_DATA = fill_help_tables.sql - # mysqlbug should be distributed built so that people can report build # failures with it. CLEANFILES = @server_scripts@ \ @@ -81,7 +82,7 @@ CLEANFILES = @server_scripts@ \ mysqldumpslow \ mysqld_multi \ fill_help_tables \ - fill_help_tables.sql + mysql_create_system_tables SUPERCLEANFILES = mysqlbug @@ -137,12 +138,5 @@ SUFFIXES = .sh # Don't update the files from bitkeeper %::SCCS/s.% -all: fill_help_tables.sql make_win_src_distribution make_binary_distribution - -# The following rule is here to ensure that build will continue -# even if we don't have perl installed. In this case the help tables -# will be empty +all: make_win_src_distribution make_binary_distribution -fill_help_tables.sql: fill_help_tables ../Docs/manual.texi - -./fill_help_tables < ../Docs/manual.texi > fill_help_tables.sql - echo "" >> fill_help_tables.sql diff --git a/scripts/fill_help_tables.sh b/scripts/fill_help_tables.sh index e21b0ff2bb0..b8cf4ccb3a7 100644 --- a/scripts/fill_help_tables.sh +++ b/scripts/fill_help_tables.sh @@ -1,31 +1,178 @@ #!@PERL@ # -# Usage: fill_help_tables <manual.texi> -# Example: ./fill_help_tables < ../Docs/manual.texi > fill_help_tables.sql +# Copyright (C) 2003 MySQL AB +# For a more info consult the file COPYRIGHT distributed with this file. # # This script generates the SQL statements required by mysql_install_db to # fill up the tables for the server-side online function help, which can be # invoked with "help <function>" from the MySQL client. # +# Usage: +# fill_help_tables OPTIONS < manual.texi > fill_help_tables.sql +# +# --help display this helpscreen and exit +# --verbose print information about help completeness to STDERR +# --lexems=path path to file with lexems. it is used with verbose option. +# default value is ../sql/lex.h +# Examples: +# ./fill_help_tables --help +# ./fill_help_tables --verbose < manual.texi > fill_help_tables.sql +# ./fill_help_tables < manual.texi > fill_help_tables.sql +# # Please note, that you first need to update Docs/manual.texi with the # manual file from the separate "mysqldoc" BitKeeper-Tree! The manual.texi # included in the source tree is just an empty stub file - the full manual # is now maintained in a separate tree. # +# extra tags in manual.texi: +# +# @c help_category <category_name>[@<parent_category_name>] +# +# @c description_for_help_topic <topic_name> <keyword1> <keyword2> +# .... +# @c end_description_for_help_topic +# +# @c example_for_help_topic <topic_name> +# @example +# .... +# @example +# +# # Original version by Victor Vagin <vva@mysql.com> # -my $cat_name= ""; -my $func_name= ""; -my $text= ""; -my $example= ""; +use strict; +use Getopt::Long; + +my $insert_portion_size= 25; +my $error_prefix= "help parsing error:"; + +my $path_to_lex_file= "../sql/lex.h"; +my $verbose_option= 0; +my $help_option= 0; + +GetOptions( + "help",\$help_option, + "verbose",\$verbose_option, + "lexems=s",\$path_to_lex_file +); + +if ($help_option ne 0) +{ + print <<_HELP; + +This script generates the SQL statements required by mysql_install_db to +fill up the tables for the server-side online function help, which can be +invoked with "help <function>" from the MySQL client. + +Usage: + fill_help_tables OPTIONS < manual.texi > fill_help_tables.sql + + --help display this helpscreen and exit + --verbose print information about help completeness to STDERR + --lexems=path path to file with lexems. it is used with verbose option. + default value is ../sql/lex.h + +Examples: + ./fill_help_tables --help + ./fill_help_tables --verbose < manual.texi > fill_help_tables.sql + ./fill_help_tables < manual.texi > fill_help_tables.sql + +_HELP + exit; +} -local $mode= ""; +my $current_category= ""; +my $current_parent_category= ""; +my $next_example_for_topic= ""; + +my %topics; +my %categories; +my %keywords; + +$categories{Contents}->{__parent_category__}= ""; + +sub add_topic_to_category +{ + my ($topic_name)= @_; + + $categories{$current_category}->{$topic_name}= $topics{$topic_name}; + my $category= $categories{$current_category}; + + if (exists($category->{__parent_category__})) + { + my $old_parent= $category->{__parent_category__}; + if ($old_parent ne $current_parent_category) + { + print STDERR "$error_prefix wrong parent for $current_category\n"; + } + } + + if ($current_parent_category ne "") + { + $category->{__parent_category__}= $current_parent_category; + } + + if (exists($topics{$topic_name}->{category})) + { + my $old_category= $topics{$topic_name}->{category}; + if ($old_category ne $category) + { + print STDERR "$error_prefix wrong category for $topic_name\n"; + } + } + + $topics{$topic_name}->{category}= $category; +} + +sub add_example +{ + my ($topic_name,$example)= @_; + + $topic_name=~ tr/a-z/A-Z/; + + if (exists($topics{$topic_name}->{example})) + { + print STDERR "$error_prefix double example for $topic_name\n"; + } + + $topics{$topic_name}->{example}= $example; + add_topic_to_category($topic_name); +} + +sub add_description +{ + my ($topic_name,$description)= @_; + + $topic_name=~ tr/a-z/A-Z/; + + if (exists($topics{$topic_name}->{description})) + { + print STDERR "$error_prefix double description for $topic_name\n"; + } + $topics{$topic_name}->{description}= $description; + add_topic_to_category($topic_name); +} + +sub add_keyword +{ + my ($topic_name,$keyword)= @_; + + $topic_name=~ tr/a-z/A-Z/; + $keyword=~ tr/a-z/A-Z/; + + push(@{$topics{$topic_name}->{keywords}},$keyword); + if (exists($keywords{$keyword}->{$topic_name})) + { + print STDERR "$error_prefix double keyword $keyword for $topic_name\n"; + } + $keywords{$keyword}->{$topic_name}= $topics{$topic_name}; +} sub prepare_name { my ($a)= @_; - + $a =~ s/(\@itemize \@bullet)/ /g; $a =~ s/(\@end itemize)/ /g; $a =~ s/(\@end multitable)/ /g; @@ -46,41 +193,57 @@ sub prepare_name $a =~ s/\`/\`\`/g; $a =~ s/\@table \@code/ /g; - $a =~ s/\(\)//g; - - $a =~ s/((\w|\s)+)\(([\+-=><\/%*!<>\s]+)\)/$3/gxs; #$a =~ s/((\w|\s)+)\(([\+-=><\/%*!<>\s]+)\)/$3 $1/gxs; - $a =~ s/([\+-=><\/%*!<>\s]+)\(((\w|\s)+)\)/$1/gxs;#$a =~ s/([\+-=><\/%*!<>\s]+)\(((\w|\s)+)\)/$1 $2/gxs; + $a =~ s/\"/\\\"/g; + + $a =~ s/((\w|\s)+)\(([\+-=><\/%*!<>\s]+)\)/$3/gxs; + $a =~ s/([\+-=><\/%*!<>\s]+)\(((\w|\s)+)\)/$1/gxs; $a =~ s/((\w|\s)+)\((.+)\)/$1/gxs; - + return $a; } -sub prepare_text +sub prepare_description { my ($a)= @_; - $a =~ s/(\@itemize \@bullet)/ /g; - $a =~ s/(\@end itemize)/ /g; + $a =~ s/(\@itemize \@bullet\n)//g; + $a =~ s/(\@c help_keyword (.*?)\n)//g; + $a =~ s/(\@end itemize\n)//g; + $a =~ s/(\@end example\n)//g; + $a =~ s/(\@example\n)//g; + $a =~ s/(\@{)/{/g; + $a =~ s/(\@})/}/g; $a =~ s/(\@end multitable)/ /g; $a =~ s/(\@end table)/ /g; - $a =~ s/(\@cindex(.*?)\n)/ /g; + $a =~ s/(\@cindex(.*?)\n)//g; + $a =~ s/(\@findex(.*?)\n)//g; + $a =~ s/(\@table(.*?)\n)//g; $a =~ s/(\@multitable \@columnfractions(.*?)\n)/ /g; $a =~ s/(\@node(.*?)\n)/ /g; $a =~ s/(\@tab)/\t/g; $a =~ s/\@itemx/ /g; - $a =~ s/\@item/ /g; + $a =~ s/(\@item\n(\s*?))(\S)/ --- $3/g; + $a =~ s/(\@item)/ /g; + $a =~ s/(\@tindex\s(.*?)\n)//g; + $a =~ s/(\@c\s(.*?)\n)//g; $a =~ s/\@code\{((.|\n)+?)\}/$1/go; $a =~ s/\@strong\{(.+?)\}/$1/go; $a =~ s/\@samp\{(.+?)\}/$1/go; $a =~ s/\@emph\{((.|\n)+?)\}/\/$1\//go; $a =~ s/\@xref\{((.|\n)+?)\}/See also : [$1]/go; $a =~ s/\@ref\{((.|\n)+?)\}/[$1]/go; - $a =~ s/\'/\'\'/g; + $a =~ s/\@w\{((.|\n)+?)\}/$1/go; + $a =~ s/\@strong\{((.|\n)+?)\}/\n!!!!\n$1\n!!!!\n/go; + $a =~ s/\@file\{((.|\n)+?)\}/\*$1/go; $a =~ s/\\/\\\\/g; - $a =~ s/\`/\`\`/g; - $a =~ s/(\n*?)$//g; + $a =~ s/\n\n$/\n/g; + $a =~ s/\n\n$/\n/g; + $a =~ s/\n\n$/\n/g; + $a =~ s/\n\n$/\n/g; + $a =~ s/\n\n$/\n/g; $a =~ s/\n/\\n/g; + $a =~ s/\"/\\\"/g; $a =~ s/\@table \@code/ /g; @@ -91,148 +254,291 @@ sub prepare_example { my ($a)= @_; - $a =~ s/\'/\'\'/g; + $a =~ s/(^\@c for_help_topic(.*?)\n)//g; + $a =~ s/\\/\\\\/g; - $a =~ s/\`/\`\`/g; + $a =~ s/(\@{)/{/g; + $a =~ s/(\@})/}/g; + $a =~ s/(\@\@)/\@/g; $a =~ s/(\n*?)$//g; $a =~ s/\n/\\n/g; - + $a =~ s/\"/\\\"/g; + return $a; } -sub flush_all +sub parse_example { - my ($mode) = @_; - - if ($mode eq ""){return;} - - $func_name= prepare_name($func_name); - $text= prepare_text($text); - $example= prepare_example($example); - - if ($func_name ne "" && $text ne "" && !($func_name =~ /[abcdefghikjlmnopqrstuvwxyz]/)){ - print "INSERT IGNORE INTO help_topic (name,description,example) VALUES ("; - print "'$func_name',"; - print "'$text',"; - print "'$example'"; - print ");\n"; - print "INSERT IGNORE INTO help_relation (help_category_id,help_topic_id) VALUES (\@cur_category,LAST_INSERT_ID());\n"; + return if (!($_=~/\@example/)); + return if ($next_example_for_topic eq ""); + + my $topic_name= $next_example_for_topic; + $next_example_for_topic= ""; + my $text= ""; + + while (<>) + { + last if ($_=~/\@end example/); + $text .= $_; } + + $text= prepare_example($text); - $func_name= ""; - $text= ""; - $example= ""; - $mode= ""; + add_example($topic_name,$text) if ($topic_name ne ""); } -sub new_category +sub parse_example_for_topic { - my ($category)= @_; - - $category= prepare_text($category); - - print "INSERT IGNORE INTO help_category (name) VALUES (\'$category\');\n"; - print "SET \@cur_category=LAST_INSERT_ID();\n"; + my ($for_topic)= m|\@c example_for_help_topic (.+?)$|; + return if ($for_topic eq ""); + + $next_example_for_topic= $for_topic; } -#print "INSERT IGNORE INTO db (Host,DB,User,Select_priv) VALUES ('%','mysql_help','','Y');\n"; -#print "CREATE DATABASE mysql_help;\n"; +sub parse_description +{ + my ($topic_description)= m|\@c description_for_help_topic (.+?)$|; + return if ($topic_description eq ""); + + my ($topic_name,$topic_keywords)= split(/ /,$topic_description); + + if ($topic_name eq "" || $topic_keywords eq "") + { + $topic_name= $topic_description; + } + else + { + my $keyword; + foreach $keyword (split(/ /,$topic_keywords)) + { + add_keyword($topic_name,$keyword) if ($keyword ne ""); + } + } + + my $text= ""; + + while (<>) + { + last if ($_=~/\@c end_description_for_help_topic/); + $text .= $_; + } + + $text= prepare_description($text); + add_description($topic_name,$text); +} -print "USE mysql;\n"; +sub parse_category +{ + my ($c_name,$pc_name)= m|\@c help_category (.+?)\@(.+?)$|; -print "DROP TABLE IF EXISTS help_topic;\n"; -print "CREATE TABLE help_topic ("; -print " help_topic_id int unsigned not null auto_increment,"; -print " name varchar(64) not null,"; -print " description text not null,"; -print " example text not null,"; -print " url varchar(128) not null,"; -print " primary key (help_topic_id),"; -print " unique index(name)"; -print ") type=myisam;\n\n"; + if ($pc_name ne "") + { + $current_category= prepare_name($c_name); + $current_parent_category= prepare_name($pc_name); + } + else + { + my ($c_name)=m|\@c help_category (.+?)$|; + return if ($c_name eq ""); -print "DROP TABLE IF EXISTS help_category;\n"; -print "CREATE TABLE help_category ("; -print " help_category_id smallint unsigned not null auto_increment,"; -print " name varchar(64) not null,"; -print " url varchar(128) not null,"; -print " primary key (help_category_id),"; -print " unique index (name)"; -print ") type=myisam;\n\n"; + $current_category= prepare_name($c_name); + $current_parent_category= "Contents" + } +} -print "DROP TABLE IF EXISTS help_relation;\n"; -print "CREATE TABLE help_relation ("; -print" help_topic_id int unsigned not null references help_topic,"; -print" help_category_id smallint unsigned not null references help_category,"; -print" primary key (help_category_id, help_topic_id),"; -print ") type=myisam;\n\n"; +# parse manual: -print "SET \@cur_category=null;\n\n"; +while (<>) +{ + parse_example_for_topic (); + parse_example (); + parse_description (); + parse_category (); +} -my $in_section_6_3= 0; +# test results of parsing: -for(<>) +sub print_bad_names { - if ($_=~/\@section Functions for Use in \@code{SELECT} and \@code{WHERE} Clauses/ && - !$in_section_6_3){ - $in_section_6_3= 1; - next; + my($names,$prompt)= @_; + if (scalar(@{$names})) + { + print STDERR "\n-------------- $prompt : \n\n"; + my $name; + foreach $name (@{$names}) + { + print STDERR "$name\n"; + } + print STDERR "\n"; } +} - if ($_=~/\@section/ && $in_section_6_3){ - $in_section_6_3= 0; - next; +sub print_verbose_errors +{ + my($name_of_log_file)= @_; + + my @without_help; + my @description_with_at; + my @example_with_at; + my @without_description; + my @without_example; + + print STDERR "\n-------------- parameters of help completeness : \n\n"; + + my $count_lex= 0; + if (!open (TLEX,"<$path_to_lex_file")) + { + print STDERR "Error opening lex file \"$path_to_lex_file\" $!\n"; } + else + { + for (<TLEX>) + { + my ($a,$lex,$b)=m|(.+?)\"(.+?)\"(.+?)$|; + next if ($lex eq ""); + $count_lex++; + next if (exists($topics{$lex}) || exists($keywords{$lex})); + push(@without_help,$lex); + } + close(TLEX); + print STDERR "number of lexems in \"$path_to_lex_file\" - $count_lex\n"; + } + + my $name; + my @topic_names= keys(%topics); + foreach $name (@topic_names) + { + my $topic= $topics{$name}; + push(@description_with_at,$name) if ($topic->{description}=~/\@/); + push(@example_with_at,$name) if ($topic->{example}=~/\@/); + push(@without_description,$name) if (!exists($topic->{description})); + push(@without_example,$name) if (!exists($topic->{example})); + } + + my $count_categories= scalar(keys(%categories)); + print STDERR "number of help categories - ",$count_categories,"\n"; + my $count_topics= scalar(@topic_names); + print STDERR "number of help topics - ",$count_topics,"\n"; + my $count_keywords= scalar(keys(%keywords)); + print STDERR "number of help keywords - ",$count_keywords,"\n"; + + my $count_without_help= scalar(@without_help); + print_bad_names(\@without_help,"lexems without help (". + $count_without_help." ~ ". + (int (($count_without_help/$count_lex)*100)). + "%)"); + print_bad_names(\@description_with_at, + " topics below have symbol \'@\' in their descriptions.\n". + "it's probably the litter from 'texi' tags (script needs fixing)"); + print_bad_names(\@example_with_at, + " topics below have symbol \'@\' in their examples.\n". + "it's probably the litter from 'texi' tags (script needs fixing)"); + print_bad_names(\@without_description,"topics without description"); + + my $count_without_example= scalar(@without_example); + print_bad_names(\@without_example,"topics without example (". + $count_without_example." ~ ". + (int (($count_without_example/$count_topics)*100)). + "%)"); +} - if (!$in_section_6_3) { next; } +print_verbose_errors if ($verbose_option ne 0); - my $c_name= ""; +# output result - ($c_name)=m|\@c for_mysql_help,(.+?)$|; - if (!($c_name eq "") && ! ($c_name =~ m/$cat_name/i)){ - ($cat_name)= $c_name; - new_category($cat_name); - next; +sub print_insert_header +{ + my($count,$header)= @_; + + if ($count % $insert_portion_size ne 0) { + print ","; + } else { + print ";\n" if ($count ne 0); + print "$header"; } +} - ($c_name)=m|\@subsubsection (.+?)$|; - if (!($c_name eq "") && ! ($c_name =~ m/$cat_name/i)){ - ($cat_name)= $c_name; - new_category($cat_name); - next; - } +print "delete from help_topic;\n"; +print "delete from help_category;\n"; +print "delete from help_keyword;\n"; +print "delete from help_relation;\n\n"; - ($c_name)=m|\@subsection (.+?)$|; - if (!($c_name eq "") && ! ($c_name =~ m/$cat_name/i)){ - ($cat_name)= $c_name; - new_category($cat_name); - next; +my @category_names= keys(%categories); +if (scalar(@category_names)) +{ + my $cat_name; + my $count= 0; + foreach $cat_name (@category_names) + { + $categories{$cat_name}->{__id__}= $count; + $count++; } - ($f_name)=m|\@findex (.+?)$|; - if (!($f_name eq "")){ - flush_all($mode); - ($func_name)= ($f_name); - $mode= "text"; - next; + my $header= "insert into help_category ". + "(help_category_id,name,parent_category_id) values "; + $count= 0; + foreach $cat_name (@category_names) + { + print_insert_header($count,$header); + my $parent_cat_name= $categories{$cat_name}->{__parent_category__}; + my $parent_cat_id= $parent_cat_name eq "" + ? "-1" : $categories{$parent_cat_name}->{__id__}; + print "($count,\"$cat_name\",$parent_cat_id)"; + $count++; } + printf ";\n\n"; +} - if ($_=~/\@example/ && ($mode eq "text")){ - $mode= "example"; - next; +my @topic_names= keys(%topics); +if (scalar(@topic_names)) +{ + my $header= "insert into help_topic ". + "(help_topic_id,help_category_id,name,description,example) values "; + my $topic_name; + my $count= 0; + foreach $topic_name (@topic_names) + { + print_insert_header($count,$header); + my $topic= $topics{$topic_name}; + print "($count,"; + print "$topic->{category}->{__id__},"; + print "\"$topic_name\","; + print "\"$topic->{description}\","; + print "\"$topic->{example}\")"; + $topics{$topic_name}->{__id__}= $count; + $count++; } + printf ";\n\n"; +} - if ($_=~/\@end example/ && ($mode eq "example")){ - flush_all($mode); - next; +my @keywords_names= keys(%keywords); +if (scalar(@keywords_names)) +{ + my $header= "insert into help_keyword (help_keyword_id,name) values "; + my $keyword_name; + my $count= 0; + foreach $keyword_name (@keywords_names) + { + print_insert_header($count,$header); + print "($count,\"$keyword_name\")"; + $count++; } - - if ($mode eq "text") { $text .= $_; } - if ($mode eq "example") { $example .= $_; } + printf ";\n\n"; + + $header= "insert into help_relation ". + "(help_topic_id,help_keyword_id) values "; + $count= 0; + my $count_keyword= 0; + foreach $keyword_name (@keywords_names) + { + my $topic_name; + foreach $topic_name (keys(%{$keywords{$keyword_name}})) + { + print_insert_header($count,$header); + print "($topics{$topic_name}->{__id__},$count_keyword)"; + $count++; + } + $count_keyword++; + } + printf ";\n\n"; } - - -print "DELETE help_category "; -print "FROM help_category "; -print "LEFT JOIN help_relation ON help_category.help_category_id=help_relation.help_category_id "; -print "WHERE help_relation.help_category_id is null;" diff --git a/scripts/make_win_src_distribution.sh b/scripts/make_win_src_distribution.sh index 73600d5749b..a6312193221 100755 --- a/scripts/make_win_src_distribution.sh +++ b/scripts/make_win_src_distribution.sh @@ -160,7 +160,7 @@ copy_dir_files() { for arg do print_debug "Copying files from directory '$arg'" cd $SOURCE/$arg/ - for i in *.c *.h *.ih *.i *.ic *.asm *.def \ + for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def \ README INSTALL* LICENSE do if [ -f $i ] diff --git a/scripts/mysql_create_system_tables.sh b/scripts/mysql_create_system_tables.sh new file mode 100644 index 00000000000..c54394305cd --- /dev/null +++ b/scripts/mysql_create_system_tables.sh @@ -0,0 +1,311 @@ +#!/bin/sh + +# Copyright (C) 1997-2002 MySQL AB +# For a more info consult the file COPYRIGHT distributed with this file + +# This script writes on stdout SQL commands to generate all not +# existing MySQL system tables. It also replaces the help tables with +# new context from the manual (from fill_help_tables.sql). + +# $1 - "test" or "real" or "verbose" variant of database +# $2 - path to mysql-database directory +# $3 - hostname +# $4 - windows option + +if test x$1 = x"" ; +then + echo " +This script writes on stdout SQL commands to generate all not +existing MySQL system tables. It also replaces the help tables with +new context from the manual (from fill_help_tables.sql). + +Usage: + mysql_create_system_tables {help|real|verbose} <path to mysql-database directory> <hostname> <windows option> +"; + exit; +fi + +mdata=$2 +hostname=$3 +windows=$4 + +# Initialize variables +c_d="" i_d="" +c_h="" i_h="" +c_u="" i_u="" +c_f="" i_f="" +c_t="" c_c="" +c_ht="" +c_hc="" +c_hr="" +c_hk="" +i_ht="" + +# Check for old tables +if test ! -f $mdata/db.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing db table" 1>&2; + fi + + # mysqld --bootstrap wants one command/line + c_d="$c_d CREATE TABLE db (" + c_d="$c_d Host char(60) binary DEFAULT '' NOT NULL," + c_d="$c_d Db char(64) binary DEFAULT '' NOT NULL," + c_d="$c_d User char(16) binary DEFAULT '' NOT NULL," + c_d="$c_d Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d References_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d PRIMARY KEY Host (Host,Db,User)," + c_d="$c_d KEY User (User)" + c_d="$c_d )" + c_d="$c_d comment='Database privileges';" + + i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); + INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');" +fi + +if test ! -f $mdata/host.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing host table" 1>&2; + fi + + c_h="$c_h CREATE TABLE host (" + c_h="$c_h Host char(60) binary DEFAULT '' NOT NULL," + c_h="$c_h Db char(64) binary DEFAULT '' NOT NULL," + c_h="$c_h Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h References_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h PRIMARY KEY Host (Host,Db)" + c_h="$c_h )" + c_h="$c_h comment='Host privileges; Merged with database privileges';" +fi + +if test ! -f $mdata/user.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing user table" 1>&2; + fi + + c_u="$c_u CREATE TABLE user (" + c_u="$c_u Host char(60) binary DEFAULT '' NOT NULL," + c_u="$c_u User char(16) binary DEFAULT '' NOT NULL," + c_u="$c_u Password char(45) binary DEFAULT '' NOT NULL," + c_u="$c_u Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Process_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u File_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u References_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Super_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u ssl_type enum('','ANY','X509', 'SPECIFIED') DEFAULT '' NOT NULL," + c_u="$c_u ssl_cipher BLOB NOT NULL," + c_u="$c_u x509_issuer BLOB NOT NULL," + c_u="$c_u x509_subject BLOB NOT NULL," + c_u="$c_u max_questions int(11) unsigned DEFAULT 0 NOT NULL," + c_u="$c_u max_updates int(11) unsigned DEFAULT 0 NOT NULL," + c_u="$c_u max_connections int(11) unsigned DEFAULT 0 NOT NULL," + c_u="$c_u PRIMARY KEY Host (Host,User)" + c_u="$c_u )" + c_u="$c_u comment='Users and global privileges';" + + if test x$1 = x"test" + then + i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + REPLACE INTO user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + INSERT INTO user (host,user) values ('localhost',''); + INSERT INTO user (host,user) values ('$hostname','');" + else + i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + INSERT INTO user (host,user) values ('localhost','');" + if test "$windows" -eq 0 + then + i_u="$i_u + INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + INSERT INTO user (host,user) values ('$hostname','');" + fi + fi +fi + +if test ! -f $mdata/func.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing func table" 1>&2; + fi + + c_f="$c_f CREATE TABLE func (" + c_f="$c_f name char(64) binary DEFAULT '' NOT NULL," + c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL," + c_f="$c_f dl char(128) DEFAULT '' NOT NULL," + c_f="$c_f type enum ('function','aggregate') NOT NULL," + c_f="$c_f PRIMARY KEY (name)" + c_f="$c_f )" + c_f="$c_f comment='User defined functions';" +fi + +if test ! -f $mdata/tables_priv.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing tables_priv table" 1>&2; + fi + + c_t="$c_t CREATE TABLE tables_priv (" + c_t="$c_t Host char(60) binary DEFAULT '' NOT NULL," + c_t="$c_t Db char(64) binary DEFAULT '' NOT NULL," + c_t="$c_t User char(16) binary DEFAULT '' NOT NULL," + c_t="$c_t Table_name char(60) binary DEFAULT '' NOT NULL," + c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL," + c_t="$c_t Timestamp timestamp(14)," + c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL," + c_t="$c_t Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," + c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name)," + c_t="$c_t KEY Grantor (Grantor)" + c_t="$c_t )" + c_t="$c_t comment='Table privileges';" +fi + +if test ! -f $mdata/columns_priv.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing columns_priv table" 1>&2; + fi + + c_c="$c_c CREATE TABLE columns_priv (" + c_c="$c_c Host char(60) binary DEFAULT '' NOT NULL," + c_c="$c_c Db char(64) binary DEFAULT '' NOT NULL," + c_c="$c_c User char(16) binary DEFAULT '' NOT NULL," + c_c="$c_c Table_name char(64) binary DEFAULT '' NOT NULL," + c_c="$c_c Column_name char(64) binary DEFAULT '' NOT NULL," + c_c="$c_c Timestamp timestamp(14)," + c_c="$c_c Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," + c_c="$c_c PRIMARY KEY (Host,Db,User,Table_name,Column_name)" + c_c="$c_c )" + c_c="$c_c comment='Column privileges';" +fi + +if test ! -f $mdata/help_topic.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing help_topic table" 1>&2; + fi + + c_ht="$c_ht CREATE TABLE help_topic (" + c_ht="$c_ht help_topic_id int unsigned not null," + c_ht="$c_ht name varchar(64) not null," + c_ht="$c_ht help_category_id smallint unsigned not null," + c_ht="$c_ht description text not null," + c_ht="$c_ht example text not null," + c_ht="$c_ht url varchar(128) not null," + c_ht="$c_ht primary key (help_topic_id)," + c_ht="$c_ht unique index (name)" + c_ht="$c_ht )" + c_ht="$c_ht comment='help topics';" +fi + +old_categories="yes" + +if test ! -f $mdata/help_category.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing help_category table" 1>&2; + fi + + c_hc="$c_hc CREATE TABLE help_category (" + c_hc="$c_hc help_category_id smallint unsigned not null," + c_hc="$c_hc name varchar(64) not null," + c_hc="$c_hc parent_category_id smallint unsigned null," + c_hc="$c_hc url varchar(128) not null," + c_hc="$c_hc primary key (help_category_id)," + c_hc="$c_hc unique index (name)" + c_hc="$c_hc )" + c_hc="$c_hc comment='help categories';" +fi + +if test ! -f $mdata/help_keyword.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing help_keyword table" 1>&2; + fi + + c_hk="$c_hk CREATE TABLE help_keyword (" + c_hk="$c_hk help_keyword_id int unsigned not null," + c_hk="$c_hk name varchar(64) not null," + c_hk="$c_hk primary key (help_keyword_id)," + c_hk="$c_hk unique index (name)" + c_hk="$c_hk )" + c_hk="$c_hk comment='help keywords';" +fi + +if test ! -f $mdata/help_relation.frm +then + if test x$1 = x"verbose" ; then + echo "Preparing help_relation table" 1>&2; + fi + + c_hr="$c_hr CREATE TABLE help_relation (" + c_hr="$c_hr help_topic_id int unsigned not null references help_topic," + c_hr="$c_hr help_keyword_id int unsigned not null references help_keyword," + c_hr="$c_hr primary key (help_keyword_id, help_topic_id)" + c_hr="$c_hr )" + c_hr="$c_hr comment='keyword-topic relation';" +fi + +cat << END_OF_DATA +use mysql; +$c_d +$i_d + +$c_h +$i_h + +$c_u +$i_u + +$c_f +$i_f + +$c_t +$c_c + +$c_ht +$c_hc +$c_hr +$c_hk +END_OF_DATA + diff --git a/scripts/mysql_fix_privilege_tables.sh b/scripts/mysql_fix_privilege_tables.sh index 83ee5023b89..05d6f3ffb71 100644 --- a/scripts/mysql_fix_privilege_tables.sh +++ b/scripts/mysql_fix_privilege_tables.sh @@ -1,14 +1,5 @@ #!/bin/sh -echo "This scripts updates the mysql.user, mysql.db, mysql.host and the" -echo "mysql.func tables to MySQL 3.22.14 and above." -echo "" -echo "This is needed if you want to use the new GRANT functions," -echo "CREATE AGGREGATE FUNCTION or want to use the more secure passwords in 3.23" -echo "" -echo "If you get 'Access denied' errors, you should run this script again" -echo "and give the MySQL root user password as an argument!" - root_password="$1" host="localhost" user="root" @@ -20,6 +11,21 @@ else cmd="@bindir@/mysql -f --user=$user --password=$root_password --host=$host mysql" fi +# Debian addition +if [ "$1" = "--sql-only" ]; then + root_password="" + cmd="/usr/share/mysql/echo_stderr" +fi + +echo "This scripts updates the mysql.user, mysql.db, mysql.host and the" +echo "mysql.func tables to MySQL 3.22.14 and above." +echo "" +echo "This is needed if you want to use the new GRANT functions," +echo "CREATE AGGREGATE FUNCTION or want to use the more secure passwords in 3.23" +echo "" +echo "If you get 'Access denied' errors, you should run this script again" +echo "and give the MySQL root user password as an argument!" + echo "Converting all privilege tables to MyISAM format" $cmd <<END_OF_DATA ALTER TABLE user type=MyISAM; diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 1a969895f7f..96e33d3e7c5 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -87,7 +87,7 @@ if test -z "$basedir" then basedir=@prefix@ bindir=@bindir@ - execdir=@libexecdir@ + execdir=@libexecdir@ pkgdatadir=@pkgdatadir@ else bindir="$basedir/bin" @@ -100,24 +100,24 @@ else else execdir="$basedir/bin" fi - - # find fill_help_tables.sh - for i in $basedir/support-files $basedir/share $basedir/share/mysql $basedir/scripts @pkgdatadir@ - do - if test -f $i/fill_help_tables.sql - then - pkgdatadir=$i - fi - done fi +# find fill_help_tables.sh +for i in $basedir/support-files $basedir/share $basedir/share/mysql $basedir/scripts `pwd` @pkgdatadir@ +do + if test -f $i/fill_help_tables.sql + then + pkgdatadir=$i + fi +done + if test -f $pkgdatadir/fill_help_tables.sql then fill_help_tables=$pkgdatadir/fill_help_tables.sql else if test $verbose -eq 1 then - echo "Could not find help file 'fill_help_tables.sql'". + echo "Could not find help file 'fill_help_tables.sql' ;$pkgdatadir; ;$basedir;". fi fi @@ -147,7 +147,8 @@ then resolved=`$bindir/resolveip localhost 2>&1` if [ $? -eq 0 ] then - echo "Sorry, the host '$hostname' could not be looked up." + echo "Neither host '$hostname' and 'localhost' could not be looked up with" + echo "$bindir/resolveip" echo "Please configure the 'hostname' command to return a correct hostname." echo "If you want to solve this at a later stage, restart this script with" echo "the --force option" @@ -163,215 +164,29 @@ then fi # Create database directories mysql & test -if test "$in_rpm" -eq 0 || "$windows" -eq 0 -then + if test ! -d $ldata; then mkdir $ldata; chmod 700 $ldata ; fi if test ! -d $ldata/mysql; then mkdir $ldata/mysql; chmod 700 $ldata/mysql ; fi if test ! -d $ldata/test; then mkdir $ldata/test; chmod 700 $ldata/test ; fi if test -w / -a ! -z "$user"; then chown $user $ldata $ldata/mysql $ldata/test; fi -fi - -# Initialize variables -c_d="" i_d="" -c_h="" i_h="" -c_u="" i_u="" -c_f="" i_f="" -c_t="" c_c="" -# Check for old tables if test ! -f $mdata/db.frm then - if test $verbose -eq 1 ; then - echo "Preparing db table" - fi - # mysqld --bootstrap wants one command/line - c_d="$c_d CREATE TABLE db (" - c_d="$c_d Host char(60) binary DEFAULT '' NOT NULL," - c_d="$c_d Db char(64) binary DEFAULT '' NOT NULL," - c_d="$c_d User char(16) binary DEFAULT '' NOT NULL," - c_d="$c_d Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d References_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_d="$c_d PRIMARY KEY Host (Host,Db,User)," - c_d="$c_d KEY User (User)" - c_d="$c_d )" - c_d="$c_d comment='Database privileges';" - - i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); - INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');" -fi - -if test ! -f $mdata/host.frm -then - if test $verbose -eq 1 ; then - echo "Preparing host table" - fi - - c_h="$c_h CREATE TABLE host (" - c_h="$c_h Host char(60) binary DEFAULT '' NOT NULL," - c_h="$c_h Db char(64) binary DEFAULT '' NOT NULL," - c_h="$c_h Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h References_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_h="$c_h PRIMARY KEY Host (Host,Db)" - c_h="$c_h )" - c_h="$c_h comment='Host privileges; Merged with database privileges';" -fi - -if test ! -f $mdata/user.frm -then - if test $verbose -eq 1 ; then - echo "Preparing user table" - fi - - c_u="$c_u CREATE TABLE user (" - c_u="$c_u Host char(60) binary DEFAULT '' NOT NULL," - c_u="$c_u User char(16) binary DEFAULT '' NOT NULL," - c_u="$c_u Password char(45) binary DEFAULT '' NOT NULL," - c_u="$c_u Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Process_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u File_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u References_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Super_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL," - c_u="$c_u ssl_type enum('','ANY','X509', 'SPECIFIED') DEFAULT '' NOT NULL," - c_u="$c_u ssl_cipher BLOB NOT NULL," - c_u="$c_u x509_issuer BLOB NOT NULL," - c_u="$c_u x509_subject BLOB NOT NULL," - c_u="$c_u max_questions int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_updates int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_connections int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u PRIMARY KEY Host (Host,User)" - c_u="$c_u )" - c_u="$c_u comment='Users and global privileges';" - - i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - - REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - - INSERT INTO user (host,user) values ('localhost',''); -" - - if test "$windows" -eq 0 - then - i_u="$i_u INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - - REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - - INSERT INTO user (host,user) values ('$hostname','');" - fi -fi - -if test ! -f $mdata/func.frm -then - if test $verbose -eq 1 ; then - echo "Preparing func table" - fi - - c_f="$c_f CREATE TABLE func (" - c_f="$c_f name char(64) binary DEFAULT '' NOT NULL," - c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL," - c_f="$c_f dl char(128) DEFAULT '' NOT NULL," - c_f="$c_f type enum ('function','aggregate') NOT NULL," - c_f="$c_f PRIMARY KEY (name)" - c_f="$c_f )" - c_f="$c_f comment='User defined functions';" + c_d="yes" fi -if test ! -f $mdata/tables_priv.frm +if test $verbose -eq 1 then - if test $verbose -eq 1 ; then - echo "Preparing tables_priv table" - fi - - c_t="$c_t CREATE TABLE tables_priv (" - c_t="$c_t Host char(60) binary DEFAULT '' NOT NULL," - c_t="$c_t Db char(64) binary DEFAULT '' NOT NULL," - c_t="$c_t User char(16) binary DEFAULT '' NOT NULL," - c_t="$c_t Table_name char(60) binary DEFAULT '' NOT NULL," - c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL," - c_t="$c_t Timestamp timestamp(14)," - c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL," - c_t="$c_t Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," - c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name)," - c_t="$c_t KEY Grantor (Grantor)" - c_t="$c_t )" - c_t="$c_t comment='Table privileges';" -fi - -if test ! -f $mdata/columns_priv.frm -then - if test $verbose -eq 1 ; then - echo "Preparing columns_priv table" - fi - - c_c="$c_c CREATE TABLE columns_priv (" - c_c="$c_c Host char(60) binary DEFAULT '' NOT NULL," - c_c="$c_c Db char(64) binary DEFAULT '' NOT NULL," - c_c="$c_c User char(16) binary DEFAULT '' NOT NULL," - c_c="$c_c Table_name char(64) binary DEFAULT '' NOT NULL," - c_c="$c_c Column_name char(64) binary DEFAULT '' NOT NULL," - c_c="$c_c Timestamp timestamp(14)," - c_c="$c_c Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," - c_c="$c_c PRIMARY KEY (Host,Db,User,Table_name,Column_name)" - c_c="$c_c )" - c_c="$c_c comment='Column privileges';" + create_option="verbose" +else + create_option="real" fi -echo "Installing privilege tables" +echo "Installing all prepared tables" if ( - cat << END_OF_DATA -use mysql; -$c_d -$i_d - -$c_h -$i_h - -$c_u -$i_u - -$c_f -$i_f - -$c_t -$c_c -END_OF_DATA + mysql_create_system_tables $create_option $mdata $hostname $windows if test -n "$fill_help_tables" then cat $fill_help_tables diff --git a/scripts/mysql_setpermission.sh b/scripts/mysql_setpermission.sh index 43bf8a14c06..9699cd28047 100644 --- a/scripts/mysql_setpermission.sh +++ b/scripts/mysql_setpermission.sh @@ -16,20 +16,25 @@ ## 1.2 begin screen now in a loop + quit is using 0 instead of 9 ## after ideas of Paul DuBois. ## 1.2a Add Grant, References, Index and Alter privilege handling (Monty) +## 1.3 Applied patch provided by Martin Mokrejs <mmokrejs@natur.cuni.cz> +## (General code cleanup, use the GRANT statement instead of updating +## the privilege tables directly, added option to revoke privileges) #### TODO # # empty ... suggestions ... mail them to me ... -$version="1.2"; +$version="1.3"; use DBI; use Getopt::Long; use strict; -use vars qw($dbh $hostname $opt_user $opt_password $opt_help $opt_host +use vars qw($dbh $sth $hostname $opt_user $opt_password $opt_help $opt_host $opt_socket $opt_port $host $version); +my $sqlhost = ""; +my $user = ""; $dbh=$host=$opt_user= $opt_password= $opt_help= $opt_host= $opt_socket= ""; $opt_port=0; @@ -42,11 +47,11 @@ usage() if ($opt_help); # the help function if ($opt_host eq '') { - $hostname = "localhost"; + $sqlhost = "localhost"; } else { - $hostname = $opt_host; + $sqlhost = $opt_host; } # ask for a password if no password is set already @@ -62,7 +67,7 @@ if ($opt_password eq '') # make the connection to MySQL -$dbh= DBI->connect("DBI:mysql:mysql:host=$hostname:port=$opt_port:mysql_socket=$opt_socket",$opt_user,$opt_password, {PrintError => 0}) || +$dbh= DBI->connect("DBI:mysql:mysql:host=$sqlhost:port=$opt_port:mysql_socket=$opt_socket",$opt_user,$opt_password, {PrintError => 0}) || die("Can't make a connection to the mysql server.\n The error: $DBI::errstr"); # the start of the program @@ -86,27 +91,44 @@ sub q1 { # first question ... print "#"x70; print "\n"; print "What would you like to do:\n"; - print " 1. Set password for a user.\n"; - print " 2. Add a database + user privilege for that database.\n"; - print " - user can do all except all admin functions\n"; - print " 3. Add user privilege for an existing database.\n"; - print " - user can do all except all admin functions\n"; - print " 4. Add user privilege for an existing database.\n"; - print " - user can do all except all admin functions + no create/drop\n"; - print " 5. Add user privilege for an existing database.\n"; - print " - user can do only selects (no update/delete/insert etc.)\n"; + print " 1. Set password for an existing user.\n"; + print " 2. Create a database + user privilege for that database\n"; + print " and host combination (user can only do SELECT)\n"; + print " 3. Create/append user privilege for an existing database\n"; + print " and host combination (user can only do SELECT)\n"; + print " 4. Create/append broader user privileges for an existing\n"; + print " database and host combination\n"; + print " (user can do SELECT,INSERT,UPDATE,DELETE)\n"; + print " 5. Create/append quite extended user privileges for an\n"; + print " existing database and host combination (user can do\n"; + print " SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,\n"; + print " LOCK TABLES,CREATE TEMPORARY TABLES)\n"; + print " 6. Create/append database administrative privileges for an\n"; + print " existing database and host combination (user can do\n"; + print " SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,\n"; + print " CREATE TEMPORARY TABLES,SHOW DATABASES,PROCESS)\n"; + print " 7. Create/append full privileges for an existing database\n"; + print " and host combination (user has FULL privilege)\n"; + print " 8. Remove all privileges for for an existing database and\n"; + print " host combination.\n"; + print " (user will have all permission fields set to N)\n"; print " 0. exit this program\n"; - print "\nMake your choice [1,2,3,4,5,0]: "; + print "\nMake your choice [1,2,3,4,5,6,7,0]: "; while (<STDIN>) { $answer = $_; chomp($answer); - if ($answer =~ /1|2|3|4|5|0/) { - &setpwd if ($answer == 1); - &addall($answer) if ($answer =~ /^[2345]$/); - if ($answer == 0) { - print "Sorry, hope we can help you next time \n\n"; + if ($answer =~ /^[12345678]$/) { + if ($answer == 1) { + setpwd(); + } elsif ($answer =~ /^[2345678]$/) { + addall($answer); + } else { + print "Sorry, something went wrong. With such option number you should not get here.\n\n"; $end = 1; } + } elsif ($answer == 0) { + print "We hope we can help you next time \n\n"; + $end = 1; } else { print "Your answer was $answer\n"; print "and that's wrong .... Try again\n"; @@ -121,7 +143,7 @@ sub q1 { # first question ... ### sub setpwd { - my ($user,$pass,$host); + my ($user,$pass,$host) = ""; print "\n\nSetting a (new) password for a user.\n"; $user = user(); @@ -168,22 +190,18 @@ sub setpwd ### # all things which will be added are done here ### -sub addall -{ +sub addall { my ($todo) = @_; my ($answer,$good,$db,$user,$pass,$host,$priv); - if ($todo == 2) - { + if ($todo == 2) { $db = newdatabase(); - } - else - { + } else { $db = database(); } $user = newuser(); - $pass = newpass(); + $pass = newpass("$user"); $host = newhosts(); print "#"x70; @@ -198,104 +216,80 @@ sub addall print "Are you pretty sure you would like to implement this [yes/no]: "; my $no = <STDIN>; chomp($no); - if ($no =~ /n/i) - { + if ($no =~ /n/i) { print "Okay .. that was it then ... See ya\n\n"; return(0); - } - else - { + } else { print "Okay ... let's go then ...\n\n"; } - if ($todo == 2) - { + if ($todo == 2) { # create the database - my $sth = $dbh->do("create database $db") || $dbh->errstr; - } - - # select the privilege .... - if (($todo == 2) || ($todo == 3)) - { - $priv = "'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'"; + if ($db) { + my $sth = $dbh->do("CREATE DATABASE $db") || $dbh->errstr; + } else { + print STDERR "What do you want? You wanted to create new database and add new user, right?\n"; + die "But then specify databasename, please\n"; } - elsif ($todo == 4) - { - $priv = "'Y','Y','Y','Y','N','N','N','Y','Y','Y'"; } - elsif ($todo == 5) - { - $priv = "'Y','N','N','N','N','N','N','N','N','N'"; - } - else - { - print "Sorry, choice number $todo isn't known inside the program .. See ya\n"; + + if ( ( !$todo ) or not ( $todo =~ m/^[2-8]$/ ) ) { + print STDERR "Sorry, select option $todo isn't known inside the program .. See ya\n"; quit(); } my @hosts = split(/,/,$host); - $user = $dbh->quote($user); - $db = $dbh->quote($db); - if ($pass eq '') - { - $pass = "''"; + if (!$user) { + die "username not specified: $user\n"; } - else - { - $pass = "PASSWORD(". $dbh->quote($pass) . ")"; + if (!$db) { + die "databasename is not specified nor *\n"; } - foreach my $key (@hosts) - { - my $key1 = $dbh->quote($key); - my $sth = $dbh->prepare("select Host,User from user where Host = $key1 and User = $user") || die $dbh->errstr; - $sth->execute || die $dbh->errstr; - my @r = $sth->fetchrow_array; - if ($r[0]) - { - print "WARNING WARNING SKIPPING CREATE FOR USER $user AND HOST $key\n"; - print "Reason: entry already exists in the user table.\n"; + foreach $host (@hosts) { + # user privileges: SELECT + if (($todo == 2) || ($todo == 3)) { + $sth = $dbh->do("GRANT SELECT ON $db.* TO $user@\"$host\" IDENTIFIED BY \'$pass\'") || die $dbh->errstr; + } elsif ($todo == 4) { + # user privileges: SELECT,INSERT,UPDATE,DELETE + $sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE ON $db.* TO $user@\"$host\" IDENTIFIED BY \'$pass\'") || die $dbh->errstr; + } elsif ($todo == 5) { + # user privileges: SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES + $sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES ON $db.* TO $user@\"$host\" IDENTIFIED BY \'$pass\'") || die $dbh->errstr; + } elsif ($todo == 6) { + # admin privileges: GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES,SHOW DATABASES,PROCESS + $sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES,SHOW DATABASES,PROCESS ON $db.* TO $user@\"$host\" IDENTIFIED BY \'$pass\'") || die $dbh->errstr; + } elsif ($todo == 7) { + # all privileges + $sth = $dbh->do("GRANT ALL ON $db.* TO \'$user\'\@\'$host\' IDENTIFIED BY \'$pass\'") || die $dbh->errstr; + } elsif ($todo == 8) { + # all privileges set to N + $sth = $dbh->do("REVOKE ALL ON *.* FROM \'$user\'\@\'$host\'") || die $dbh->errstr; } - else - { - $sth = $dbh->prepare("insert into user (Host,User,Password) values($key1,$user,$pass)") || die $dbh->errstr; - $sth->execute || die $dbh->errstr; - $sth->finish; } - $sth = $dbh->prepare("INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES ($key1,$db,$user,$priv)") || die $dbh->errstr; - $sth->execute || die $dbh->errstr; - $sth->finish; - } - $dbh->do("flush privileges") || print "Can't load privileges\n"; + $dbh->do("FLUSH PRIVILEGES") || print STDERR "Can't flush privileges\n"; print "Everything is inserted and mysql privileges have been reloaded.\n\n"; } ### # ask for a new database name ### -sub newdatabase -{ +sub newdatabase { my ($answer,$good,$db); print "\n\nWhich database would you like to add: "; - while (<STDIN>) - { + while (<STDIN>) { $answer = $_; $good = 0; chomp($answer); - if ($answer) - { - my $sth = $dbh->prepare("show databases") || die $dbh->errstr; + if ($answer) { + my $sth = $dbh->prepare("SHOW DATABASES") || die $dbh->errstr; $sth->execute || die $dbh->errstr; - while (my @r = $sth->fetchrow_array) - { - if ($r[0] eq $answer) - { + while (my @r = $sth->fetchrow_array) { + if ($r[0] eq $answer) { print "\n\nSorry, this database name is already in use; try something else: "; $good = 1; } } - } - else - { + } else { print "You must type something ...\nTry again: "; next; } @@ -309,48 +303,44 @@ sub newdatabase ### # select a database ### -sub database -{ +sub database { my ($answer,$good,$db); - print "\n\nWhich database would you like to select: \n"; + print "\n\nWhich database from existing databases would you like to select: \n"; print "You can choose from: \n"; my $sth = $dbh->prepare("show databases") || die $dbh->errstr; $sth->execute || die $dbh->errstr; - while (my @r = $sth->fetchrow_array) - { + while (my @r = $sth->fetchrow_array) { print " - $r[0] \n"; } - print "Which database will it be (case sensitive): "; - while (<STDIN>) - { + print "Which database will it be (case sensitive). Type * for any: \n"; + while (<STDIN>) { $answer = $_; $good = 0; chomp($answer); - if ($answer) - { + if ($answer) { + if ($answer eq "*") { + print "OK, the user entry will NOT be limited to any database"; + return("*"); + } my $sth = $dbh->prepare("show databases") || die $dbh->errstr; $sth->execute || die $dbh->errstr; - while (my @r = $sth->fetchrow_array) - { - if ($r[0] eq $answer) - { + while (my @r = $sth->fetchrow_array) { + if ($r[0] eq $answer) { $good = 1; $db = $r[0]; last; } } - } - else - { - print "You must type something ...\nTry again: "; + } else { + print "Type either database name or * meaning any databasename. That means"; + print " any of those above but also any which will be created in future!"; + print " This option gives a user chance to operate on databse mysql, which"; + print " contains privilege settings. That is really risky!\n"; next; } - if ($good == 1) - { + if ($good == 1) { last; - } - else - { + } else { print "You must select one from the list.\nTry again: "; next; } @@ -364,7 +354,8 @@ sub database ### sub newuser { - my ($answer,$user); + my $user = ""; + my $answer = ""; print "\nWhat username is to be created: "; while(<STDIN>) @@ -430,7 +421,7 @@ sub user sub newpass { my ($user) = @_; - my ($answer,$good,$pass,$yes); + my ($pass,$answer,$good,$yes); print "Would you like to set a password for $user [y/n]: "; $yes = <STDIN>; @@ -487,7 +478,7 @@ sub newpass ### sub newhosts { - my ($answer,$good,$host); + my ($host,$answer,$good); print "We now need to know from what host(s) the user will connect.\n"; print "Keep in mind that % means 'from any host' ...\n"; diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 094b1fbfcd3..e400c27b84c 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -224,7 +224,7 @@ then if test -n "$open_files" then ulimit -n $open_files - args="open-files-limit=$open_files $args" + args="--open-files-limit=$open_files $args" fi if test -n "$core_file_size" then diff --git a/scripts/mysqlhotcopy.sh b/scripts/mysqlhotcopy.sh index ec76aa479f3..a89a8919752 100644 --- a/scripts/mysqlhotcopy.sh +++ b/scripts/mysqlhotcopy.sh @@ -55,7 +55,8 @@ Usage: $0 db_name[./table_regex/] [new_db_name | directory] -P, --port=# port to use when connecting to local server with TCP/IP -S, --socket=# socket to use when connecting to local server - --allowold don\'t abort if target already exists (rename it _old) + --allowold don\'t abort if target dir already exists (rename it _old) + --addtodest don\'t rename target dir if it exists, just add files to it --keepold don\'t delete previous (now renamed) target when done --noindices don\'t include full index files in copy --method=# method for copy (only "cp" currently supported) @@ -98,6 +99,7 @@ GetOptions( \%opt, "socket|S=s", "allowold!", "keepold!", + "addtodest!", "noindices!", "method=s", "debug", @@ -380,14 +382,14 @@ if ($opt{method} =~ /^cp\b/) push @existing, $rdb->{target} if ( -d $rdb->{target} ); } - if ( @existing && !$opt{allowold} ) + if ( @existing && !($opt{allowold} || $opt{addtodest}) ) { $dbh->disconnect(); - die "Can't hotcopy to '", join( "','", @existing ), "' because directory\nalready exist and the --allowold option was not given.\n" + die "Can't hotcopy to '", join( "','", @existing ), "' because directory\nalready exist and the --allowold or --addtodest options were not given.\n" } } -retire_directory( @existing ) if ( @existing ); +retire_directory( @existing ) if @existing && !$opt{addtodest}; foreach my $rdb ( @db_desc ) { foreach my $td ( '', @{$rdb->{raid_dirs}} ) { @@ -403,8 +405,8 @@ foreach my $rdb ( @db_desc ) { ## ... } else { - mkdir($tgt_dirpath, 0750) - or die "Can't create '$tgt_dirpath': $!\n"; + mkdir($tgt_dirpath, 0750) or die "Can't create '$tgt_dirpath': $!\n" + unless -d $tgt_dirpath; } } } @@ -861,6 +863,22 @@ Any existing versions of the backup directory are deleted. Behaves as for the --allowold, with the additional feature of keeping the backup directory after the copy successfully completes. +=item --addtodest + +Don't rename target directory if it already exists, just add the +copied files into it. + +This is most useful when backing up a database with many large +tables and you don't want to have all the tables locked for the +whole duration. + +In this situation, I<if> you are happy for groups of tables to be +backed up separately (and thus possibly not be logically consistant +with one another) then you can run mysqlhotcopy several times on +the same database each with different db_name./table_regex/. +All but the first should use the --addtodest option so the tables +all end up in the same directory. + =item --flushlog Rotate the log files by executing "FLUSH LOGS" after all tables are @@ -869,13 +887,13 @@ locked, and before they are copied. =item --resetmaster Reset the bin-log by executing "RESET MASTER" after all tables are -locked, and before they are copied. Usefull if you are recovering a +locked, and before they are copied. Useful if you are recovering a slave in a replication setup. =item --resetslave Reset the master.info by executing "RESET SLAVE" after all tables are -locked, and before they are copied. Usefull if you are recovering a +locked, and before they are copied. Useful if you are recovering a server in a mutual replication setup. =item --regexp pattern @@ -941,7 +959,7 @@ will vary with your ability to understand how scp works. 'man scp' and 'man ssh' are your friends. The destination directory _must exist_ on the target machine using the -scp method. --keepold and --allowold are meeningless with scp. +scp method. --keepold and --allowold are meaningless with scp. Liberal use of the --debug option will help you figure out what\'s really going on when you do an scp. diff --git a/sql-bench/Makefile.am b/sql-bench/Makefile.am index ab6be7269e3..579a2a9f7fe 100644 --- a/sql-bench/Makefile.am +++ b/sql-bench/Makefile.am @@ -41,12 +41,9 @@ EXTRA_DIST = $(EXTRA_SCRIPTS) dist-hook: mkdir -p $(distdir)/Data/ATIS $(distdir)/Data/Wisconsin \ - $(distdir)/Results $(distdir)/Results-win32 \ $(distdir)/limits $(distdir)/Comments for i in $(srcdir)/Data/ATIS/*.* ; do $(INSTALL_DATA) $$i $(distdir)/Data/ATIS ; done for i in $(srcdir)/Data/Wisconsin/*.* ; do $(INSTALL_DATA) $$i $(distdir)/Data/Wisconsin ; done - for i in $(srcdir)/Results/*-* ; do $(INSTALL_DATA) $$i $(distdir)/Results; done - for i in $(srcdir)/Results-win32/*-* ; do $(INSTALL_DATA) $$i $(distdir)/Results-win32; done for i in $(srcdir)/limits/*.* ; do $(INSTALL_DATA) $$i $(distdir)/limits; done for i in $(srcdir)/Comments/*.* ; do $(INSTALL_DATA) $$i $(distdir)/Comments; done @@ -55,15 +52,11 @@ install-data-local: $(DESTDIR)$(benchdir)/Data \ $(DESTDIR)$(benchdir)/Data/ATIS \ $(DESTDIR)$(benchdir)/Data/Wisconsin \ - $(DESTDIR)$(benchdir)/Results \ - $(DESTDIR)$(benchdir)/Results-win32 \ $(DESTDIR)$(benchdir)/limits \ $(DESTDIR)$(benchdir)/Comments $(INSTALL_DATA) $(srcdir)/README $(DESTDIR)$(benchdir) for i in $(srcdir)/Data/ATIS/*.* ; do $(INSTALL_DATA) $$i $(DESTDIR)$(benchdir)/Data/ATIS ; done for i in $(srcdir)/Data/Wisconsin/*.* ; do $(INSTALL_DATA) $$i $(DESTDIR)$(benchdir)/Data/Wisconsin ; done - for i in $(srcdir)/Results/*-* ; do $(INSTALL_DATA) $$i $(DESTDIR)$(benchdir)/Results; done - for i in $(srcdir)/Results-win32/*-* ; do $(INSTALL_DATA) $$i $(DESTDIR)$(benchdir)/Results-win32; done for i in $(srcdir)/limits/*.* ; do $(INSTALL_DATA) $$i $(DESTDIR)$(benchdir)/limits; done for i in $(srcdir)/Comments/*.* ; do $(INSTALL_DATA) $$i $(DESTDIR)$(benchdir)/Comments; done diff --git a/sql-bench/crash-me.sh b/sql-bench/crash-me.sh index 61468d69fb1..ff649acdae4 100644 --- a/sql-bench/crash-me.sh +++ b/sql-bench/crash-me.sh @@ -2734,6 +2734,51 @@ assert("drop table crash_me_n $drop_attr"); +$key = 'sorted_group_by'; +$prompt = 'Group by always sorted'; +if (!defined($limits{$key})) +{ + save_incomplete($key,$prompt); + print "$prompt="; + safe_query_l($key,[ + "create table crash_me_t1 (a int not null, b int not null)", + "insert into crash_me_t1 values (1,1)", + "insert into crash_me_t1 values (1,2)", + "insert into crash_me_t1 values (3,1)", + "insert into crash_me_t1 values (3,2)", + "insert into crash_me_t1 values (2,2)", + "insert into crash_me_t1 values (2,1)", + "create table crash_me_t2 (a int not null, b int not null)", + "create index crash_me_t2_ind on crash_me_t2 (a)", + "insert into crash_me_t2 values (1,3)", + "insert into crash_me_t2 values (3,1)", + "insert into crash_me_t2 values (2,2)", + "insert into crash_me_t2 values (1,1)"]); + + my $bigqry = "select crash_me_t1.a,crash_me_t2.b from ". + "crash_me_t1,crash_me_t2 where crash_me_t1.a=crash_me_t2.a ". + "group by crash_me_t1.a,crash_me_t2.b"; + + my $limit='no'; + my $rs = get_recordset($key,$bigqry); + print_recordset($key,$rs); + if ( defined ($rs)) { + if (compare_recordset($key,$rs,[[1,1],[1,3],[2,2],[3,1]]) eq 0) + { + $limit='yes' + } + } else { + add_log($key,"error: ".$DBI::errstr); + } + + print "$limit\n"; + safe_query_l($key,["drop table crash_me_t1", + "drop table crash_me_t2"]); + save_config_data($key,$limit,$prompt); + +} else { + print "$prompt=$limits{$key} (cashed)\n"; +} # diff --git a/sql-common/client.c b/sql-common/client.c new file mode 100644 index 00000000000..4baee2d2477 --- /dev/null +++ b/sql-common/client.c @@ -0,0 +1,2364 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + This file is included by both libmysql.c (the MySQL client C API) + and the mysqld server to connect to another MYSQL server. + + The differences for the two cases are: + + - Things that only works for the client: + - Trying to automaticly determinate user name if not supplied to + mysql_real_connect() + - Support for reading local file with LOAD DATA LOCAL + - SHARED memory handling + - Protection against sigpipe + - Prepared statements + + - Things that only works for the server + - Alarm handling on connect + + In all other cases, the code should be idential for the client and + server. +*/ + +#include <my_global.h> + +#if defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT) + +#include "mysql.h" +#if !defined(MYSQL_SERVER) && defined(__WIN__) || defined(_WIN32) || defined(_WIN64) +#include <winsock.h> +#include <odbcinst.h> +#endif +#include <my_sys.h> +#include <mysys_err.h> +#include <m_string.h> +#include <m_ctype.h> +#include "mysql_version.h" +#include "mysqld_error.h" +#include "errmsg.h" +#include <violite.h> +#include <assert.h> +#if defined(THREAD) && !defined(__WIN__) +#include <my_pthread.h> /* because of signal() */ +#endif + +#if defined( OS2) && defined(MYSQL_SERVER) +#undef ER +#define ER CER +#endif + +#include <sys/stat.h> +#include <signal.h> +#include <time.h> + +#ifdef HAVE_PWD_H +#include <pwd.h> +#endif + +#if !defined(MSDOS) && !defined(__WIN__) +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#ifdef HAVE_SELECT_H +# include <select.h> +#endif +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +#endif /*!defined(MSDOS) && !defined(__WIN__) */ +#ifdef HAVE_SYS_UN_H +# include <sys/un.h> +#endif + +#ifndef INADDR_NONE +#define INADDR_NONE -1 +#endif +#if defined(MSDOS) || defined(__WIN__) +#define perror(A) +#else +#include <errno.h> +#define SOCKET_ERROR -1 +#endif + +#include "client_settings.h" +#include <sql_common.h> + +const char *unknown_sqlstate= "000000"; + +/**************************************************************************** + A modified version of connect(). my_connect() allows you to specify + a timeout value, in seconds, that we should wait until we + derermine we can't connect to a particular host. If timeout is 0, + my_connect() will behave exactly like connect(). + + Base version coded by Steve Bernacki, Jr. <steve@navinet.net> +*****************************************************************************/ + +my_bool my_connect(my_socket s, const struct sockaddr *name, + uint namelen, uint timeout) +{ +#if defined(__WIN__) || defined(OS2) || defined(__NETWARE__) + return connect(s, (struct sockaddr*) name, namelen) != 0; +#else + int flags, res, s_err; + SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint); + fd_set sfds; + struct timeval tv; + time_t start_time, now_time; + + /* + If they passed us a timeout of zero, we should behave + exactly like the normal connect() call does. + */ + + if (timeout == 0) + return connect(s, (struct sockaddr*) name, namelen) != 0; + + flags = fcntl(s, F_GETFL, 0); /* Set socket to not block */ +#ifdef O_NONBLOCK + fcntl(s, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ +#endif + + res = connect(s, (struct sockaddr*) name, namelen); + s_err = errno; /* Save the error... */ + fcntl(s, F_SETFL, flags); + if ((res != 0) && (s_err != EINPROGRESS)) + { + errno = s_err; /* Restore it */ + return(1); + } + if (res == 0) /* Connected quickly! */ + return(0); + + /* + Otherwise, our connection is "in progress." We can use + the select() call to wait up to a specified period of time + for the connection to succeed. If select() returns 0 + (after waiting howevermany seconds), our socket never became + writable (host is probably unreachable.) Otherwise, if + select() returns 1, then one of two conditions exist: + + 1. An error occured. We use getsockopt() to check for this. + 2. The connection was set up sucessfully: getsockopt() will + return 0 as an error. + + Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> + who posted this method of timing out a connect() in + comp.unix.programmer on August 15th, 1997. + */ + + FD_ZERO(&sfds); + FD_SET(s, &sfds); + /* + select could be interrupted by a signal, and if it is, + the timeout should be adjusted and the select restarted + to work around OSes that don't restart select and + implementations of select that don't adjust tv upon + failure to reflect the time remaining + */ + start_time = time(NULL); + for (;;) + { + tv.tv_sec = (long) timeout; + tv.tv_usec = 0; +#if defined(HPUX10) && defined(THREAD) + if ((res = select(s+1, NULL, (int*) &sfds, NULL, &tv)) > 0) + break; +#else + if ((res = select(s+1, NULL, &sfds, NULL, &tv)) > 0) + break; +#endif + if (res == 0) /* timeout */ + return -1; + now_time=time(NULL); + timeout-= (uint) (now_time - start_time); + if (errno != EINTR || (int) timeout <= 0) + return 1; + } + + /* + select() returned something more interesting than zero, let's + see if we have any errors. If the next two statements pass, + we've got an open socket! + */ + + s_err=0; + if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) + return(1); + + if (s_err) + { /* getsockopt could succeed */ + errno = s_err; + return(1); /* but return an error... */ + } + return (0); /* ok */ + +#endif +} + +/* + Create a named pipe connection +*/ + +#ifdef __WIN__ + +HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, + char **arg_unix_socket) +{ + HANDLE hPipe=INVALID_HANDLE_VALUE; + char szPipeName [ 257 ]; + DWORD dwMode; + int i; + my_bool testing_named_pipes=0; + char *host= *arg_host, *unix_socket= *arg_unix_socket; + + if ( ! unix_socket || (unix_socket)[0] == 0x00) + unix_socket = mysql_unix_port; + if (!host || !strcmp(host,LOCAL_HOST)) + host=LOCAL_HOST_NAMEDPIPE; + + sprintf( szPipeName, "\\\\%s\\pipe\\%s", host, unix_socket); + DBUG_PRINT("info",("Server name: '%s'. Named Pipe: %s", + host, unix_socket)); + + for (i=0 ; i < 100 ; i++) /* Don't retry forever */ + { + if ((hPipe = CreateFile(szPipeName, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + 0, + NULL )) != INVALID_HANDLE_VALUE) + break; + if (GetLastError() != ERROR_PIPE_BUSY) + { + net->last_errno=CR_NAMEDPIPEOPEN_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + /* wait for for an other instance */ + if (! WaitNamedPipe(szPipeName, connect_timeout*1000) ) + { + net->last_errno=CR_NAMEDPIPEWAIT_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + } + if (hPipe == INVALID_HANDLE_VALUE) + { + net->last_errno=CR_NAMEDPIPEOPEN_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + dwMode = PIPE_READMODE_BYTE | PIPE_WAIT; + if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) ) + { + CloseHandle( hPipe ); + net->last_errno=CR_NAMEDPIPESETSTATE_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + *arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */ + return (hPipe); +} +#endif + +/***************************************************************************** + Read a packet from server. Give error message if socket was down + or packet is an error message +*****************************************************************************/ + +ulong +net_safe_read(MYSQL *mysql) +{ + NET *net= &mysql->net; + ulong len=0; + init_sigpipe_variables + + /* Don't give sigpipe errors if the client doesn't want them */ + set_sigpipe(mysql); + if (net->vio != 0) + len=my_net_read(net); + reset_sigpipe(mysql); + + if (len == packet_error || len == 0) + { + DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", + vio_description(net->vio),len)); + end_server(mysql); + net->last_errno=(net->last_errno == ER_NET_PACKET_TOO_LARGE ? + CR_NET_PACKET_TOO_LARGE: + CR_SERVER_LOST); + strmov(net->last_error,ER(net->last_errno)); + strmov(net->sqlstate, unknown_sqlstate); + return (packet_error); + } + if (net->read_pos[0] == 255) + { + if (len > 3) + { + char *pos=(char*) net->read_pos+1; + net->last_errno=uint2korr(pos); + pos+=2; + len-=2; + if (protocol_41(mysql) && pos[0] == '#') + { + strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + pos+= SQLSTATE_LENGTH+1; + } + (void) strmake(net->last_error,(char*) pos, + min((uint) len,(uint) sizeof(net->last_error)-1)); + } + else + { + net->last_errno=CR_UNKNOWN_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + } + DBUG_PRINT("error",("Got error: %d/%s (%s)", + net->last_errno, net->sqlstate, net->last_error)); + return(packet_error); + } + return len; +} + +void free_rows(MYSQL_DATA *cur) +{ + if (cur) + { + free_root(&cur->alloc,MYF(0)); + my_free((gptr) cur,MYF(0)); + } +} + +my_bool +advanced_command(MYSQL *mysql, enum enum_server_command command, + const char *header, ulong header_length, + const char *arg, ulong arg_length, my_bool skip_check) +{ + NET *net= &mysql->net; + my_bool result= 1; + init_sigpipe_variables + + /* Don't give sigpipe errors if the client doesn't want them */ + set_sigpipe(mysql); + + if (mysql->net.vio == 0) + { /* Do reconnect if possible */ + if (mysql_reconnect(mysql)) + return 1; + } + if (mysql->status != MYSQL_STATUS_READY) + { + strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); + strmov(net->sqlstate, unknown_sqlstate); + return 1; + } + + net->last_error[0]=0; + net->last_errno=0; + strmov(net->sqlstate, unknown_sqlstate); + mysql->net.report_error=0; + mysql->info=0; + mysql->affected_rows= ~(my_ulonglong) 0; + net_clear(&mysql->net); /* Clear receive buffer */ + if (!arg) + arg=""; + + if (net_write_command(net,(uchar) command, header, header_length, + arg, arg_length)) + { + DBUG_PRINT("error",("Can't send command to server. Error: %d", + socket_errno)); + if (net->last_errno == ER_NET_PACKET_TOO_LARGE) + { + net->last_errno=CR_NET_PACKET_TOO_LARGE; + strmov(net->last_error,ER(net->last_errno)); + goto end; + } + end_server(mysql); + if (mysql_reconnect(mysql)) + goto end; + if (net_write_command(net,(uchar) command, header, header_length, + arg, arg_length)) + { + net->last_errno=CR_SERVER_GONE_ERROR; + strmov(net->last_error,ER(net->last_errno)); + goto end; + } + } + result=0; + if (!skip_check) + result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ? + 1 : 0); + end: + reset_sigpipe(mysql); + return result; +} + +my_bool +simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + ulong length, my_bool skip_check) +{ + return advanced_command(mysql, command, NullS, 0, arg, length, skip_check); +} + +void free_old_query(MYSQL *mysql) +{ + DBUG_ENTER("free_old_query"); + if (mysql->fields) + free_root(&mysql->field_alloc,MYF(0)); + else + init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ + mysql->fields=0; + mysql->field_count=0; /* For API */ + DBUG_VOID_RETURN; +} + +#ifdef __WIN__ +static my_bool is_NT(void) +{ + char *os=getenv("OS"); + return (os && !strcmp(os, "Windows_NT")) ? 1 : 0; +} +#endif + +/************************************************************************** + Shut down connection +**************************************************************************/ + +void end_server(MYSQL *mysql) +{ + DBUG_ENTER("end_server"); + if (mysql->net.vio != 0) + { + init_sigpipe_variables + DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio))); + set_sigpipe(mysql); + vio_delete(mysql->net.vio); + reset_sigpipe(mysql); + mysql->net.vio= 0; /* Marker */ + } + net_end(&mysql->net); + free_old_query(mysql); + DBUG_VOID_RETURN; +} + +void STDCALL +mysql_free_result(MYSQL_RES *result) +{ + DBUG_ENTER("mysql_free_result"); + DBUG_PRINT("enter",("mysql_res: %lx",result)); + if (result) + { + if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) + { + DBUG_PRINT("warning",("Not all rows in set where read; Ignoring rows")); + for (;;) + { + ulong pkt_len; + if ((pkt_len=net_safe_read(result->handle)) == packet_error) + break; + if (pkt_len <= 8 && result->handle->net.read_pos[0] == 254) + break; /* End of data */ + } + result->handle->status=MYSQL_STATUS_READY; + } + free_rows(result->data); + if (result->fields) + free_root(&result->field_alloc,MYF(0)); + if (result->row) + my_free((gptr) result->row,MYF(0)); + my_free((gptr) result,MYF(0)); + } + DBUG_VOID_RETURN; +} + +/**************************************************************************** + Get options from my.cnf +****************************************************************************/ + +static const char *default_options[]= +{ + "port","socket","compress","password","pipe", "timeout", "user", + "init-command", "host", "database", "debug", "return-found-rows", + "ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath", + "character-sets-dir", "default-character-set", "interactive-timeout", + "connect-timeout", "local-infile", "disable-local-infile", + "replication-probe", "enable-reads-from-master", "repl-parse-query", + "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", + "multi-results", "multi-queries", + NullS +}; + +static TYPELIB option_types={array_elements(default_options)-1, + "options",default_options}; + +static int add_init_command(struct st_mysql_options *options, const char *cmd) +{ + char *tmp; + + if (!options->init_commands) + { + options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY), + MYF(MY_WME)); + init_dynamic_array(options->init_commands,sizeof(char*),0,5 CALLER_INFO); + } + + if (!(tmp= my_strdup(cmd,MYF(MY_WME))) || + insert_dynamic(options->init_commands, (gptr)&tmp)) + { + my_free(tmp, MYF(MY_ALLOW_ZERO_PTR)); + return 1; + } + + return 0; +} + +static void mysql_read_default_options(struct st_mysql_options *options, + const char *filename,const char *group) +{ + int argc; + char *argv_buff[1],**argv; + const char *groups[3]; + DBUG_ENTER("mysql_read_default_options"); + DBUG_PRINT("enter",("file: %s group: %s",filename,group ? group :"NULL")); + + argc=1; argv=argv_buff; argv_buff[0]= (char*) "client"; + groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0; + + load_defaults(filename, groups, &argc, &argv); + if (argc != 1) /* If some default option */ + { + char **option=argv; + while (*++option) + { + /* DBUG_PRINT("info",("option: %s",option[0])); */ + if (option[0][0] == '-' && option[0][1] == '-') + { + char *end=strcend(*option,'='); + char *opt_arg=0; + if (*end) + { + opt_arg=end+1; + *end=0; /* Remove '=' */ + } + /* Change all '_' in variable name to '-' */ + for (end= *option ; *(end= strcend(end,'_')) ; ) + *end= '-'; + switch (find_type(*option+2,&option_types,2)) { + case 1: /* port */ + if (opt_arg) + options->port=atoi(opt_arg); + break; + case 2: /* socket */ + if (opt_arg) + { + my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR)); + options->unix_socket=my_strdup(opt_arg,MYF(MY_WME)); + } + break; + case 3: /* compress */ + options->compress=1; + options->client_flag|= CLIENT_COMPRESS; + break; + case 4: /* password */ + if (opt_arg) + { + my_free(options->password,MYF(MY_ALLOW_ZERO_PTR)); + options->password=my_strdup(opt_arg,MYF(MY_WME)); + } + break; + case 5: + options->protocol = MYSQL_PROTOCOL_PIPE; + case 20: /* connect_timeout */ + case 6: /* timeout */ + if (opt_arg) + options->connect_timeout=atoi(opt_arg); + break; + case 7: /* user */ + if (opt_arg) + { + my_free(options->user,MYF(MY_ALLOW_ZERO_PTR)); + options->user=my_strdup(opt_arg,MYF(MY_WME)); + } + break; + case 8: /* init-command */ + add_init_command(options,opt_arg); + break; + case 9: /* host */ + if (opt_arg) + { + my_free(options->host,MYF(MY_ALLOW_ZERO_PTR)); + options->host=my_strdup(opt_arg,MYF(MY_WME)); + } + break; + case 10: /* database */ + if (opt_arg) + { + my_free(options->db,MYF(MY_ALLOW_ZERO_PTR)); + options->db=my_strdup(opt_arg,MYF(MY_WME)); + } + break; +#ifdef MYSQL_CLIENT + case 11: /* debug */ + mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); + break; +#endif + case 12: /* return-found-rows */ + options->client_flag|=CLIENT_FOUND_ROWS; + break; +#ifdef HAVE_OPENSSL + case 13: /* ssl_key */ + my_free(options->ssl_key, MYF(MY_ALLOW_ZERO_PTR)); + options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); + break; + case 14: /* ssl_cert */ + my_free(options->ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); + options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); + break; + case 15: /* ssl_ca */ + my_free(options->ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); + options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); + break; + case 16: /* ssl_capath */ + my_free(options->ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); + options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); + break; +#else + case 13: /* Ignore SSL options */ + case 14: + case 15: + case 16: + break; +#endif /* HAVE_OPENSSL */ + case 17: /* charset-lib */ + my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR)); + options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); + break; + case 18: + my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR)); + options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); + break; + case 19: /* Interactive-timeout */ + options->client_flag|= CLIENT_INTERACTIVE; + break; + case 21: + if (!opt_arg || atoi(opt_arg) != 0) + options->client_flag|= CLIENT_LOCAL_FILES; + else + options->client_flag&= ~CLIENT_LOCAL_FILES; + break; + case 22: + options->client_flag&= CLIENT_LOCAL_FILES; + break; + case 23: /* replication probe */ + options->rpl_probe= 1; + break; + case 24: /* enable-reads-from-master */ + options->no_master_reads= 0; + break; + case 25: /* repl-parse-query */ + options->rpl_parse= 1; + break; + case 27: + options->max_allowed_packet= atoi(opt_arg); + break; +#ifdef MYSQL_CLIENT + case 28: /* protocol */ + if ((options->protocol = find_type(opt_arg, &sql_protocol_typelib,0)) == ~(ulong) 0) + { + fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg); + exit(1); + } + break; +#endif + case 29: /* shared_memory_base_name */ +#ifdef HAVE_SMEM + if (options->shared_memory_base_name != def_shared_memory_base_name) + my_free(options->shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); + options->shared_memory_base_name=my_strdup(opt_arg,MYF(MY_WME)); +#endif + break; + case 30: + options->client_flag|= CLIENT_MULTI_RESULTS; + break; + case 31: + options->client_flag|= CLIENT_MULTI_QUERIES | CLIENT_MULTI_RESULTS; + break; + default: + DBUG_PRINT("warning",("unknown option: %s",option[0])); + } + } + } + } + free_defaults(argv); + DBUG_VOID_RETURN; +} + +/************************************************************************** + Get column lengths of the current row + If one uses mysql_use_result, res->lengths contains the length information, + else the lengths are calculated from the offset between pointers. +**************************************************************************/ + +void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count) +{ + ulong *prev_length; + byte *start=0; + MYSQL_ROW end; + + prev_length=0; /* Keep gcc happy */ + for (end=column + field_count + 1 ; column != end ; column++, to++) + { + if (!*column) + { + *to= 0; /* Null */ + continue; + } + if (start) /* Found end of prev string */ + *prev_length= (ulong) (*column-start-1); + start= *column; + prev_length= to; + } +} + + +static inline void +unpack_fields_40(MYSQL_ROWS *row, MYSQL_FIELD *field, MEM_ROOT *alloc, + ulong *lengths, uint n_lengths, + my_bool default_value, my_bool long_flag_protocol) +{ + DBUG_ENTER("unpack_fields_40"); + + for (; row ; row = row->next,field++) + { + fetch_lengths(lengths, row->data, n_lengths); + field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]); + field->name= strdup_root(alloc,(char*) row->data[1]); + field->length= (uint) uint3korr(row->data[2]); + field->type= (enum enum_field_types) (uchar) row->data[3][0]; + + field->catalog=(char*) ""; + field->db= (char*) ""; + field->catalog_length= 0; + field->db_length= 0; + field->org_table_length= field->table_length= lengths[0]; + field->name_length= lengths[1]; + + if (long_flag_protocol) + { + field->flags= uint2korr(row->data[4]); + field->decimals=(uint) (uchar) row->data[4][2]; + } + else + { + field->flags= (uint) (uchar) row->data[4][0]; + field->decimals=(uint) (uchar) row->data[4][1]; + } + if (INTERNAL_NUM_FIELD(field)) + field->flags|= NUM_FLAG; + if (default_value && row->data[5]) + { + field->def=strdup_root(alloc,(char*) row->data[5]); + field->def_length= lengths[5]; + } + else + field->def=0; + field->max_length= 0; + } +} + +/*************************************************************************** + Change field rows to field structs +***************************************************************************/ + +MYSQL_FIELD * +unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, + my_bool default_value, uint server_capabilities) +{ +#ifdef MYSQL_CLIENT + MYSQL_ROWS *row; +#endif + MYSQL_FIELD *field,*result; + ulong lengths[9]; /* Max of fields */ + DBUG_ENTER("unpack_fields"); + + field=result=(MYSQL_FIELD*) alloc_root(alloc, + (uint) sizeof(MYSQL_FIELD)*fields); + if (!result) + { + free_rows(data); /* Free old data */ + DBUG_RETURN(0); + } + bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields); +#ifdef MYSQL_SERVER + unpack_fields_40(data->data, field, alloc, lengths, default_value ? 6 : 5, + default_value, server_capabilities & CLIENT_LONG_FLAG); +#else + if (server_capabilities & CLIENT_PROTOCOL_41) + { + /* server is 4.1, and returns the new field result format */ + for (row=data->data; row ; row = row->next,field++) + { + uchar *pos; + fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7); + field->catalog = strdup_root(alloc,(char*) row->data[0]); + field->db = strdup_root(alloc,(char*) row->data[1]); + field->table = strdup_root(alloc,(char*) row->data[2]); + field->org_table= strdup_root(alloc,(char*) row->data[3]); + field->name = strdup_root(alloc,(char*) row->data[4]); + field->org_name = strdup_root(alloc,(char*) row->data[5]); + + field->catalog_length= lengths[0]; + field->db_length= lengths[1]; + field->table_length= lengths[2]; + field->org_table_length= lengths[3]; + field->name_length= lengths[4]; + field->org_name_length= lengths[5]; + + /* Unpack fixed length parts */ + pos= (uchar*) row->data[6]; + field->charsetnr= uint2korr(pos); + field->length= (uint) uint4korr(pos+2); + field->type= (enum enum_field_types) pos[6]; + field->flags= uint2korr(pos+7); + field->decimals= (uint) pos[9]; + + if (INTERNAL_NUM_FIELD(field)) + field->flags|= NUM_FLAG; + if (default_value && row->data[7]) + { + field->def=strdup_root(alloc,(char*) row->data[7]); + field->def_length= lengths[7]; + } + else + field->def=0; + field->max_length= 0; + } + } +#ifndef DELETE_SUPPORT_OF_4_0_PROTOCOL + else + unpack_fields_40(data->data, field, alloc, lengths, default_value ? 6 : 5, + default_value, server_capabilities & CLIENT_LONG_FLAG); +#endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */ +#endif /*MYSQL_SERVER*/ + free_rows(data); /* Free old data */ + DBUG_RETURN(result); +} + +/* Read all rows (fields or data) from server */ + +MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, + uint fields) +{ + uint field; + ulong pkt_len; + ulong len; + uchar *cp; + char *to, *end_to; + MYSQL_DATA *result; + MYSQL_ROWS **prev_ptr,*cur; + NET *net = &mysql->net; + DBUG_ENTER("read_rows"); + + if ((pkt_len= net_safe_read(mysql)) == packet_error) + DBUG_RETURN(0); + if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), + MYF(MY_WME | MY_ZEROFILL)))) + { + net->last_errno=CR_OUT_OF_MEMORY; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + DBUG_RETURN(0); + } + init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ + result->alloc.min_malloc=sizeof(MYSQL_ROWS); + prev_ptr= &result->data; + result->rows=0; + result->fields=fields; + + /* + The last EOF packet is either a single 254 character or (in MySQL 4.1) + 254 followed by 1-7 status bytes. + + This doesn't conflict with normal usage of 254 which stands for a + string where the length of the string is 8 bytes. (see net_field_length()) + */ + + while (*(cp=net->read_pos) != 254 || pkt_len >= 8) + { + result->rows++; + if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, + sizeof(MYSQL_ROWS))) || + !(cur->data= ((MYSQL_ROW) + alloc_root(&result->alloc, + (fields+1)*sizeof(char *)+pkt_len)))) + { + free_rows(result); + net->last_errno=CR_OUT_OF_MEMORY; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + DBUG_RETURN(0); + } + *prev_ptr=cur; + prev_ptr= &cur->next; + to= (char*) (cur->data+fields+1); + end_to=to+pkt_len-1; + for (field=0 ; field < fields ; field++) + { + if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH) + { /* null field */ + cur->data[field] = 0; + } + else + { + cur->data[field] = to; + if (len > (ulong) (end_to - to)) + { + free_rows(result); + net->last_errno=CR_MALFORMED_PACKET; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + DBUG_RETURN(0); + } + memcpy(to,(char*) cp,len); to[len]=0; + to+=len+1; + cp+=len; + if (mysql_fields) + { + if (mysql_fields[field].max_length < len) + mysql_fields[field].max_length=len; + } + } + } + cur->data[field]=to; /* End of last field */ + if ((pkt_len=net_safe_read(mysql)) == packet_error) + { + free_rows(result); + DBUG_RETURN(0); + } + } + *prev_ptr=0; /* last pointer is null */ +#ifndef MYSQL_SERVER + if (pkt_len > 1) /* MySQL 4.1 protocol */ + { + mysql->warning_count= uint2korr(cp+1); + DBUG_PRINT("info",("warning_count: %ld", mysql->warning_count)); + } +#endif + DBUG_PRINT("exit",("Got %d rows",result->rows)); + DBUG_RETURN(result); +} + +/* + Read one row. Uses packet buffer as storage for fields. + When next packet is read, the previous field values are destroyed +*/ + + +static int +read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) +{ + uint field; + ulong pkt_len,len; + uchar *pos, *prev_pos, *end_pos; + NET *net= &mysql->net; + + if ((pkt_len=net_safe_read(mysql)) == packet_error) + return -1; + if (pkt_len <= 8 && net->read_pos[0] == 254) + { +#ifndef MYSQL_SERVER + if (pkt_len > 1) /* MySQL 4.1 protocol */ + mysql->warning_count= uint2korr(net->read_pos+1); +#endif + return 1; /* End of data */ + } + prev_pos= 0; /* allowed to write at packet[-1] */ + pos=net->read_pos; + end_pos=pos+pkt_len; + for (field=0 ; field < fields ; field++) + { + if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH) + { /* null field */ + row[field] = 0; + *lengths++=0; + } + else + { + if (len > (ulong) (end_pos - pos)) + { + net->last_errno=CR_UNKNOWN_ERROR; + strmov(net->last_error,ER(net->last_errno)); + strmov(net->sqlstate, unknown_sqlstate); + return -1; + } + row[field] = (char*) pos; + pos+=len; + *lengths++=len; + } + if (prev_pos) + *prev_pos=0; /* Terminate prev field */ + prev_pos=pos; + } + row[field]=(char*) prev_pos+1; /* End of last field */ + *prev_pos=0; /* Terminate last field */ + return 0; +} + + +/**************************************************************************** + Init MySQL structure or allocate one +****************************************************************************/ + +MYSQL * STDCALL +mysql_init(MYSQL *mysql) +{ + mysql_once_init(); + if (!mysql) + { + if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) + return 0; + mysql->free_me=1; + } + else + bzero((char*) (mysql),sizeof(*(mysql))); +#ifndef MYSQL_SERVER + mysql->options.connect_timeout=CONNECT_TIMEOUT; + mysql->last_used_con = mysql->next_slave = mysql->master = mysql; + /* + By default, we are a replication pivot. The caller must reset it + after we return if this is not the case. + */ + mysql->rpl_pivot = 1; +#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) + if (!((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE)) + (void) signal(SIGPIPE,pipe_sig_handler); +#endif + +/* + Only enable LOAD DATA INFILE by default if configured with + --enable-local-infile +*/ +#ifdef ENABLED_LOCAL_INFILE + mysql->options.client_flag|= CLIENT_LOCAL_FILES; +#endif +#ifdef HAVE_SMEM + mysql->options.shared_memory_base_name=(char*)def_shared_memory_base_name; +#endif + +#else /*MYSQL_SERVER*/ + +#ifdef __WIN__ + mysql->options.connect_timeout=20; +#endif +#endif /*MYSQL_SERVER*/ + return mysql; +} + + +/* + Initialize the MySQL library + + SYNOPSIS + mysql_once_init() + + NOTES + Can't be static on NetWare + This function is called by mysql_init() and indirectly called + by mysql_query(), so one should never have to call this from an + outside program. +*/ + +void mysql_once_init(void) +{ +#ifndef MYSQL_SERVER + + if (!mysql_client_init) + { + mysql_client_init=1; + org_my_init_done=my_init_done; + my_init(); /* Will init threads */ + init_client_errs(); + if (!mysql_port) + { + mysql_port = MYSQL_PORT; +#ifndef MSDOS + { + struct servent *serv_ptr; + char *env; + if ((serv_ptr = getservbyname("mysql", "tcp"))) + mysql_port = (uint) ntohs((ushort) serv_ptr->s_port); + if ((env = getenv("MYSQL_TCP_PORT"))) + mysql_port =(uint) atoi(env); + } +#endif + } + if (!mysql_unix_port) + { + char *env; +#ifdef __WIN__ + mysql_unix_port = (char*) MYSQL_NAMEDPIPE; +#else + mysql_unix_port = (char*) MYSQL_UNIX_ADDR; +#endif + if ((env = getenv("MYSQL_UNIX_PORT"))) + mysql_unix_port = env; + } + mysql_debug(NullS); +#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__) + (void) signal(SIGPIPE,SIG_IGN); +#endif + } +#ifdef THREAD + else + my_thread_init(); /* Init if new thread */ +#endif + +#else /*MYSQL_SERVER*/ + init_client_errs(); +#endif /*MYSQL_SERVER*/ +} + + +/* + Handle password authentication +*/ + +my_bool mysql_autenticate(MYSQL *mysql, const char *passwd) +{ + ulong pkt_length; + NET *net= &mysql->net; + char buff[SCRAMBLE41_LENGTH]; + char password_hash[SCRAMBLE41_LENGTH]; /* Used for storage of stage1 hash */ + + /* We shall only query server if it expect us to do so */ + if ((pkt_length=net_safe_read(mysql)) == packet_error) + goto error; + + if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) + { + /* + This should always happen with new server unless empty password + OK/Error packets have zero as the first char + */ + if (pkt_length == 24 && net->read_pos[0]) + { + /* Old passwords will have '*' at the first byte of hash */ + if (net->read_pos[0] != '*') + { + /* Build full password hash as it is required to decode scramble */ + password_hash_stage1(buff, passwd); + /* Store copy as we'll need it later */ + memcpy(password_hash,buff,SCRAMBLE41_LENGTH); + /* Finally hash complete password using hash we got from server */ + password_hash_stage2(password_hash,(const char*) net->read_pos); + /* Decypt and store scramble 4 = hash for stage2 */ + password_crypt((const char*) net->read_pos+4,mysql->scramble_buff, + password_hash, SCRAMBLE41_LENGTH); + mysql->scramble_buff[SCRAMBLE41_LENGTH]=0; + /* Encode scramble with password. Recycle buffer */ + password_crypt(mysql->scramble_buff,buff,buff,SCRAMBLE41_LENGTH); + } + else + { + /* Create password to decode scramble */ + create_key_from_old_password(passwd,password_hash); + /* Decypt and store scramble 4 = hash for stage2 */ + password_crypt((const char*) net->read_pos+4,mysql->scramble_buff, + password_hash, SCRAMBLE41_LENGTH); + mysql->scramble_buff[SCRAMBLE41_LENGTH]=0; + /* Finally scramble decoded scramble with password */ + scramble(buff, mysql->scramble_buff, passwd,0); + } + /* Write second package of authentication */ + if (my_net_write(net,buff,SCRAMBLE41_LENGTH) || net_flush(net)) + { + net->last_errno= CR_SERVER_LOST; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + /* Read what server thinks about out new auth message report */ + if (net_safe_read(mysql) == packet_error) + goto error; + } + } + return 0; + +error: + return 1; +} + +/* + Note that the mysql argument must be initialized with mysql_init() + before calling mysql_real_connect ! +*/ + +MYSQL * STDCALL +mysql_real_connect(MYSQL *mysql,const char *host, const char *user, + const char *passwd, const char *db, + uint port, const char *unix_socket,ulong client_flag) +{ +#ifdef MYSQL_CLIENT + char *charset_name; + char charset_name_buff[16]; +#endif + char buff[NAME_LEN+USERNAME_LENGTH+100]; + char *end,*host_info; + my_socket sock; + uint32 ip_addr; + struct sockaddr_in sock_addr; + ulong pkt_length; + NET *net= &mysql->net; +#ifdef MYSQL_SERVER + thr_alarm_t alarmed; + ALARM alarm_buff; + ulong max_allowed_packet; +#endif + +#ifdef __WIN__ + HANDLE hPipe=INVALID_HANDLE_VALUE; +#endif +#ifdef HAVE_SYS_UN_H + struct sockaddr_un UNIXaddr; +#endif + init_sigpipe_variables + DBUG_ENTER("mysql_real_connect"); + LINT_INIT(host_info); + + DBUG_PRINT("enter",("host: %s db: %s user: %s", + host ? host : "(Null)", + db ? db : "(Null)", + user ? user : "(Null)")); + + /* Don't give sigpipe errors if the client doesn't want them */ + set_sigpipe(mysql); + net->vio = 0; /* If something goes wrong */ + mysql->client_flag=0; /* For handshake */ +#ifdef MYSQL_SERVER + mysql->charset=default_charset_info; /* Set character set */ +#endif + + /* use default options */ + if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) + { + mysql_read_default_options(&mysql->options, + (mysql->options.my_cnf_file ? + mysql->options.my_cnf_file : "my"), + mysql->options.my_cnf_group); + my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; + } + + /* Some empty-string-tests are done because of ODBC */ + if (!host || !host[0]) + host=mysql->options.host; + if (!user || !user[0]) + user=mysql->options.user; + if (!passwd) + { + passwd=mysql->options.password; +#ifndef DONT_USE_MYSQL_PWD + if (!passwd) + passwd=getenv("MYSQL_PWD"); /* get it from environment */ +#endif + } + if (!db || !db[0]) + db=mysql->options.db; + if (!port) + port=mysql->options.port; + if (!unix_socket) + unix_socket=mysql->options.unix_socket; + + mysql->reconnect=1; /* Reconnect as default */ + mysql->server_status=SERVER_STATUS_AUTOCOMMIT; + + /* + Grab a socket and connect it to the server + */ +#ifdef HAVE_SMEM + if ((!mysql->options.protocol || + mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) && + (!host || !strcmp(host,LOCAL_HOST))) + { + if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) == + INVALID_HANDLE_VALUE) + { + DBUG_PRINT("error", + ("host: '%s' socket: '%s' shared memory: %s have_tcpip: %d", + host ? host : "<null>", + unix_socket ? unix_socket : "<null>", + (int) mysql->options.shared_memory_base_name, + (int) have_tcpip)); + if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) + goto error; + /* Try also with PIPE or TCP/IP */ + } + else + { + mysql->options.protocol=MYSQL_PROTOCOL_MEMORY; + sock=0; + unix_socket = 0; + host=mysql->options.shared_memory_base_name; + host_info=(char*) ER(CR_SHARED_MEMORY_CONNECTION); + } + } else +#endif /* HAVE_SMEM */ +#if defined(HAVE_SYS_UN_H) + if ((!mysql->options.protocol || + mysql->options.protocol == MYSQL_PROTOCOL_SOCKET)&& + (unix_socket || mysql_unix_port) && + (!host || !strcmp(host,LOCAL_HOST))) + { + host=LOCAL_HOST; + if (!unix_socket) + unix_socket=mysql_unix_port; + host_info=(char*) ER(CR_LOCALHOST_CONNECTION); + DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); + if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) + { + net->last_errno=CR_SOCKET_CREATE_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),socket_errno); + goto error; + } + net->vio = vio_new(sock, VIO_TYPE_SOCKET, TRUE); + bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); + UNIXaddr.sun_family = AF_UNIX; + strmov(UNIXaddr.sun_path, unix_socket); + if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr), + mysql->options.connect_timeout)) + { + DBUG_PRINT("error",("Got error %d on connect to local server", + socket_errno)); + net->last_errno=CR_CONNECTION_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),unix_socket,socket_errno); + goto error; + } +#ifdef MYSQL_CLIENT + else + mysql->options.protocol=MYSQL_PROTOCOL_SOCKET; +#endif + } + else +#elif defined(__WIN__) + { + if ((!mysql->options.protocol || + mysql->options.protocol == MYSQL_PROTOCOL_PIPE)&& + ((unix_socket || !host && is_NT() || + host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) ||! have_tcpip))&& + (!net->vio)) + { + sock=0; + if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout, + (char**) &host, (char**) &unix_socket)) == + INVALID_HANDLE_VALUE) + { + DBUG_PRINT("error", + ("host: '%s' socket: '%s' have_tcpip: %d", + host ? host : "<null>", + unix_socket ? unix_socket : "<null>", + (int) have_tcpip)); + if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || + (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || + (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) + goto error; + /* Try also with TCP/IP */ + } + else + { + net->vio=vio_new_win32pipe(hPipe); + sprintf(host_info=buff, ER(CR_NAMEDPIPE_CONNECTION), host, + unix_socket); + } + } + } +#ifdef MYSQL_SERVER + if (hPipe == INVALID_HANDLE_VALUE) +#endif +#endif +#ifdef MYSQL_CLIENT + if ((!mysql->options.protocol || + mysql->options.protocol == MYSQL_PROTOCOL_TCP)&&(!net->vio)) +#endif + { + unix_socket=0; /* This is not used */ + if (!port) + port=mysql_port; + if (!host) + host=LOCAL_HOST; + sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host); + DBUG_PRINT("info",("Server name: '%s'. TCP sock: %d", host,port)); +#ifdef MYSQL_SERVER + thr_alarm_init(&alarmed); + thr_alarm(&alarmed, mysql->options.connect_timeout, &alarm_buff); +#endif + sock = (my_socket) socket(AF_INET,SOCK_STREAM,0); +#ifdef MYSQL_SERVER + thr_end_alarm(&alarmed); +#endif + /* _WIN64 ; Assume that the (int) range is enough for socket() */ + if (sock == SOCKET_ERROR) + { + net->last_errno=CR_IPSOCK_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error,ER(net->last_errno),socket_errno); + goto error; + } + net->vio = vio_new(sock,VIO_TYPE_TCPIP,FALSE); + bzero((char*) &sock_addr,sizeof(sock_addr)); + sock_addr.sin_family = AF_INET; + + /* + The server name may be a host name or IP address + */ + + if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) + { + memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); + } + else + { + int tmp_errno; + struct hostent tmp_hostent,*hp; + char buff2[GETHOSTBYNAME_BUFF_SIZE]; + hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), + &tmp_errno); + if (!hp) + { + my_gethostbyname_r_free(); + net->last_errno=CR_UNKNOWN_HOST; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno); + goto error; + } + memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length); + my_gethostbyname_r_free(); + } + sock_addr.sin_port = (ushort) htons((ushort) port); + if (my_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr), + mysql->options.connect_timeout)) + { + DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno, + host)); + net->last_errno= CR_CONN_HOST_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error ,ER(CR_CONN_HOST_ERROR), host, socket_errno); + goto error; + } + } +#ifdef MYSQL_CLIENT + else if (!net->vio) + { + DBUG_PRINT("error",("Unknow protocol %d ",mysql->options.protocol)); + net->last_errno= CR_CONN_UNKNOW_PROTOCOL; + strmov(net->sqlstate, unknown_sqlstate); + sprintf(net->last_error ,ER(CR_CONN_UNKNOW_PROTOCOL)); + goto error; + } +#endif /*MYSQL_CLIENT*/ + if (!net->vio || my_net_init(net, net->vio)) + { + vio_delete(net->vio); + net->vio = 0; + net->last_errno=CR_OUT_OF_MEMORY; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + vio_keepalive(net->vio,TRUE); +#ifdef MYSQL_SERVER + net->read_timeout=slave_net_timeout; +#endif + /* Get version info */ + mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ + if (mysql->options.connect_timeout && + vio_poll_read(net->vio, mysql->options.connect_timeout)) + { + net->last_errno= CR_SERVER_LOST; + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + if ((pkt_length=net_safe_read(mysql)) == packet_error) + goto error; + + /* Check if version of protocol matches current one */ + + mysql->protocol_version= net->read_pos[0]; + DBUG_DUMP("packet",(char*) net->read_pos,10); + DBUG_PRINT("info",("mysql protocol version %d, server=%d", + PROTOCOL_VERSION, mysql->protocol_version)); + if (mysql->protocol_version != PROTOCOL_VERSION + && mysql->protocol_version != PROTOCOL_VERSION-1) + { + net->last_errno= CR_VERSION_ERROR; + sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version, + PROTOCOL_VERSION); + goto error; + } + end=strend((char*) net->read_pos+1); + mysql->thread_id=uint4korr(end+1); + end+=5; + strmake(mysql->scramble_buff,end,8); + end+=9; + if (pkt_length >= (uint) (end+1 - (char*) net->read_pos)) + mysql->server_capabilities=uint2korr(end); + if (pkt_length >= (uint) (end+18 - (char*) net->read_pos)) + { + /* New protocol with 16 bytes to describe server characteristics */ + mysql->server_language=end[2]; + mysql->server_status=uint2korr(end+3); + } + +#ifdef MYSQL_CLIENT + /* Set character set */ + if ((charset_name=mysql->options.charset_name)) + { + const char *save=charsets_dir; + if (mysql->options.charset_dir) + charsets_dir=mysql->options.charset_dir; + mysql->charset=get_charset_by_csname(mysql->options.charset_name, + MY_CS_PRIMARY, + MYF(MY_WME)); + charsets_dir=save; + } + else if (mysql->server_language) + { + charset_name=charset_name_buff; + sprintf(charset_name,"%d",mysql->server_language); /* In case of errors */ + if (!(mysql->charset = + get_charset((uint8) mysql->server_language, MYF(0)))) + mysql->charset = default_charset_info; /* shouldn't be fatal */ + } + else + mysql->charset=default_charset_info; + + if (!mysql->charset) + { + net->last_errno=CR_CANT_READ_CHARSET; + strmov(net->sqlstate, unknown_sqlstate); + if (mysql->options.charset_dir) + sprintf(net->last_error,ER(net->last_errno), + charset_name ? charset_name : "unknown", + mysql->options.charset_dir); + else + { + char cs_dir_name[FN_REFLEN]; + get_charsets_dir(cs_dir_name); + sprintf(net->last_error,ER(net->last_errno), + charset_name ? charset_name : "unknown", + cs_dir_name); + } + goto error; + } +#endif /*MYSQL_CLIENT*/ + + /* Save connection information */ + if (!user) user=""; + if (!passwd) passwd=""; + if (!my_multi_malloc(MYF(0), + &mysql->host_info, (uint) strlen(host_info)+1, + &mysql->host, (uint) strlen(host)+1, + &mysql->unix_socket,unix_socket ? + (uint) strlen(unix_socket)+1 : (uint) 1, + &mysql->server_version, + (uint) (end - (char*) net->read_pos), + NullS) || + !(mysql->user=my_strdup(user,MYF(0))) || + !(mysql->passwd=my_strdup(passwd,MYF(0)))) + { + strmov(net->sqlstate, unknown_sqlstate); + strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY)); + goto error; + } + strmov(mysql->host_info,host_info); + strmov(mysql->host,host); + if (unix_socket) + strmov(mysql->unix_socket,unix_socket); + else + mysql->unix_socket=0; + strmov(mysql->server_version,(char*) net->read_pos+1); + mysql->port=port; + client_flag|=mysql->options.client_flag; + + /* Send client information for access check */ + client_flag|=CLIENT_CAPABILITIES; + if (client_flag & CLIENT_MULTI_QUERIES) + client_flag|= CLIENT_MULTI_RESULTS; + +#ifdef HAVE_OPENSSL + if (mysql->options.ssl_key || mysql->options.ssl_cert || + mysql->options.ssl_ca || mysql->options.ssl_capath || + mysql->options.ssl_cipher) + mysql->options.use_ssl= 1; + if (mysql->options.use_ssl) + client_flag|=CLIENT_SSL; +#endif /* HAVE_OPENSSL */ + if (db) + client_flag|=CLIENT_CONNECT_WITH_DB; + +#ifdef MYSQL_CLIENT + /* Remove options that server doesn't support */ + client_flag= ((client_flag & + ~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41)) | + (client_flag & mysql->server_capabilities)); +#ifndef HAVE_COMPRESS + client_flag&= ~CLIENT_COMPRESS; +#endif + if (client_flag & CLIENT_PROTOCOL_41) + { + /* 4.1 server and 4.1 client has a 32 byte option flag */ + int4store(buff,client_flag); + int4store(buff+4,max_allowed_packet); + buff[8]= mysql->charset->number; + bzero(buff+9, 32-9); + end= buff+32; + } + else + { + int2store(buff,client_flag); + int3store(buff+2,max_allowed_packet); + end= buff+5; + } + mysql->client_flag=client_flag; +#endif /*MYSQL_CLIENT*/ + +#ifdef MYSQL_SERVER +#ifdef HAVE_COMPRESS + if ((mysql->server_capabilities & CLIENT_COMPRESS) && + (mysql->options.compress || (client_flag & CLIENT_COMPRESS))) + client_flag|=CLIENT_COMPRESS; /* We will use compression */ + else +#endif + client_flag&= ~CLIENT_COMPRESS; +#endif /*MYSQL_SERVER*/ + +#ifdef MYSQL_SERVER +#ifdef HAVE_OPENSSL + if ((mysql->server_capabilities & CLIENT_SSL) && + (mysql->options.use_ssl || (client_flag & CLIENT_SSL))) + { + DBUG_PRINT("info", ("Changing IO layer to SSL")); + client_flag |= CLIENT_SSL; + } + else + { + if (client_flag & CLIENT_SSL) + { + DBUG_PRINT("info", ("Leaving IO layer intact because server doesn't support SSL")); + } + client_flag &= ~CLIENT_SSL; + } +#endif /* HAVE_OPENSSL */ + + max_allowed_packet=mysql->net.max_packet_size; + int2store(buff,client_flag); + int3store(buff+2,max_allowed_packet); + end= buff+5; + mysql->client_flag=client_flag; +#endif /*MYSQL_SERVER*/ + +#ifdef HAVE_OPENSSL + /* + Oops.. are we careful enough to not send ANY information without + encryption? + */ + if (client_flag & CLIENT_SSL) + { +#ifdef MYSQL_CLIENT + struct st_mysql_options *options= &mysql->options; +#endif + if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net)) + { + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno= CR_SERVER_LOST; + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + /* Do the SSL layering. */ +#ifdef MYSQL_CLIENT + if (!(mysql->connector_fd= + (gptr) new_VioSSLConnectorFd(options->ssl_key, + options->ssl_cert, + options->ssl_ca, + options->ssl_capath, + options->ssl_cipher))) + { + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno= CR_SSL_CONNECTION_ERROR; + strmov(net->last_error,ER(net->last_errno)); + goto error; + } +#endif /*MYSQL_CLIENT*/ + DBUG_PRINT("info", ("IO layer change in progress...")); + if (sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd), + mysql->net.vio, (long) (mysql->options.connect_timeout))) + { + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno= CR_SSL_CONNECTION_ERROR; + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + DBUG_PRINT("info", ("IO layer change done!")); + } +#endif /* HAVE_OPENSSL */ + + DBUG_PRINT("info",("Server version = '%s' capabilites: %lu status: %u client_flag: %lu", + mysql->server_version,mysql->server_capabilities, + mysql->server_status, client_flag)); + /* This needs to be changed as it's not useful with big packets */ + if (user && user[0]) + strmake(end,user,32); /* Max user name */ + else +#ifdef MYSQL_SERVER + { + user = getenv("USER"); + if (!user) user = "mysql"; + strmov((char*) end, user ); + } +#else + read_user_name((char*) end); +#endif /*MYSQL_SERVER*/ + /* We have to handle different version of handshake here */ +#if defined(_CUSTOMCONFIG_) && defined(MYSQL_CLIENT) +#include "_cust_libmysql.h"; +#endif + DBUG_PRINT("info",("user: %s",end)); + /* + We always start with old type handshake the only difference is message sent + If server handles secure connection type we'll not send the real scramble + */ + if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) + { + if (passwd[0]) + { + /* Prepare false scramble */ + end=strend(end)+1; + bfill(end, SCRAMBLE_LENGTH, 'x'); + end+=SCRAMBLE_LENGTH; + *end=0; + } + else /* For empty password*/ + { + end=strend(end)+1; + *end=0; /* Store zero length scramble */ + } + } + else + { + /* + Real scramble is only sent to old servers. This can be blocked + by calling mysql_options(MYSQL *, MYSQL_SECURE_CONNECT, (char*) &1); + */ + end=scramble(strend(end)+1, mysql->scramble_buff, passwd, + (my_bool) (mysql->protocol_version == 9)); + } + /* Add database if needed */ + if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) + { + end=strmake(end+1,db,NAME_LEN); + mysql->db=my_strdup(db,MYF(MY_WME)); + db=0; + } + /* Write authentication package */ + if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net)) + { + strmov(net->sqlstate, unknown_sqlstate); + net->last_errno= CR_SERVER_LOST; + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + + if (mysql_autenticate(mysql, passwd)) + goto error; + + if (client_flag & CLIENT_COMPRESS) /* We will use compression */ + net->compress=1; + +#ifdef MYSQL_CLIENT + if (mysql->options.max_allowed_packet) + net->max_packet_size= mysql->options.max_allowed_packet; + if (db && mysql_select_db(mysql,db)) + goto error; + + if (mysql->options.init_commands) + { + DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; + char **ptr= (char**)init_commands->buffer; + char **end= ptr + init_commands->elements; + + my_bool reconnect=mysql->reconnect; + mysql->reconnect=0; + + for (; ptr<end; ptr++) + { + MYSQL_RES *res; + if (mysql_query(mysql,*ptr)) + goto error; + if (mysql->fields) + { + if (!(res= mysql_use_result(mysql))) + goto error; + mysql_free_result(res); + } + } + + mysql->reconnect=reconnect; + } + + if (mysql->options.rpl_probe && mysql_rpl_probe(mysql)) + goto error; +#endif /*MYSQL_CLIENT*/ + + DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); + reset_sigpipe(mysql); + DBUG_RETURN(mysql); + +error: + reset_sigpipe(mysql); + DBUG_PRINT("error",("message: %u/%s (%s)", + net->last_errno, net->sqlstate, net->last_error)); + { + /* Free alloced memory */ + my_bool free_me=mysql->free_me; + end_server(mysql); + mysql->free_me=0; + mysql_close(mysql); + mysql->free_me=free_me; + } + DBUG_RETURN(0); +} + +/* needed when we move MYSQL structure to a different address */ + +static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql) +{ + if (mysql->master == old_mysql) + mysql->master = mysql; + if (mysql->last_used_con == old_mysql) + mysql->last_used_con = mysql; + if (mysql->last_used_slave == old_mysql) + mysql->last_used_slave = mysql; +#ifdef MYSQL_CLIENT /*should work in MYSQL_SERVER also, but doesn't */ + { + MYSQL *tmp, *tmp_prev; + for (tmp_prev = mysql, tmp = mysql->next_slave; + tmp != old_mysql;tmp = tmp->next_slave) + { + tmp_prev = tmp; + } + tmp_prev->next_slave = mysql; + } +#endif /*MYSQL_CLIENT*/ +} + +my_bool mysql_reconnect(MYSQL *mysql) +{ + MYSQL tmp_mysql; + DBUG_ENTER("mysql_reconnect"); + + if (!mysql->reconnect + || (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info) + { + /* Allow reconnect next time */ + mysql->server_status&= ~SERVER_STATUS_IN_TRANS; + strmov(mysql->net.sqlstate, unknown_sqlstate); + mysql->net.last_errno=CR_SERVER_GONE_ERROR; + strmov(mysql->net.last_error,ER(mysql->net.last_errno)); + DBUG_RETURN(1); + } + mysql_init(&tmp_mysql); + tmp_mysql.options=mysql->options; + bzero((char*) &mysql->options,sizeof(mysql->options)); + tmp_mysql.rpl_pivot = mysql->rpl_pivot; + if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, + mysql->db, mysql->port, mysql->unix_socket, + mysql->client_flag)) + { + mysql->net.last_errno= tmp_mysql.net.last_errno; + strmov(mysql->net.last_error, tmp_mysql.net.last_error); + strmov(mysql->net.sqlstate, unknown_sqlstate); + DBUG_RETURN(1); + } + tmp_mysql.free_me=mysql->free_me; + mysql->free_me=0; + mysql_close(mysql); + *mysql=tmp_mysql; + mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */ + net_clear(&mysql->net); + mysql->affected_rows= ~(my_ulonglong) 0; + DBUG_RETURN(0); +} + +/************************************************************************** + Set current database +**************************************************************************/ + +int STDCALL +mysql_select_db(MYSQL *mysql, const char *db) +{ + int error; + DBUG_ENTER("mysql_select_db"); + DBUG_PRINT("enter",("db: '%s'",db)); + + if ((error=simple_command(mysql,COM_INIT_DB,db,(ulong) strlen(db),0))) + DBUG_RETURN(error); + my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + mysql->db=my_strdup(db,MYF(MY_WME)); + DBUG_RETURN(0); +} + +/* + Free strings in the SSL structure and clear 'use_ssl' flag. + NB! Errors are not reported until you do mysql_real_connect. +*/ + +#ifdef HAVE_OPENSSL +static void +mysql_ssl_free(MYSQL *mysql __attribute__((unused))) +{ + my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.ssl_key = 0; + mysql->options.ssl_cert = 0; + mysql->options.ssl_ca = 0; + mysql->options.ssl_capath = 0; + mysql->options.ssl_cipher= 0; + mysql->options.use_ssl = FALSE; + mysql->connector_fd = 0; +} +#endif /* HAVE_OPENSSL */ + +/************************************************************************* + Send a QUIT to the server and close the connection + If handle is alloced by mysql connect free it. +*************************************************************************/ + +void STDCALL +mysql_close(MYSQL *mysql) +{ + DBUG_ENTER("mysql_close"); + if (mysql) /* Some simple safety */ + { + if (mysql->net.vio != 0) + { + free_old_query(mysql); + mysql->status=MYSQL_STATUS_READY; /* Force command */ + mysql->reconnect=0; + simple_command(mysql,COM_QUIT,NullS,0,1); + end_server(mysql); /* Sets mysql->net.vio= 0 */ + } + my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); + if (mysql->options.init_commands) + { + DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; + char **ptr= (char**)init_commands->buffer; + char **end= ptr + init_commands->elements; + for (; ptr<end; ptr++) + my_free(*ptr,MYF(MY_WME)); + delete_dynamic(init_commands); + my_free((char*)init_commands,MYF(MY_WME)); + } +#ifdef HAVE_SMEM + if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) + my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); +#endif /* HAVE_SMEM */ + + /* free/close slave list */ + if (mysql->rpl_pivot) + { + MYSQL* tmp; + for (tmp = mysql->next_slave; tmp != mysql; ) + { + /* trick to avoid following freed pointer */ + MYSQL* tmp1 = tmp->next_slave; + mysql_close(tmp); + tmp = tmp1; + } + mysql->rpl_pivot=0; + } +#ifdef MYSQL_CLIENT + if (mysql->stmts) + { + /* Free any open prepared statements */ + LIST *element, *next_element; + for (element= mysql->stmts; element; element= next_element) + { + next_element= element->next; + stmt_close((MYSQL_STMT *)element->data, 0); + } + } + if (mysql != mysql->master) + mysql_close(mysql->master); +#endif /*MYSQL_CLIENT*/ + +#ifdef HAVE_OPENSSL + mysql_ssl_free(mysql); +#endif /* HAVE_OPENSSL */ + /* Clear pointers for better safety */ + + mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; + bzero((char*) &mysql->options,sizeof(mysql->options)); + if (mysql->free_me) + my_free((gptr) mysql,MYF(0)); + } + DBUG_VOID_RETURN; +} + +my_bool STDCALL mysql_read_query_result(MYSQL *mysql) +{ + uchar *pos; + ulong field_count; + MYSQL_DATA *fields; + ulong length; + DBUG_ENTER("mysql_read_query_result"); + +#ifdef MYSQL_CLIENT + /* + Read from the connection which we actually used, which + could differ from the original connection if we have slaves + */ + mysql = mysql->last_used_con; +#endif + + if ((length = net_safe_read(mysql)) == packet_error) + DBUG_RETURN(1); + free_old_query(mysql); /* Free old result */ +#ifdef MYSQL_CLIENT /*or else gcc will warn of unused labels*/ +get_info: +#endif + pos=(uchar*) mysql->net.read_pos; + if ((field_count= net_field_length(&pos)) == 0) + { + mysql->affected_rows= net_field_length_ll(&pos); + mysql->insert_id= net_field_length_ll(&pos); + if (protocol_41(mysql)) + { + mysql->server_status=uint2korr(pos); pos+=2; + mysql->warning_count=uint2korr(pos); pos+=2; + } + else if (mysql->server_capabilities & CLIENT_TRANSACTIONS) + { + mysql->server_status=uint2korr(pos); pos+=2; + mysql->warning_count= 0; + } + DBUG_PRINT("info",("status: %ld warning_count: %ld", + mysql->server_status, mysql->warning_count)); + if (pos < mysql->net.read_pos+length && net_field_length(&pos)) + mysql->info=(char*) pos; + DBUG_RETURN(0); + } +#ifdef MYSQL_CLIENT + if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ + { + int error=send_file_to_server(mysql,(char*) pos); + if ((length=net_safe_read(mysql)) == packet_error || error) + DBUG_RETURN(1); + goto get_info; /* Get info packet */ + } +#endif + if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) + mysql->server_status|= SERVER_STATUS_IN_TRANS; + + mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */ + + if (!(fields=read_rows(mysql,(MYSQL_FIELD*)0,protocol_41(mysql) ? 7 : 5))) + DBUG_RETURN(1); + if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc, + (uint) field_count,0, + mysql->server_capabilities))) + DBUG_RETURN(1); + mysql->status= MYSQL_STATUS_GET_RESULT; + mysql->field_count= (uint) field_count; + mysql->warning_count= 0; + DBUG_RETURN(0); +} + + +/* + Send the query and return so we can do something else. + Needs to be followed by mysql_read_query_result() when we want to + finish processing it. +*/ + +int STDCALL +mysql_send_query(MYSQL* mysql, const char* query, ulong length) +{ + DBUG_ENTER("mysql_send_query"); + DBUG_PRINT("enter",("rpl_parse: %d rpl_pivot: %d", + mysql->options.rpl_parse, mysql->rpl_pivot)); +#ifdef MYSQL_CLIENT + if (mysql->options.rpl_parse && mysql->rpl_pivot) + { + switch (mysql_rpl_query_type(query, length)) { + case MYSQL_RPL_MASTER: + DBUG_RETURN(mysql_master_send_query(mysql, query, length)); + case MYSQL_RPL_SLAVE: + DBUG_RETURN(mysql_slave_send_query(mysql, query, length)); + case MYSQL_RPL_ADMIN: + break; /* fall through */ + } + } + + mysql->last_used_con = mysql; +#endif /*MYSQL_CLIENT*/ + + DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1)); +} + + +int STDCALL +mysql_real_query(MYSQL *mysql, const char *query, ulong length) +{ + DBUG_ENTER("mysql_real_query"); + DBUG_PRINT("enter",("handle: %lx",mysql)); + DBUG_PRINT("query",("Query = '%-.4096s'",query)); + + if (mysql_send_query(mysql,query,length)) + DBUG_RETURN(1); + DBUG_RETURN((int) mysql_read_query_result(mysql)); +} + +/************************************************************************** + Alloc result struct for buffered results. All rows are read to buffer. + mysql_data_seek may be used. +**************************************************************************/ + +MYSQL_RES * STDCALL +mysql_store_result(MYSQL *mysql) +{ + MYSQL_RES *result; + DBUG_ENTER("mysql_store_result"); + +#ifdef MYSQL_CLIENT + /* read from the actually used connection */ + mysql = mysql->last_used_con; +#endif + if (!mysql->fields) + DBUG_RETURN(0); + if (mysql->status != MYSQL_STATUS_GET_RESULT) + { + strmov(mysql->net.sqlstate, unknown_sqlstate); + strmov(mysql->net.last_error, + ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); + DBUG_RETURN(0); + } + mysql->status=MYSQL_STATUS_READY; /* server is ready */ + if (!(result=(MYSQL_RES*) my_malloc((uint) (sizeof(MYSQL_RES)+ + sizeof(ulong) * + mysql->field_count), + MYF(MY_WME | MY_ZEROFILL)))) + { + strmov(mysql->net.sqlstate, unknown_sqlstate); + mysql->net.last_errno=CR_OUT_OF_MEMORY; + strmov(mysql->net.last_error, ER(mysql->net.last_errno)); + DBUG_RETURN(0); + } + result->eof=1; /* Marker for buffered */ + result->lengths=(ulong*) (result+1); + if (!(result->data=read_rows(mysql,mysql->fields,mysql->field_count))) + { + my_free((gptr) result,MYF(0)); + DBUG_RETURN(0); + } + mysql->affected_rows= result->row_count= result->data->rows; + result->data_cursor= result->data->data; + result->fields= mysql->fields; + result->field_alloc= mysql->field_alloc; + result->field_count= mysql->field_count; + result->current_field=0; + result->current_row=0; /* Must do a fetch first */ + mysql->fields=0; /* fields is now in result */ + DBUG_RETURN(result); /* Data fetched */ +} + +/************************************************************************** + Return next row of the query results +**************************************************************************/ + +MYSQL_ROW STDCALL +mysql_fetch_row(MYSQL_RES *res) +{ + DBUG_ENTER("mysql_fetch_row"); + if (!res->data) + { /* Unbufferred fetch */ + if (!res->eof) + { + if (!(read_one_row(res->handle,res->field_count,res->row, res->lengths))) + { + res->row_count++; + DBUG_RETURN(res->current_row=res->row); + } + else + { + DBUG_PRINT("info",("end of data")); + res->eof=1; + res->handle->status=MYSQL_STATUS_READY; + /* Don't clear handle in mysql_free_results */ + res->handle=0; + } + } + DBUG_RETURN((MYSQL_ROW) NULL); + } + { + MYSQL_ROW tmp; + if (!res->data_cursor) + { + DBUG_PRINT("info",("end of data")); + DBUG_RETURN(res->current_row=(MYSQL_ROW) NULL); + } + tmp = res->data_cursor->data; + res->data_cursor = res->data_cursor->next; + DBUG_RETURN(res->current_row=tmp); + } +} + +/************************************************************************** + Move to a specific row and column +**************************************************************************/ + +void STDCALL +mysql_data_seek(MYSQL_RES *result, my_ulonglong row) +{ + MYSQL_ROWS *tmp=0; + DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row)); + if (result->data) + for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; + result->current_row=0; + result->data_cursor = tmp; +} + +int STDCALL +mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) +{ + DBUG_ENTER("mysql_option"); + DBUG_PRINT("enter",("option: %d",(int) option)); + switch (option) { + case MYSQL_OPT_CONNECT_TIMEOUT: + mysql->options.connect_timeout= *(uint*) arg; + break; + case MYSQL_OPT_COMPRESS: + mysql->options.compress= 1; /* Remember for connect */ + mysql->options.client_flag|= CLIENT_COMPRESS; + break; + case MYSQL_OPT_NAMED_PIPE: + mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */ + break; + case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ + if (!arg || test(*(uint*) arg)) + mysql->options.client_flag|= CLIENT_LOCAL_FILES; + else + mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; + break; +#ifdef MYSQL_CLIENT + case MYSQL_INIT_COMMAND: + add_init_command(&mysql->options,arg); + break; +#endif + case MYSQL_READ_DEFAULT_FILE: + my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.my_cnf_file=my_strdup(arg,MYF(MY_WME)); + break; + case MYSQL_READ_DEFAULT_GROUP: + my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.my_cnf_group=my_strdup(arg,MYF(MY_WME)); + break; + case MYSQL_SET_CHARSET_DIR: + my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.charset_dir=my_strdup(arg,MYF(MY_WME)); + break; + case MYSQL_SET_CHARSET_NAME: + my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.charset_name=my_strdup(arg,MYF(MY_WME)); + break; + case MYSQL_OPT_PROTOCOL: + mysql->options.protocol= *(uint*) arg; + break; + case MYSQL_SHARED_MEMORY_BASE_NAME: +#ifdef HAVE_SMEM + if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) + my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); + mysql->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME)); +#endif + break; + default: + DBUG_RETURN(1); + } + DBUG_RETURN(0); +} + + +/**************************************************************************** + Functions to get information from the MySQL structure + These are functions to make shared libraries more usable. +****************************************************************************/ + +/* MYSQL_RES */ +my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res) +{ + return res->row_count; +} + +unsigned int STDCALL mysql_num_fields(MYSQL_RES *res) +{ + return res->field_count; +} + +uint STDCALL mysql_errno(MYSQL *mysql) +{ + return mysql->net.last_errno; +} + +const char * STDCALL mysql_error(MYSQL *mysql) +{ + return mysql->net.last_error; +} + +#endif /* defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT) */ + diff --git a/sql/Makefile.am b/sql/Makefile.am index a4858ab2b38..c3b7c77e252 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -46,7 +46,7 @@ mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ item_strfunc.h item_timefunc.h item_uniq.h \ item_create.h item_subselect.h item_row.h \ - mysql_priv.h \ + mysql_priv.h item_geofunc.h \ procedure.h sql_class.h sql_lex.h sql_list.h \ sql_manager.h sql_map.h sql_string.h unireg.h \ field.h handler.h \ @@ -55,19 +55,19 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ opt_range.h opt_ft.h protocol.h \ sql_select.h structs.h table.h sql_udf.h hash_filo.h\ lex.h lex_symbol.h sql_acl.h sql_crypt.h \ - log_event.h mini_client.h sql_repl.h slave.h \ + log_event.h sql_repl.h slave.h \ stacktrace.h sql_sort.h sql_cache.h set_var.h \ - spatial.h gstream.h + spatial.h gstream.h client_settings.h mysqld_SOURCES = sql_lex.cc sql_handler.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ thr_malloc.cc item_create.cc item_subselect.cc \ - item_row.cc \ + item_row.cc item_geofunc.cc \ field.cc key.cc sql_class.cc sql_list.cc \ net_serv.cc protocol.cc lock.cc my_lock.c \ sql_string.cc sql_manager.cc sql_map.cc \ mysqld.cc password.c hash_filo.cc hostname.cc \ - convert.cc set_var.cc sql_parse.cc sql_yacc.yy \ + set_var.cc sql_parse.cc sql_yacc.yy \ sql_base.cc table.cc sql_select.cc sql_insert.cc \ sql_prepare.cc sql_error.cc \ sql_update.cc sql_delete.cc uniques.cc sql_do.cc \ @@ -83,7 +83,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \ sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \ slave.cc sql_repl.cc sql_union.cc sql_derived.cc \ - mini_client.cc mini_client_errors.c pack.c\ + client.c mini_client_errors.c pack.c\ stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\ gstream.cc spatial.cc sql_help.cc protocol_cursor.cc gen_lex_hash_SOURCES = gen_lex_hash.cc @@ -104,6 +104,8 @@ link_sources: @LN_CP_F@ ../libmysql/errmsg.c mini_client_errors.c rm -f pack.c @LN_CP_F@ ../sql-common/pack.c pack.c + rm -f client.c + @LN_CP_F@ ../sql-common/client.c client.c gen_lex_hash.o: gen_lex_hash.cc lex.h $(CXXCOMPILE) -c $(INCLUDES) $< diff --git a/sql/client_settings.h b/sql/client_settings.h new file mode 100644 index 00000000000..bc4cdf2a777 --- /dev/null +++ b/sql/client_settings.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or + (at your option) any later version. + + 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 */ + + +#include <thr_alarm.h> + +extern char *mysql_unix_port; + +#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \ + | CLIENT_LOCAL_FILES | CLIENT_SECURE_CONNECTION) + + +extern ulong slave_net_timeout; +#define init_sigpipe_variables +#define set_sigpipe(mysql) +#define reset_sigpipe(mysql) + +#ifdef HAVE_SMEM +#undef HAVE_SMEM +#endif diff --git a/sql/convert.cc b/sql/convert.cc deleted file mode 100644 index bfdf49bf42d..00000000000 --- a/sql/convert.cc +++ /dev/null @@ -1,465 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or - (at your option) any later version. - - 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 */ - -#if 0 - -/* -** Convert tables between different character sets -** Some of the tables are hidden behind IFDEF to reduce some space. -** One can enable them by removing the // characters from the next comment -** One must also give a name to each mapping that one wants to use... -*/ - -/* #define DEFINE_ALL_CHARACTER_SETS */ - -#include "mysql_priv.h" - -/**************************************************************************** - Convert tables -****************************************************************************/ - -/* Windows cp1251->koi8 and reverse conversion by Timur I. Bakeyev <translate@bat.ru> */ -/* based on Russian-Apache Team tables by Dmitry M. Klimoff <dmk@kosnet.ru> */ - -static unsigned char cp1251_koi8[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, -144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, -160,161,162,163,164,189,166,167,179,169,180,171,172,173,174,183, -176,177,182,166,173,181,182,183,163,185,164,187,188,189,190,167, -225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240, -242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241, -193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208, -210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209 -}; - -static unsigned char koi8_cp1251[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, -144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, -160,161,162,184,186,165,179,191,168,169,170,171,172,180,174,175, -176,177,178,168,170,181,178,175,184,185,186,187,188,165,190,191, -254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238, -239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250, -222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206, -207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218 -}; - - -#ifdef DEFINE_ALL_CHARACTER_SETS - -/* These tables was generated from package 'cstools' (author Jan "Yenya" Kasprzak <kas@muni.cz>) */ - -/* Windows pc1250 to iso 8859-2 */ - -static unsigned char t1250_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129, 0,131, 0, 0, 0, 0,136, 0,169, 0,166,171,174,172, -144, 0, 0, 0, 0, 0, 0, 0,152, 0,185, 0,182,187,190,188, -160,183,162,163,164,161, 0,167,168, 0,170, 0, 0,173, 0,175, -176, 0,178,179,180, 0, 0, 0,184,177,186, 0,165,189,181,191, -192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, -208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, -224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, -240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 -}; - -static unsigned char til2_t1250[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129, 0,131, 0, 0, 0, 0,136, 0, 0, 0, 0, 0, 0, 0, -144, 0, 0, 0, 0, 0, 0, 0,152, 0, 0, 0, 0, 0, 0, 0, -160,165,162,163,164,188,140,167,168,138,170,141,143,173,142,175, -176,185,178,179,180,190,156,161,184,154,186,157,159,189,158,191, -192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, -208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, -224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, -240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 -}; - -/* Windows pc1252 to iso 8859-2 */ - -static unsigned char t1252_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129, 0, 0, 0, 0, 0, 0,136, 0,169, 0, 0,141,142,143, -144, 0, 0, 0, 0, 0, 0, 0,189, 0,185, 0, 0,157,158, 0, -160, 0, 0, 0,164, 0, 0,167,168, 0, 0, 0, 0,173, 0, 0, -176, 0, 0, 0,180, 0, 0, 0,184, 0, 0, 0, 0, 0, 0, 0, - 0,193,194, 0,196, 0, 0,199, 0,201, 0,203, 0,205,206, 0, -208, 0, 0,211,212, 0,214,215, 0, 0,218, 0,220,221, 0,223, - 0,225,226, 0,228, 0, 0,231, 0,233, 0,235, 0,237,238, 0, -240, 0, 0,243,244, 0,246,247, 0, 0,250, 0,252,253, 0, 0 -}; -static unsigned char til2_t1252[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129, 0, 0, 0, 0, 0, 0,136, 0, 0, 0, 0,141,142,143, -144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,157,158, 0, -160, 0, 0, 0,164, 0, 0,167,168,138, 0, 0, 0,173, 0, 0, -176, 0, 0, 0,180, 0, 0, 0,184,154, 0, 0, 0,152, 0, 0, - 0,193,194, 0,196, 0, 0,199, 0,201, 0,203, 0,205,206, 0, -208, 0, 0,211,212, 0,214,215, 0, 0,218, 0,220,221, 0,223, - 0,225,226, 0,228, 0, 0,231, 0,233, 0,235, 0,237,238, 0, -240, 0, 0,243,244, 0,246,247, 0, 0,250, 0,252,253, 0, 0 -}; - -/* MSDOS Kamenicky encoding (for Czech/Slovak) to iso 8859-2 */ - -static unsigned char tkam_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -200,252,233,239,228,207,171,232,236,204,197,205,181,229,196,193, -201,190,174,244,246,211,249,218,253,214,220,169,165,221,216,187, -225,237,243,250,242,210,217,212,185,248,224,192, 0,167, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0,247, 0,176, 0, 0, 0, 0, 0, 0, 0 -}; -static unsigned char til2_tkam[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0,156, 0,173, 0,155, 0,134, 0, 0,146, 0, -248, 0, 0, 0, 0,140, 0, 0, 0,168, 0,159, 0, 0,145, 0, -171,143, 0, 0,142,138, 0, 0,128,144, 0, 0,137,139, 0,133, - 0, 0,165,149,167, 0,153, 0,158,166,151, 0,154,157, 0, 0, -170,160, 0, 0,132,141, 0, 0,135,130, 0, 0,136,161, 0,131, - 0, 0,164,162,147, 0,148,246,169,150,163, 0,129,152, 0, 0 -}; - -/* Macintosh Roman encoding to iso 8859-2 */ - -static unsigned char tmac_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -196, 0,199,201, 0,214,220,225, 0,226,228, 0, 0,231,233, 0, - 0,235,237, 0,238, 0, 0,243, 0,244,246, 0,250, 0, 0,252, - 0,176, 0, 0,167, 0, 0,223, 0, 0, 0,180,168, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,160, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0,247, 0, 0, 0, 0,164, 0, 0, 0, 0, - 0, 0, 0, 0, 0,194, 0,193,203, 0,205,206, 0, 0,211,212, - 0, 0,218, 0, 0, 0, 0, 0, 0,162,255, 0,184,189,178,183 -}; -static unsigned char til2_tmac[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -202, 0,249, 0,219, 0, 0,164,172, 0, 0, 0, 0, 0, 0, 0, -161, 0,254, 0,171, 0, 0,255,252, 0, 0, 0, 0,253, 0, 0, - 0,231,229, 0,128, 0, 0,130, 0,131, 0,232, 0,234,235, 0, - 0, 0, 0,238,239, 0,133, 0, 0, 0,242, 0,134, 0, 0,167, - 0,135,137, 0,138, 0, 0,141, 0,142, 0,145, 0,146,148, 0, - 0, 0, 0,151,153, 0,154,214, 0, 0,156, 0,159, 0, 0,250 -}; - -/* Macintosh Central European encodingto iso 8859-2 */ - -static unsigned char tmacce_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -196, 0, 0,201,161,214,220,225,177,200,228,232,198,230,233,172, -188,207,237,239, 0, 0, 0,243, 0,244,246, 0,250,204,236,252, - 0,176,202, 0,167, 0, 0,223, 0, 0, 0,234,168, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0,179, 0, 0,165,181,197,229, 0, - 0,209, 0, 0,241,210, 0, 0, 0, 0,160,242,213, 0,245, 0, - 0, 0, 0, 0, 0, 0,247, 0, 0,192,224,216, 0, 0,248, 0, - 0,169, 0, 0,185,166,182,193,171,187,205,174,190, 0,211,212, - 0,217,218,249,219,251, 0, 0,221,253, 0,175,163,191, 0,183 -}; -static unsigned char til2_tmacce[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -202,132, 0,252, 0,187,229,164,172,225, 0,232,143, 0,235,251, -161,136, 0,184, 0,188,230,255, 0,228, 0,233,144, 0,236,253, -217,231, 0, 0,128,189,140, 0,137,131,162, 0,157,234, 0,145, - 0,193,197,238,239,204,133, 0,219,241,242,244,134,248, 0,167, -218,135, 0, 0,138,190,141, 0,139,142,171, 0,158,146, 0,147, - 0,196,203,151,153,206,154,214,222,243,156,245,159,249, 0, 0 -}; - -/* PC-Latin2 encoding, supported by M$-DOS to iso 8859-2 */ - -static unsigned char tpc2_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -199,252,233,226,228,249,230,231,179,235,213,245,238,172,196,198, -201,197,229,244,246,165,181,166,182,214,220,171,187,163,215,232, -225,237,243,250,161,177,174,190,202,234, 0,188,200,186, 0, 0, - 0, 0, 0, 0, 0,193,194,204,170, 0, 0, 0, 0,175,191, 0, - 0, 0, 0, 0, 0, 0,195,227, 0, 0, 0, 0, 0, 0, 0,164, -240,208,207,203,239,210,205,206,236, 0, 0, 0, 0,222,217, 0, -211,223,212,209,241,242,169,185,192,218,224,219,253,221,254,180, - 0,189,178,183,162,167,247,184, 0,168,255,251,216,248, 0, 0 -}; -static unsigned char til2_tpc2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0,164,244,157,207,149,151,245,249,230,184,155,141, 0,166,189, - 0,165,242,136,239,150,152,243,247,231,173,156,171,241,167,190, -232,181,182,198,142,145,143,128,172,144,168,211,183,214,215,210, -209,227,213,224,226,138,153,158,252,222,233,235,154,237,221,225, -234,160,131,199,132,146,134,135,159,130,169,137,216,161,140,212, -208,228,229,162,147,139,148,246,253,133,163,251,129,236,238,250 -}; - -/* Encoding used by standard IBM PC vga cards to iso8859-2 */ -static unsigned char tvga_til2[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -199,252,233,226,228, 0, 0,231, 0,235, 0, 0,238, 0,196, 0, -201, 0, 0,244,246, 0, 0, 0, 0,214,220, 0, 0, 0, 0, 0, -225,237,243,250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0,247, 0,176, 0, 0, 0, 0, 0, 0, 0 -}; -static unsigned char til2_tvga[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0,142, 0, 0,128, 0,144, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0,153, 0, 0, 0, 0, 0,154, 0, 0, 0, - 0,160,131, 0,132, 0, 0,135, 0,130, 0,137, 0,161,140, 0, - 0, 0, 0,162,147, 0,148,246, 0, 0,163, 0,129, 0, 0, 0 -}; - -//Ukrainian koi8 and win1251 converting tables by Max Veremayenko -//(verem@tg.kiev.ua - -static unsigned char koi8_ukr_win1251ukr[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, -144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, -160,161,162,184,186,165,179,191,168,169,170,171,172,180,174,175, -176,177,178,168,170,181,178,175,184,185,186,187,188,165,190,191, -254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238, -239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250, -222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206, -207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218 -}; - -static unsigned char win1251ukr_koi8_ukr[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, -144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, -160,161,162,163,164,189,166,167,179,169,180,171,172,173,174,183, -176,177,182,166,173,181,182,183,163,185,164,187,188,189,190,167, -225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240, -242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241, -193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208, -210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209 -}; - -#endif /* DEFINE_ALL_CHARACTER_SETS */ - -/**************************************************************************** -** Declare mapping variables -****************************************************************************/ - - -CONVERT conv_cp1251_koi8("cp1251_koi8", cp1251_koi8, koi8_cp1251, 1); -#ifdef DEFINE_ALL_CHARACTER_SETS -CONVERT conv_cp1250_latin2("cp1250_latin2", t1250_til2, til2_t1250, 2); -CONVERT conv_kam_latin2("kam_latin2", tkam_til2, til2_tkam, 3); -CONVERT conv_mac_latin2("mac_latin2", tmac_til2, til2_tmac, 4); -CONVERT conv_macce_latin2("macce_latin2", tmacce_til2, til2_tmacce, 5); -CONVERT conv_pc2_latin2("pc2_latin2", tpc2_til2, til2_tpc2, 6); -CONVERT conv_vga_latin2("vga_latin2", tvga_til2, til2_tvga, 7); -CONVERT conv_koi8_cp1251("koi8_cp1251", koi8_cp1251, cp1251_koi8, 8); -CONVERT conv_win1251ukr_koi8_ukr("win1251ukr_koi8_ukr", win1251ukr_koi8_ukr, - koi8_ukr_win1251ukr, 9); -CONVERT conv_koi8_ukr_win1251ukr("koi8_ukr_win1251ukr", koi8_ukr_win1251ukr, - win1251ukr_koi8_ukr, 10); -#endif /* DEFINE_ALL_CHARACTER_SETS */ - -CONVERT *convert_tables[]= { - &conv_cp1251_koi8, -#ifdef DEFINE_ALL_CHARACTER_SETS - &conv_cp1250_latin2, - &conv_kam_latin2, - &conv_mac_latin2, - &conv_macce_latin2, - &conv_pc2_latin2, - &conv_vga_latin2, - &conv_koi8_cp1251, - &conv_win1251ukr_koi8_ukr, - &conv_koi8_ukr_win1251ukr, -#endif /* DEFINE_ALL_CHARACTER_SETS */ - NULL -}; - - -CONVERT *get_convert_set(const char *name) -{ - for (CONVERT **ptr=convert_tables ; *ptr ; ptr++) - { - if (!my_strcasecmp(&my_charset_latin1,(*ptr)->name,name)) - return (*ptr); - } - return 0; -} - - -void CONVERT::convert_array(const uchar *map, uchar * buf, uint len) -{ - for (uchar *end=buf+len ; buf != end ; buf++) - *buf= map[*buf]; -} - - -/* This is identical as net_store_data, but with a conversion */ - -bool CONVERT::store(String *packet,const char *from,uint length) -{ - uint packet_length=packet->length(); - if (packet_length+5+length > packet->alloced_length() && - packet->realloc(packet_length+5+length)) - return 1; - char *to=(char*) net_store_length((char*) packet->ptr()+packet_length, - (ulonglong)length); - packet->length((uint) (store_dest(to, from, length)-packet->ptr())); - return 0; -} - -#endif diff --git a/sql/field.cc b/sql/field.cc index e54986ded22..04859dd22e0 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -161,6 +161,14 @@ static bool test_if_real(const char *str,int length, CHARSET_INFO *cs) } +static inline uint field_length_without_space(const char *ptr, uint length) +{ + const char *end= ptr+length; + while (end > ptr && end[-1] == ' ') + end--; + return (uint) (end-ptr); +} + /**************************************************************************** ** Functions for the base classes ** This is an unpacked number. @@ -246,26 +254,6 @@ void Field_str::make_field(Send_field *field) } -void Field_str::add_binary_or_charset(String &res) const -{ - if (charset() == &my_charset_bin) - res.append(" binary"); - else if (field_charset != table->table_charset && - !(current_thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS) && - !(current_thd->variables.sql_mode & MODE_MYSQL323) && - !(current_thd->variables.sql_mode & MODE_MYSQL40) && - !(current_thd->variables.sql_mode & MODE_POSTGRESQL) && - !(current_thd->variables.sql_mode & MODE_ORACLE) && - !(current_thd->variables.sql_mode & MODE_MSSQL) && - !(current_thd->variables.sql_mode & MODE_DB2) && - !(current_thd->variables.sql_mode & MODE_SAPDB)) - { - res.append(" character set "); - res.append(field_charset->csname); - } -} - - uint Field::fill_cache_field(CACHE_FIELD *copy) { copy->str=ptr; @@ -347,7 +335,7 @@ bool Field::optimize_range(uint idx) void Field_null::sql_type(String &res) const { - res.set_latin1("null", 4); + res.set_ascii("null", 4); } @@ -367,7 +355,7 @@ void Field_decimal::overflow(bool negative) uint len=field_length; char *to=ptr, filler= '9'; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); if (negative) { if (!unsigned_flag) @@ -477,7 +465,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) from++; if (from == end) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); is_cuted_fields_incr=1; } else if (*from == '+' || *from == '-') // Found some sign ? @@ -553,7 +541,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) for (;from != end && my_isspace(&my_charset_bin, *from); from++) ; if (from != end) // If still something left, warn { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); is_cuted_fields_incr=1; } } @@ -731,7 +719,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) if (tmp_char != '0') // Losing a non zero digit ? { if (!is_cuted_fields_incr) - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); return 0; } continue; @@ -748,7 +736,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) if (tmp_char != '0') // Losing a non zero digit ? { if (!is_cuted_fields_incr) - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); return 0; } continue; @@ -868,7 +856,7 @@ String *Field_decimal::val_str(String *val_buffer __attribute__((unused)), if (field_length < tmp_length) // Error in data val_ptr->length(0); else - val_ptr->set_latin1((const char*) str, field_length-tmp_length); + val_ptr->set_ascii((const char*) str, field_length-tmp_length); return val_ptr; } @@ -944,7 +932,7 @@ void Field_decimal::sql_type(String &res) const tmp--; if (dec) tmp--; - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "decimal(%d,%d)",tmp,dec)); add_zerofill_and_unsigned(res); } @@ -966,18 +954,18 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < 0) { tmp=0; /* purecov: inspected */ - current_thd->cuted_fields++; /* purecov: inspected */ + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (tmp > 255) { tmp= 255; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } } @@ -986,18 +974,18 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < -128) { tmp= -128; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (tmp >= 128) { tmp= 127; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } } @@ -1015,13 +1003,13 @@ int Field_tiny::store(double nr) if (nr < 0.0) { *ptr=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > 255.0) { *ptr=(char) 255; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1032,13 +1020,13 @@ int Field_tiny::store(double nr) if (nr < -128.0) { *ptr= (char) -128; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > 127.0) { *ptr=127; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1055,13 +1043,13 @@ int Field_tiny::store(longlong nr) if (nr < 0L) { *ptr=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > 255L) { *ptr= (char) 255; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1072,13 +1060,13 @@ int Field_tiny::store(longlong nr) if (nr < -128L) { *ptr= (char) -128; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > 127L) { *ptr=127; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1112,9 +1100,11 @@ String *Field_tiny::val_str(String *val_buffer, char *to=(char*) val_buffer->ptr(); if (unsigned_flag) - length= (uint) cs->long10_to_str(cs,to,mlength, 10,(long) *((uchar*) ptr)); + length= (uint) cs->cset->long10_to_str(cs,to,mlength, 10, + (long) *((uchar*) ptr)); else - length= (uint) cs->long10_to_str(cs,to,mlength,-10,(long) *((signed char*) ptr)); + length= (uint) cs->cset->long10_to_str(cs,to,mlength,-10, + (long) *((signed char*) ptr)); val_buffer->length(length); if (zerofill) @@ -1147,7 +1137,7 @@ void Field_tiny::sort_string(char *to,uint length __attribute__((unused))) void Field_tiny::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "tinyint(%d)",(int) field_length)); add_zerofill_and_unsigned(res); } @@ -1168,18 +1158,18 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < 0) { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (tmp > (uint16) ~0) { tmp=(uint16) ~0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } } @@ -1188,18 +1178,18 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < INT_MIN16) { tmp= INT_MIN16; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (tmp > INT_MAX16) { tmp=INT_MAX16; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } } @@ -1225,13 +1215,13 @@ int Field_short::store(double nr) if (nr < 0) { res=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (double) (uint16) ~0) { res=(int16) (uint16) ~0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1242,13 +1232,13 @@ int Field_short::store(double nr) if (nr < (double) INT_MIN16) { res=INT_MIN16; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (double) INT_MAX16) { res=INT_MAX16; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1274,13 +1264,13 @@ int Field_short::store(longlong nr) if (nr < 0L) { res=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (longlong) (uint16) ~0) { res=(int16) (uint16) ~0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1291,13 +1281,13 @@ int Field_short::store(longlong nr) if (nr < INT_MIN16) { res=INT_MIN16; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > INT_MAX16) { res=INT_MAX16; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1357,9 +1347,10 @@ String *Field_short::val_str(String *val_buffer, shortget(j,ptr); if (unsigned_flag) - length=(uint) cs->long10_to_str(cs, to, mlength, 10, (long) (uint16) j); + length=(uint) cs->cset->long10_to_str(cs, to, mlength, 10, + (long) (uint16) j); else - length=(uint) cs->long10_to_str(cs, to, mlength,-10, (long) j); + length=(uint) cs->cset->long10_to_str(cs, to, mlength,-10, (long) j); val_buffer->length(length); if (zerofill) prepend_zeros(val_buffer); @@ -1420,7 +1411,7 @@ void Field_short::sort_string(char *to,uint length __attribute__((unused))) void Field_short::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "smallint(%d)",(int) field_length)); add_zerofill_and_unsigned(res); } @@ -1442,18 +1433,18 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < 0) { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (tmp >= (long) (1L << 24)) { tmp=(long) (1L << 24)-1L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } } @@ -1462,18 +1453,18 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < INT_MIN24) { tmp= INT_MIN24; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (tmp > INT_MAX24) { tmp=INT_MAX24; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } } @@ -1492,14 +1483,14 @@ int Field_medium::store(double nr) if (nr < 0) { int3store(ptr,0); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr >= (double) (long) (1L << 24)) { uint32 tmp=(uint32) (1L << 24)-1L; int3store(ptr,tmp); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1511,14 +1502,14 @@ int Field_medium::store(double nr) { long tmp=(long) INT_MIN24; int3store(ptr,tmp); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (double) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1535,14 +1526,14 @@ int Field_medium::store(longlong nr) if (nr < 0L) { int3store(ptr,0); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr >= (longlong) (long) (1L << 24)) { long tmp=(long) (1L << 24)-1L;; int3store(ptr,tmp); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1554,14 +1545,14 @@ int Field_medium::store(longlong nr) { long tmp=(long) INT_MIN24; int3store(ptr,tmp); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (longlong) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1595,7 +1586,7 @@ String *Field_medium::val_str(String *val_buffer, char *to=(char*) val_buffer->ptr(); long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr); - length=(uint) cs->long10_to_str(cs,to,mlength,-10,j); + length=(uint) cs->cset->long10_to_str(cs,to,mlength,-10,j); val_buffer->length(length); if (zerofill) prepend_zeros(val_buffer); /* purecov: inspected */ @@ -1639,7 +1630,7 @@ void Field_medium::sort_string(char *to,uint length __attribute__((unused))) void Field_medium::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "mediumint(%d)",(int) field_length)); add_zerofill_and_unsigned(res); } @@ -1655,7 +1646,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) int error= 0; char *end; - tmp= cs->scan(cs, from, from+len, MY_SEQ_SPACES); + tmp= cs->cset->scan(cs, from, from+len, MY_SEQ_SPACES); len-= tmp; from+= tmp; my_errno=0; @@ -1676,7 +1667,8 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) (from+len != end && current_thd->count_cuted_fields && !test_if_int(from,len,end,cs))) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + error= 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -1700,13 +1692,13 @@ int Field_long::store(double nr) if (nr < 0) { res=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (double) (ulong) ~0L) { res=(int32) (uint32) ~0L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1717,13 +1709,13 @@ int Field_long::store(double nr) if (nr < (double) INT_MIN32) { res=(int32) INT_MIN32; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (double) INT_MAX32) { res=(int32) INT_MAX32; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1750,13 +1742,13 @@ int Field_long::store(longlong nr) if (nr < 0) { res=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr >= (LL(1) << 32)) { res=(int32) (uint32) ~0L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1767,13 +1759,13 @@ int Field_long::store(longlong nr) if (nr < (longlong) INT_MIN32) { res=(int32) INT_MIN32; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > (longlong) INT_MAX32) { res=(int32) INT_MAX32; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1832,9 +1824,9 @@ String *Field_long::val_str(String *val_buffer, longget(j,ptr); if (unsigned_flag) - length=cs->long10_to_str(cs,to,mlength, 10,(long) (uint32)j); + length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32)j); else - length=cs->long10_to_str(cs,to,mlength,-10,(long) j); + length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j); val_buffer->length(length); if (zerofill) prepend_zeros(val_buffer); @@ -1897,7 +1889,7 @@ void Field_long::sort_string(char *to,uint length __attribute__((unused))) void Field_long::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int(%d)",(int) field_length)); add_zerofill_and_unsigned(res); } @@ -1912,7 +1904,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) int error= 0; char *end; - tmp= cs->scan(cs, from, from+len, MY_SEQ_SPACES); + tmp= cs->cset->scan(cs, from, from+len, MY_SEQ_SPACES); len-= (uint)tmp; from+= tmp; my_errno=0; @@ -1932,7 +1924,10 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) if (error || (from+len != end && current_thd->count_cuted_fields && !test_if_int(from,len,end,cs))) - current_thd->cuted_fields++; + { + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + error= 1; + } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -1955,13 +1950,13 @@ int Field_longlong::store(double nr) if (nr < 0) { res=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr >= (double) ~ (ulonglong) 0) { res= ~(longlong) 0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -1972,13 +1967,13 @@ int Field_longlong::store(double nr) if (nr <= (double) LONGLONG_MIN) { res=(longlong) LONGLONG_MIN; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr >= (double) LONGLONG_MAX) { res=(longlong) LONGLONG_MAX; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -2053,7 +2048,7 @@ String *Field_longlong::val_str(String *val_buffer, #endif longlongget(j,ptr); - length=(uint) (cs->longlong10_to_str)(cs,to,mlength, + length=(uint) (cs->cset->longlong10_to_str)(cs,to,mlength, unsigned_flag ? 10 : -10, j); val_buffer->length(length); if (zerofill) @@ -2127,7 +2122,7 @@ void Field_longlong::sort_string(char *to,uint length __attribute__((unused))) void Field_longlong::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint(%d)",(int) field_length)); add_zerofill_and_unsigned(res); } @@ -2142,7 +2137,7 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) Field_float::store(my_strntod(cs,(char*) from,len,(char**)NULL,&err)); if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); return 1; } return (err) ? 1 : 0; @@ -2157,20 +2152,20 @@ int Field_float::store(double nr) nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point if (unsigned_flag && nr < 0) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); nr=0; error= 1; } if (nr < -FLT_MAX) { j= -FLT_MAX; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr > FLT_MAX) { j=FLT_MAX; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -2193,7 +2188,7 @@ int Field_float::store(longlong nr) float j= (float) nr; if (unsigned_flag && j < 0) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); j=0; error= 1; } @@ -2394,12 +2389,12 @@ void Field_float::sql_type(String &res) const { if (dec == NOT_FIXED_DEC) { - res.set_latin1("float", 5); + res.set_ascii("float", 5); } else { CHARSET_INFO *cs= res.charset(); - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "float(%d,%d)",(int) field_length,dec)); } add_zerofill_and_unsigned(res); @@ -2415,11 +2410,12 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) double j= my_strntod(cs,(char*) from,len,(char**)0,&err); if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs)) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + err= 1; } if (unsigned_flag && j < 0) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); j=0; err= 1; } @@ -2442,7 +2438,7 @@ int Field_double::store(double nr) nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point if (unsigned_flag && nr < 0) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); nr=0; error= 1; } @@ -2464,7 +2460,7 @@ int Field_double::store(longlong nr) int error= 0; if (unsigned_flag && j < 0) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; j=0; } @@ -2651,11 +2647,11 @@ void Field_double::sql_type(String &res) const CHARSET_INFO *cs=res.charset(); if (dec == NOT_FIXED_DEC) { - res.set_latin1("double",6); + res.set_ascii("double",6); } else { - res.length(cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "double(%d,%d)",(int) field_length,dec)); } add_zerofill_and_unsigned(res); @@ -2705,7 +2701,7 @@ int Field_timestamp::store(double nr) if (nr < 0 || nr > 99991231235959.0) { nr= 0; // Avoid overflow on buff - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } error|= Field_timestamp::store((longlong) rint(nr)); @@ -2721,6 +2717,7 @@ int Field_timestamp::store(double nr) static longlong fix_datetime(longlong nr) { + current_thd->last_cuted_field= 0; if (nr == LL(0) || nr >= LL(10000101000000)) return nr; // Normal datetime >= Year 1000 if (nr < 101) @@ -2745,7 +2742,7 @@ static longlong fix_datetime(longlong nr) return nr+LL(19000000000000); // YYMMDDHHMMSS, 1970-1999 err: - current_thd->cuted_fields++; + current_thd->last_cuted_field= 1; return LL(0); } @@ -2778,6 +2775,8 @@ int Field_timestamp::store(longlong nr) else #endif longstore(ptr,(uint32) timestamp); + if (current_thd->last_cuted_field) + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); return 0; } @@ -2988,7 +2987,7 @@ void Field_timestamp::sort_string(char *to,uint length __attribute__((unused))) void Field_timestamp::sql_type(String &res) const { - res.set_latin1("timestamp", 9); + res.set_ascii("timestamp", 9); } @@ -3021,6 +3020,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0L; error= 1; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } else { @@ -3030,7 +3030,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp > 8385959) { tmp=8385959; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } } @@ -3048,13 +3048,13 @@ int Field_time::store(double nr) if (nr > 8385959.0) { tmp=8385959L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr < -8385959.0) { tmp= -8385959L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3065,7 +3065,7 @@ int Field_time::store(double nr) if (tmp % 100 > 59 || tmp/100 % 100 > 59) { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } } @@ -3081,13 +3081,13 @@ int Field_time::store(longlong nr) if (nr > (longlong) 8385959L) { tmp=8385959L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else if (nr < (longlong) -8385959L) { tmp= -8385959L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3096,7 +3096,7 @@ int Field_time::store(longlong nr) if (tmp % 100 > 59 || tmp/100 % 100 > 59) { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } } @@ -3186,7 +3186,7 @@ void Field_time::sort_string(char *to,uint length __attribute__((unused))) void Field_time::sql_type(String &res) const { - res.set_latin1("time", 4); + res.set_ascii("time", 4); } /**************************************************************************** @@ -3204,11 +3204,11 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs) if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { *ptr=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); return 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); if (nr != 0 || len != 4) { if (nr < YY_PART_YEAR) @@ -3236,7 +3236,7 @@ int Field_year::store(longlong nr) if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { *ptr=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); return 1; } if (nr != 0 || field_length != 4) // 0000 -> 0; 00 -> 2000 @@ -3284,7 +3284,7 @@ String *Field_year::val_str(String *val_buffer, void Field_year::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - res.length(cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(), + res.length(cs->cset->snprintf(cs,(char*)res.ptr(),res.alloced_length(), "year(%d)",(int) field_length)); } @@ -3305,6 +3305,7 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) { tmp=0; error= 1; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } else tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day); @@ -3329,7 +3330,7 @@ int Field_date::store(double nr) if (nr < 0.0 || nr > 99991231.0) { tmp=0L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3355,7 +3356,7 @@ int Field_date::store(longlong nr) if (nr < 0 || nr > LL(99991231)) { tmp=0L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3466,7 +3467,7 @@ void Field_date::sort_string(char *to,uint length __attribute__((unused))) void Field_date::sql_type(String &res) const { - res.set_latin1("date", 4); + res.set_ascii("date", 4); } /**************************************************************************** @@ -3484,6 +3485,7 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0L; error= 1; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } else tmp= l_time.day + l_time.month*32 + l_time.year*16*32; @@ -3496,6 +3498,7 @@ int Field_newdate::store(double nr) if (nr < 0.0 || nr > 99991231235959.0) { (void) Field_newdate::store((longlong) -1); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); return 1; } else @@ -3512,7 +3515,7 @@ int Field_newdate::store(longlong nr) if (nr < 0L || nr > 99991231L) { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3530,7 +3533,7 @@ int Field_newdate::store(longlong nr) if (month > 12 || day > 31) { tmp=0L; // Don't allow date to change - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3548,7 +3551,7 @@ void Field_newdate::store_time(TIME *ltime,timestamp_type type) else { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } int3store(ptr,tmp); } @@ -3604,11 +3607,11 @@ bool Field_newdate::get_date(TIME *ltime,bool fuzzydate) if (is_null()) return 1; uint32 tmp=(uint32) uint3korr(ptr); - bzero((char*) ltime,sizeof(*ltime)); ltime->day= tmp & 31; ltime->month= (tmp >> 5) & 15; ltime->year= (tmp >> 9); ltime->time_type=TIMESTAMP_DATE; + ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; return (!fuzzydate && (!ltime->month || !ltime->day)) ? 1 : 0; } @@ -3634,7 +3637,7 @@ void Field_newdate::sort_string(char *to,uint length __attribute__((unused))) void Field_newdate::sql_type(String &res) const { - res.set_latin1("date", 4); + res.set_ascii("date", 4); } @@ -3666,7 +3669,7 @@ int Field_datetime::store(double nr) if (nr < 0.0 || nr > 99991231235959.0) { nr=0.0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } error |= Field_datetime::store((longlong) rint(nr)); @@ -3680,7 +3683,7 @@ int Field_datetime::store(longlong nr) if (nr < 0 || nr > LL(99991231235959)) { nr=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } else @@ -3693,6 +3696,8 @@ int Field_datetime::store(longlong nr) else #endif longlongstore(ptr,nr); + if (current_thd->last_cuted_field) + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); return error; } @@ -3705,7 +3710,7 @@ void Field_datetime::store_time(TIME *ltime,timestamp_type type) else { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -3865,7 +3870,7 @@ void Field_datetime::sort_string(char *to,uint length __attribute__((unused))) void Field_datetime::sql_type(String &res) const { - res.set_latin1("datetime", 8); + res.set_ascii("datetime", 8); } /**************************************************************************** @@ -3896,7 +3901,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) { memcpy(ptr,from,length); if (length < field_length) - field_charset->fill(field_charset,ptr+length,field_length-length,' '); + field_charset->cset->fill(field_charset,ptr+length,field_length-length,' '); } else { @@ -3905,10 +3910,10 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) { // Check if we loosed some info const char *end=from+length; from+= field_length; - from+= field_charset->scan(field_charset, from, end, MY_SEQ_SPACES); + from+= field_charset->cset->scan(field_charset, from, end, MY_SEQ_SPACES); if (from != end) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error=1; } } @@ -3932,7 +3937,7 @@ int Field_string::store(longlong nr) char buff[64]; int l; CHARSET_INFO *cs=charset(); - l= (cs->longlong10_to_str)(cs,buff,sizeof(buff),-10,nr); + l= (cs->cset->longlong10_to_str)(cs,buff,sizeof(buff),-10,nr); return Field_string::store(buff,(uint)l,cs); } @@ -3969,9 +3974,19 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)), int Field_string::cmp(const char *a_ptr, const char *b_ptr) { - return my_strnncoll(field_charset, - (const uchar*)a_ptr,field_length, - (const uchar*)b_ptr,field_length); + if (field_charset->strxfrm_multiply > 1) + { + /* + We have to remove end space to be able to compare multi-byte-characters + like in latin_de 'ae' and 0xe4 + */ + return field_charset->coll->strnncollsp(field_charset, + (const uchar*) a_ptr, field_length, + (const uchar*) b_ptr, field_length); + } + return field_charset->coll->strnncoll(field_charset, + (const uchar*) a_ptr, field_length, + (const uchar*) b_ptr, field_length); } void Field_string::sort_string(char *to,uint length) @@ -3987,7 +4002,7 @@ void Field_string::sort_string(char *to,uint length) void Field_string::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - ulong length= cs->snprintf(cs,(char*) res.ptr(), + ulong length= cs->cset->snprintf(cs,(char*) res.ptr(), res.alloced_length(), "%s(%d)", (field_length > 3 && (table->db_options_in_use & @@ -3995,7 +4010,6 @@ void Field_string::sql_type(String &res) const "varchar" : "char"), (int) field_length); res.length(length); - add_binary_or_charset(res); } @@ -4077,7 +4091,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) if (length > field_length) { length=field_length; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error= 1; } memcpy(ptr+2,from,length); @@ -4101,7 +4115,7 @@ int Field_varstring::store(longlong nr) char buff[64]; int l; CHARSET_INFO *cs=charset(); - l= (cs->longlong10_to_str)(cs,buff,sizeof(buff),-10,nr); + l= (cs->cset->longlong10_to_str)(cs,buff,sizeof(buff),-10,nr); return Field_varstring::store(buff,(uint)l,cs); } @@ -4158,11 +4172,10 @@ void Field_varstring::sort_string(char *to,uint length) void Field_varstring::sql_type(String &res) const { CHARSET_INFO *cs=res.charset(); - ulong length= cs->snprintf(cs,(char*) res.ptr(), + ulong length= cs->cset->snprintf(cs,(char*) res.ptr(), res.alloced_length(),"varchar(%u)", field_length); res.length(length); - add_binary_or_charset(res); } char *Field_varstring::pack(char *to, const char *from, uint max_length) @@ -4300,7 +4313,7 @@ void Field_blob::store_length(uint32 number) if (number > 255) { number=255; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } ptr[0]= (uchar) number; break; @@ -4308,7 +4321,7 @@ void Field_blob::store_length(uint32 number) if (number > (uint16) ~0) { number= (uint16) ~0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -4323,7 +4336,7 @@ void Field_blob::store_length(uint32 number) if (number > (uint32) (1L << 24)) { number= (uint32) (1L << 24)-1L; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } int3store(ptr,number); break; @@ -4602,17 +4615,12 @@ void Field_blob::sql_type(String &res) const case 3: str="medium"; length= 6; break; case 4: str="long"; length=4; break; } - res.set_latin1(str,length); + res.set_ascii(str,length); if (charset() == &my_charset_bin) res.append("blob"); else { res.append("text"); - if (field_charset != table->table_charset) - { - res.append(" character set "); - res.append(field_charset->csname); - } } } @@ -4934,11 +4942,11 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) if (err || end != from+length || tmp > typelib->count) { tmp=0; - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } } else - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } store_type((ulonglong) tmp); return err; @@ -4956,7 +4964,7 @@ int Field_enum::store(longlong nr) int error= 0; if ((uint) nr > typelib->count || nr == 0) { - current_thd->cuted_fields++; + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); nr=0; error=1; } @@ -5066,7 +5074,6 @@ void Field_enum::sql_type(String &res) const flag=1; } res.append(')'); - add_binary_or_charset(res); } @@ -5084,7 +5091,7 @@ void Field_enum::sql_type(String &res) const */ ulonglong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, - uint *err_len) + uint *err_len, bool *set_warning) { const char *end= x + length; *err_pos= 0; // No error yet @@ -5095,8 +5102,7 @@ ulonglong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, ulonglong found= 0; if (x != end) { - const char *start= x; - bool error= 0; + const char *start= x; for (;;) { const char *pos= start; @@ -5109,7 +5115,7 @@ ulonglong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, { *err_pos= (char*) start; *err_len= var_len; - error= 1; + *set_warning= 1; } else found|= ((longlong) 1 << (find - 1)); @@ -5117,8 +5123,6 @@ ulonglong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, break; start= pos + 1; } - if (error) - current_thd->cuted_fields++; } return found; } @@ -5126,6 +5130,7 @@ ulonglong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) { + bool set_warning= 0; int err= 0; char *not_used; uint not_used2; @@ -5138,7 +5143,7 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) from= tmpstr.ptr(); length= tmpstr.length(); } - ulonglong tmp= find_set(typelib, from, length, ¬_used, ¬_used2); + ulonglong tmp= find_set(typelib, from, length, ¬_used, ¬_used2, &set_warning); if (!tmp && length && length < 22) { /* This is for reading numbers with LOAD DATA INFILE */ @@ -5147,10 +5152,12 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) if (err || end != from+length || tmp > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1)) { - tmp=0; + tmp=0; + current_thd->cuted_fields++; + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, ER(ER_WARN_DATA_TRUNCATED), + field_name, 0); } - else - current_thd->cuted_fields--; // Remove warning from find_set } store_type(tmp); return err; @@ -5163,8 +5170,8 @@ int Field_set::store(longlong nr) if ((ulonglong) nr > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1)) { - nr&= (longlong) (((longlong) 1 << typelib->count) - (longlong) 1); - current_thd->cuted_fields++; + nr&= (longlong) (((longlong) 1 << typelib->count) - (longlong) 1); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); error=1; } store_type((ulonglong) nr); @@ -5211,7 +5218,6 @@ void Field_set::sql_type(String &res) const flag=1; } res.append(')'); - add_binary_or_charset(res); } /* returns 1 if the fields are equally defined */ @@ -5480,3 +5486,13 @@ create_field::create_field(Field *old_field,Field *orig_field) geom_type= ((Field_geom*)old_field)->geom_type; } } + + +/* Warning handling */ +void Field::set_warning(const uint level, const uint code) +{ + THD *thd= current_thd; + thd->cuted_fields++; + push_warning_printf(thd, (MYSQL_ERROR::enum_warning_level) level, + code, ER(code), field_name, thd->row_count); +} diff --git a/sql/field.h b/sql/field.h index 088dae49c6f..21f2ab4b6e9 100644 --- a/sql/field.h +++ b/sql/field.h @@ -84,7 +84,8 @@ public: virtual void reset_fields() {} virtual void set_default() { - my_ptrdiff_t offset = table->default_values - table->record[0]; + my_ptrdiff_t offset = (my_ptrdiff_t) (table->default_values - + table->record[0]); memcpy(ptr, ptr + offset, pack_length()); if (null_ptr) *null_ptr= ((*null_ptr & (uchar) ~null_bit) | @@ -135,6 +136,8 @@ public: Field *tmp= (Field*) memdup_root(root,(char*) this,size_of()); if (tmp) { + if (tmp->table->maybe_null) + tmp->flags&= ~NOT_NULL_FLAG; tmp->table= new_table; tmp->key_start= tmp->part_of_key= tmp->part_of_sortkey= 0; tmp->unireg_check=Field::NONE; @@ -210,7 +213,9 @@ public: virtual bool get_date(TIME *ltime,bool fuzzydate); virtual bool get_time(TIME *ltime); virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } + virtual bool has_charset(void) const { return FALSE; } virtual void set_charset(CHARSET_INFO *charset) { } + void set_warning(const unsigned int level, const unsigned int code); friend bool reopen_table(THD *,struct st_table *,bool); friend int cre_myisam(my_string name, register TABLE *form, uint options, ulonglong auto_increment_value); @@ -274,12 +279,10 @@ public: flags|=BINARY_FLAG; } Item_result result_type () const { return STRING_RESULT; } - void add_binary_or_charset(String &res) const; uint decimals() const { return NOT_FIXED_DEC; } void make_field(Send_field *); uint size_of() const { return sizeof(*this); } CHARSET_INFO *charset(void) const { return field_charset; } - void set_charset(CHARSET_INFO *charset) { field_charset=charset; } bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; } friend class create_field; @@ -786,7 +789,7 @@ public: enum ha_base_keytype key_type() const { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; } bool zero_pack() const { return 0; } - void reset(void) { charset()->fill(charset(),ptr,field_length,' '); } + void reset(void) { charset()->cset->fill(charset(),ptr,field_length,' '); } int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr); @@ -804,6 +807,7 @@ public: uint max_packed_col_length(uint max_length); uint size_of() const { return sizeof(*this); } enum_field_types real_type() const { return FIELD_TYPE_STRING; } + bool has_charset(void) const { return TRUE; } }; @@ -846,6 +850,7 @@ public: uint max_packed_col_length(uint max_length); uint size_of() const { return sizeof(*this); } enum_field_types real_type() const { return FIELD_TYPE_VAR_STRING; } + bool has_charset(void) const { return TRUE; } }; @@ -933,6 +938,8 @@ public: inline void clear_temporary() { bzero((char*) &value,sizeof(value)); } friend void field_conv(Field *to,Field *from); uint size_of() const { return sizeof(*this); } + bool has_charset(void) const + { return charset() == &my_charset_bin ? FALSE : TRUE; } }; @@ -1001,6 +1008,7 @@ public: virtual bool zero_pack() const { return 0; } bool optimize_range(uint idx) { return 0; } bool eq_def(Field *field); + bool has_charset(void) const { return TRUE; } }; @@ -1025,6 +1033,7 @@ public: String *val_str(String*,String *); void sql_type(String &str) const; enum_field_types real_type() const { return FIELD_TYPE_SET; } + bool has_charset(void) const { return TRUE; } }; @@ -1109,7 +1118,7 @@ bool set_field_to_null(Field *field); bool set_field_to_null_with_conversions(Field *field, bool no_conversions); uint find_enum(TYPELIB *typelib,const char *x, uint length); ulonglong find_set(TYPELIB *typelib,const char *x, uint length, - char **err_pos, uint *err_len); + char **err_pos, uint *err_len, bool *set_warning); bool test_if_int(const char *str, int length, const char *int_end, CHARSET_INFO *cs); diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 47996606638..ec2488f520a 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -121,7 +121,7 @@ set_field_to_null(Field *field) field->reset(); if (current_thd->count_cuted_fields) { - current_thd->cuted_fields++; // Increment error counter + field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_DATA_TRUNCATED); return 0; } if (!current_thd->no_errors) @@ -175,7 +175,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions) return 0; // field is set in handler.cc if (current_thd->count_cuted_fields) { - current_thd->cuted_fields++; // Increment error counter + field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_NULL_TO_NOTNULL); return 0; } if (!current_thd->no_errors) @@ -225,7 +225,8 @@ static void do_copy_not_null(Copy_field *copy) { if (*copy->from_null_ptr & copy->from_bit) { - current_thd->cuted_fields++; + copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED); copy->to_field->reset(); } else @@ -324,7 +325,8 @@ static void do_cut_string(Copy_field *copy) { if (!my_isspace(system_charset_info, *ptr)) // QQ: ucs incompatible { - current_thd->cuted_fields++; // Give a warning + copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED); break; } } @@ -344,7 +346,8 @@ static void do_varstring(Copy_field *copy) { length=copy->to_length-2; if (current_thd->count_cuted_fields) - current_thd->cuted_fields++; // Increment error counter + copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED); } int2store(copy->to_ptr,length); memcpy(copy->to_ptr+2, copy->from_ptr,length); diff --git a/sql/filesort.cc b/sql/filesort.cc index a3d24cd9242..2130bdaeb93 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -76,7 +76,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ulong memavl, min_sort_memory; uint maxbuffer; BUFFPEK *buffpek; - ha_rows records; + ha_rows records= HA_POS_ERROR; uchar **sort_keys; IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile; SORTPARAM param; @@ -494,6 +494,7 @@ static void make_sortkey(register SORTPARAM *param, sort_field != param->end ; sort_field++) { + bool maybe_null=0; if ((field=sort_field->field)) { // Field if (field->maybe_null()) @@ -519,7 +520,7 @@ static void make_sortkey(register SORTPARAM *param, case STRING_RESULT: { CHARSET_INFO *cs=item->charset(); - if (item->maybe_null) + if ((maybe_null=item->maybe_null)) *to++=1; /* All item->str() to use some extra byte for end null.. */ String tmp((char*) to,sort_field->length+4,cs); @@ -567,7 +568,7 @@ static void make_sortkey(register SORTPARAM *param, case INT_RESULT: { longlong value=item->val_int(); - if (item->maybe_null) + if ((maybe_null=item->maybe_null)) *to++=1; /* purecov: inspected */ if (item->null_value) { @@ -601,13 +602,13 @@ static void make_sortkey(register SORTPARAM *param, case REAL_RESULT: { double value=item->val(); - if (item->null_value) + if ((maybe_null=item->null_value)) { bzero((char*) to,sort_field->length+1); to++; break; } - if (item->maybe_null) + if ((maybe_null=item->maybe_null)) *to++=1; change_double_for_sort(value,(byte*) to); break; @@ -621,6 +622,8 @@ static void make_sortkey(register SORTPARAM *param, } if (sort_field->reverse) { /* Revers key */ + if (maybe_null) + to[-1]= ~to[-1]; length=sort_field->length; while (length--) { diff --git a/sql/ha_heap.h b/sql/ha_heap.h index fe874dab3f2..c369c7029b4 100644 --- a/sql/ha_heap.h +++ b/sql/ha_heap.h @@ -53,8 +53,9 @@ class ha_heap: public handler uint max_keys() const { return MAX_KEY; } uint max_key_parts() const { return MAX_REF_PARTS; } uint max_key_length() const { return HA_MAX_REC_LENGTH; } - virtual double scan_time() { return (double) (records+deleted) / 20.0+10; } - virtual double read_time(ha_rows rows) { return (double) rows / 20.0+1; } + double scan_time() { return (double) (records+deleted) / 20.0+10; } + double read_time(uint index, uint ranges, ha_rows rows) + { return (double) rows / 20.0+1; } virtual bool fast_key_read() { return 1;} int open(const char *name, int mode, uint test_if_locked); diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 4f955d8f79e..bf4dc7e5066 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -100,7 +100,7 @@ char* innobase_unix_file_flush_method = NULL; /* Below we have boolean-valued start-up parameters, and their default values */ -uint innobase_flush_log_at_trx_commit = 0; +uint innobase_flush_log_at_trx_commit = 1; my_bool innobase_log_archive = FALSE; my_bool innobase_use_native_aio = FALSE; my_bool innobase_fast_shutdown = TRUE; @@ -242,6 +242,10 @@ convert_error_code_to_mysql( return(HA_ERR_CANNOT_ADD_FOREIGN); + } else if (error == (int) DB_CANNOT_DROP_CONSTRAINT) { + + return(HA_WRONG_CREATE_OPTION); + } else if (error == (int) DB_COL_APPEARS_TWICE_IN_INDEX) { return(HA_ERR_CRASHED); @@ -556,12 +560,12 @@ innobase_query_caching_of_table_permitted( #endif if (row_search_check_if_query_cache_permitted(trx, norm_name)) { - printf("Query cache for %s permitted\n", norm_name); + /* printf("Query cache for %s permitted\n", norm_name); */ return((my_bool)TRUE); } - printf("Query cache for %s NOT permitted\n", norm_name); + /* printf("Query cache for %s NOT permitted\n", norm_name); */ return((my_bool)FALSE); } @@ -597,7 +601,7 @@ innobase_invalidate_query_cache( Call this when you have opened a new table handle in HANDLER, before you call index_read_idx() etc. Actually, we can let the cursor stay open even over a transaction commit! Then you should call this before every operation, -fecth next etc. This function inits the necessary things even after a +fetch next etc. This function inits the necessary things even after a transaction commit. */ void @@ -644,6 +648,8 @@ ha_innobase::init_table_handle_for_HANDLER(void) we???? */ prebuilt->read_just_key = FALSE; + + prebuilt->used_in_HANDLER = TRUE; } /************************************************************************* @@ -883,7 +889,7 @@ innobase_flush_logs(void) DBUG_ENTER("innobase_flush_logs"); - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); DBUG_RETURN(result); } @@ -932,7 +938,7 @@ Commits a transaction in an InnoDB database. */ int innobase_commit( /*============*/ - /* out: 0 or error number */ + /* out: 0 */ THD* thd, /* in: MySQL thread handle of the user for whom the transaction should be committed */ void* trx_handle)/* in: InnoDB trx handle or @@ -940,7 +946,6 @@ innobase_commit( that the current SQL statement ended, and we should mark the start of a new statement with a savepoint */ { - int error = 0; trx_t* trx; DBUG_ENTER("innobase_commit"); @@ -967,29 +972,27 @@ innobase_commit( innobase_release_stat_resources(trx); trx_mark_sql_stat_end(trx); -#ifndef DBUG_OFF - if (error) { - DBUG_PRINT("error", ("error: %d", error)); - } -#endif /* Tell InnoDB server that there might be work for utility threads: */ srv_active_wake_master_thread(); - DBUG_RETURN(error); + DBUG_RETURN(0); } /********************************************************************* This is called when MySQL writes the binlog entry for the current transaction. Writes to the InnoDB tablespace info which tells where the MySQL binlog entry for the current transaction ended. Also commits the -transaction inside InnoDB. */ +transaction inside InnoDB but does NOT flush InnoDB log files to disk. +To flush you have to call innobase_flush_log_to_disk. We have separated +flushing to eliminate the bottleneck of LOCK_log in log.cc which disabled +InnoDB's group commit capability. */ int innobase_report_binlog_offset_and_commit( /*=====================================*/ - /* out: 0 or error code */ + /* out: 0 */ THD* thd, /* in: user thread */ void* trx_handle, /* in: InnoDB trx handle */ char* log_file_name, /* in: latest binlog file name */ @@ -1005,7 +1008,39 @@ innobase_report_binlog_offset_and_commit( trx->mysql_log_file_name = log_file_name; trx->mysql_log_offset = (ib_longlong)end_offset; - return(innobase_commit(thd, trx_handle)); + trx->flush_log_later = TRUE; + + innobase_commit(thd, trx_handle); + + trx->flush_log_later = FALSE; + + return(0); +} + +/********************************************************************* +This is called after MySQL has written the binlog entry for the current +transaction. Flushes the InnoDB log files to disk if required. */ + +int +innobase_commit_complete( +/*=====================*/ + /* out: 0 */ + void* trx_handle) /* in: InnoDB trx handle */ +{ + trx_t* trx; + + if (srv_flush_log_at_trx_commit == 0) { + + return(0); + } + + trx = (trx_t*)trx_handle; + + ut_a(trx != NULL); + + trx_commit_complete_for_mysql(trx); + + return(0); } /********************************************************************* @@ -1195,6 +1230,9 @@ ha_innobase::open( last_query_id = (ulong)-1; + active_index = 0; + active_index_before_scan = (uint)-1; /* undefined value */ + if (!(share=get_share(name))) DBUG_RETURN(1); @@ -1938,13 +1976,6 @@ ha_innobase::write_row( build_template(prebuilt, NULL, table, ROW_MYSQL_WHOLE_ROW); } - if (user_thd->lex.sql_command == SQLCOM_INSERT - && user_thd->lex.duplicates == DUP_IGNORE) { - prebuilt->trx->ignore_duplicates_in_insert = TRUE; - } else { - prebuilt->trx->ignore_duplicates_in_insert = FALSE; - } - srv_conc_enter_innodb(prebuilt->trx); error = row_insert_for_mysql((byte*) record, prebuilt); @@ -1985,8 +2016,6 @@ ha_innobase::write_row( } } - prebuilt->trx->ignore_duplicates_in_insert = FALSE; - error = convert_error_code_to_mysql(error, user_thd); /* Tell InnoDB server that there might be work for @@ -2057,7 +2086,8 @@ calc_row_difference( upd_t* uvect, /* in/out: update vector */ mysql_byte* old_row, /* in: old row in MySQL format */ mysql_byte* new_row, /* in: new row in MySQL format */ - struct st_table* table, /* in: table in MySQL data dictionary */ + struct st_table* table, /* in: table in MySQL data + dictionary */ mysql_byte* upd_buff, /* in: buffer to use */ row_prebuilt_t* prebuilt, /* in: InnoDB prebuilt struct */ THD* thd) /* in: user thread */ @@ -2107,8 +2137,10 @@ calc_row_difference( case DATA_VARCHAR: case DATA_BINARY: case DATA_VARMYSQL: - o_ptr = row_mysql_read_var_ref_noninline(&o_len, o_ptr); - n_ptr = row_mysql_read_var_ref_noninline(&n_len, n_ptr); + o_ptr = row_mysql_read_var_ref_noninline(&o_len, + o_ptr); + n_ptr = row_mysql_read_var_ref_noninline(&n_len, + n_ptr); default: ; } @@ -2556,7 +2588,7 @@ ha_innobase::change_active_index( /* MySQL changes the active index for a handle also during some queries, for example SELECT MAX(a), SUM(a) first retrieves the MAX() - and then calculates te sum. Previously we played safe and used + and then calculates the sum. Previously we played safe and used the flag ROW_MYSQL_WHOLE_ROW below, but that caused unnecessary copying. Starting from MySQL-4.1 we use a more efficient flag here. */ @@ -2755,6 +2787,11 @@ ha_innobase::rnd_init( row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt; + /* Store the active index value so that we can restore the original + value after a scan */ + + active_index_before_scan = active_index; + if (prebuilt->clust_index_was_generated) { err = change_active_index(MAX_KEY); } else { @@ -2767,13 +2804,25 @@ ha_innobase::rnd_init( } /********************************************************************* -Ends a table scan ???????????????? */ +Ends a table scan. */ int ha_innobase::rnd_end(void) /*======================*/ /* out: 0 or error number */ { + /* Restore the old active_index back; MySQL may assume that a table + scan does not change active_index. We only restore the value if + MySQL has called rnd_init before: sometimes MySQL seems to call + rnd_end WITHOUT calling rnd_init. */ + + if (active_index_before_scan != (uint)-1) { + + change_active_index(active_index_before_scan); + + active_index_before_scan = (uint)-1; + } + return(index_end()); } @@ -3088,6 +3137,9 @@ ha_innobase::create( trx_search_latch_release_if_reserved(parent_trx); trx = trx_allocate_for_mysql(); + + trx->mysql_thd = thd; + trx->mysql_query_str = &((*thd).query); if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) { trx->check_foreigns = FALSE; @@ -3216,7 +3268,7 @@ ha_innobase::create( the InnoDB data dictionary get out-of-sync if the user runs with innodb_flush_log_at_trx_commit = 0 */ - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); innobase_table = dict_table_get(norm_name, NULL); @@ -3271,6 +3323,9 @@ ha_innobase::delete_table( trx = trx_allocate_for_mysql(); + trx->mysql_thd = current_thd; + trx->mysql_query_str = &((*current_thd).query); + name_len = strlen(name); assert(name_len < 1000); @@ -3288,7 +3343,7 @@ ha_innobase::delete_table( the InnoDB data dictionary get out-of-sync if the user runs with innodb_flush_log_at_trx_commit = 0 */ - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); /* Tell the InnoDB server that there might be work for utility threads: */ @@ -3349,6 +3404,8 @@ innobase_drop_database( my_casedn_str(system_charset_info, namebuf); #endif trx = trx_allocate_for_mysql(); + trx->mysql_thd = current_thd; + trx->mysql_query_str = &((*current_thd).query); error = row_drop_database_for_mysql(namebuf, trx); @@ -3356,7 +3413,7 @@ innobase_drop_database( the InnoDB data dictionary get out-of-sync if the user runs with innodb_flush_log_at_trx_commit = 0 */ - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); /* Tell the InnoDB server that there might be work for utility threads: */ @@ -3408,6 +3465,8 @@ ha_innobase::rename_table( } trx = trx_allocate_for_mysql(); + trx->mysql_thd = current_thd; + trx->mysql_query_str = &((*current_thd).query); name_len1 = strlen(from); name_len2 = strlen(to); @@ -3426,7 +3485,7 @@ ha_innobase::rename_table( the InnoDB data dictionary get out-of-sync if the user runs with innodb_flush_log_at_trx_commit = 0 */ - log_flush_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP); + log_write_up_to(ut_dulint_max, LOG_WAIT_ONE_GROUP, TRUE); /* Tell the InnoDB server that there might be work for utility threads: */ @@ -3541,10 +3600,8 @@ ha_innobase::records_in_range( /************************************************************************* Gives an UPPER BOUND to the number of rows in a table. This is used in -filesort.cc and the upper bound must hold. TODO: Since the number of -rows in a table may change after this function is called, we still may -get a 'Sort aborted' error in filesort.cc of MySQL. The ultimate fix is to -improve the algorithm of filesort.cc. */ +filesort.cc and its better if the upper bound hold. +*/ ha_rows ha_innobase::estimate_number_of_rows(void) @@ -3610,6 +3667,29 @@ ha_innobase::scan_time() return((double) (prebuilt->table->stat_clustered_index_size)); } +/* + Calculate the time it takes to read a set of ranges through and index + This enables us to optimise reads for clustered indexes. +*/ + +double ha_innobase::read_time(uint index, uint ranges, ha_rows rows) +{ + ha_rows total_rows; + double time_for_scan; + if (index != table->primary_key) + return handler::read_time(index, ranges, rows); // Not clustered + if (rows <= 2) + return (double) rows; + /* + Assume that the read is proportional to scan time for all rows + one + seek per range. + */ + time_for_scan= scan_time(); + if ((total_rows= estimate_number_of_rows()) < rows) + return time_for_scan; + return (ranges + (double) rows / (double) total_rows * time_for_scan); +} + /************************************************************************* Returns statistics information of the table to the MySQL interpreter, in various fields of the handle object. */ @@ -3734,6 +3814,23 @@ ha_innobase::info( DBUG_VOID_RETURN; } +/************************************************************************** +Updates index cardinalities of the table, based on 10 random dives into +each index tree. This does NOT calculate exact statistics of the table. */ + +int +ha_innobase::analyze( +/*=================*/ + /* out: returns always 0 (success) */ + THD* thd, /* in: connection thread handle */ + HA_CHECK_OPT* check_opt) /* in: currently ignored */ +{ + /* Simply call ::info() with all the flags */ + info(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE); + + return(0); +} + /*********************************************************************** Tries to check that an InnoDB table is not corrupted. If corruption is noticed, prints to stderr information about it. In case of corruption @@ -3915,7 +4012,7 @@ ha_innobase::extra( break; case HA_EXTRA_RESET_STATE: prebuilt->read_just_key = 0; - break; + break; case HA_EXTRA_NO_KEYREAD: prebuilt->read_just_key = 0; break; @@ -4084,6 +4181,8 @@ ha_innobase::external_lock( trx->mysql_n_tables_locked = 0; + prebuilt->used_in_HANDLER = FALSE; + /* Here we release the search latch and InnoDB thread FIFO ticket if they were reserved. */ diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index be1174added..9ca8475e75e 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -58,7 +58,15 @@ class ha_innobase: public handler ulong start_of_scan; /* this is set to 1 when we are starting a table scan but have not yet fetched any row, else 0 */ - + uint active_index_before_scan; + /* since a table scan in InnoDB is + always done through an index, a table + scan may change active_index; but + MySQL may assume that active_index + after a table scan is the same as + before; we store the value here so + that we can restore the value after + a scan */ uint last_match_mode;/* match mode of the latest search: ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX, or undefined */ @@ -118,6 +126,7 @@ class ha_innobase: public handler void initialize(void); int close(void); double scan_time(); + double read_time(uint index, uint ranges, ha_rows rows); int write_row(byte * buf); int update_row(const byte * old_data, byte * new_data); @@ -143,6 +152,7 @@ class ha_innobase: public handler void position(const byte *record); void info(uint); + int analyze(THD* thd,HA_CHECK_OPT* check_opt); int extra(enum ha_extra_function operation); int reset(void); int external_lock(THD *thd, int lock_type); @@ -189,6 +199,9 @@ extern char *innobase_unix_file_flush_method; /* The following variables have to be my_bool for SHOW VARIABLES to work */ extern my_bool innobase_log_archive, innobase_use_native_aio, innobase_fast_shutdown; +extern "C" { +extern ulong srv_max_buf_pool_modified_pct; +} extern TYPELIB innobase_lock_typelib; @@ -203,6 +216,8 @@ int innobase_report_binlog_offset_and_commit( void* trx_handle, char* log_file_name, my_off_t end_offset); +int innobase_commit_complete( + void* trx_handle); int innobase_rollback(THD *thd, void* trx_handle); int innobase_close_connection(THD *thd); int innobase_drop_database(char *path); diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 213f5baf388..a9c3ddaef60 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -499,7 +499,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) param.thd = thd; param.op_name = (char*) "repair"; param.testflag = ((check_opt->flags & ~(T_EXTEND)) | - T_SILENT | T_FORCE_CREATE | + T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); param.sort_buffer_length= check_opt->sort_buffer_size; start_records=file->state->records; @@ -592,10 +592,24 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) { local_testflag|= T_STATISTICS; param.testflag|= T_STATISTICS; // We get this for free - thd->proc_info="Repair by sorting"; statistics_done=1; - error = mi_repair_by_sort(¶m, file, fixed_name, - param.testflag & T_QUICK); + if (current_thd->variables.myisam_repair_threads>1) + { + char buf[40]; + /* TODO: respect myisam_repair_threads variable */ + my_snprintf(buf, 40, "Repair with %d threads", my_count_bits(key_map)); + thd->proc_info=buf; + error = mi_repair_parallel(¶m, file, fixed_name, + param.testflag & T_QUICK); + thd->proc_info="Repair done"; // to reset proc_info, as + // it was pointing to local buffer + } + else + { + thd->proc_info="Repair by sorting"; + error = mi_repair_by_sort(¶m, file, fixed_name, + param.testflag & T_QUICK); + } } else { diff --git a/sql/handler.cc b/sql/handler.cc index f2b7dbdf531..db1857e938c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -253,6 +253,9 @@ int ha_autocommit_or_rollback(THD *thd, int error) replication. This function also calls the commit of the table handler, because the order of transactions in the log of the table handler must be the same as in the binlog. + NOTE that to eliminate the bottleneck of the group commit, we do not + flush the handler log files here, but only later in a call of + ha_commit_complete(). arguments: thd: the thread handle of the current connection @@ -279,13 +282,38 @@ int ha_report_binlog_offset_and_commit(THD *thd, my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); error=1; } - trans->innodb_active_trans=0; } #endif return error; } /* + Flushes the handler log files (if my.cnf settings do not free us from it) + after we have called ha_report_binlog_offset_and_commit(). To eliminate + the bottleneck from the group commit, this should be called when + LOCK_log has been released in log.cc. + + arguments: + thd: the thread handle of the current connection + return value: always 0 +*/ + +int ha_commit_complete(THD *thd) +{ +#ifdef HAVE_INNOBASE_DB + THD_TRANS *trans; + trans = &thd->transaction.all; + if (trans->innobase_tid) + { + innobase_commit_complete(trans->innobase_tid); + + trans->innodb_active_trans=0; + } +#endif + return 0; +} + +/* This function should be called when MySQL sends rows of a SELECT result set or the EOF mark to the client. It releases a possible adaptive hash index S-latch held by thd in InnoDB and also releases a possible InnoDB query @@ -812,7 +840,8 @@ void handler::print_error(int error, myf errflag) DBUG_VOID_RETURN; } - /* Return key if error because of duplicated keys */ + +/* Return key if error because of duplicated keys */ uint handler::get_dup_key(int error) { @@ -823,6 +852,7 @@ uint handler::get_dup_key(int error) DBUG_RETURN(table->file->errkey); } + int handler::delete_table(const char *name) { int error=0; @@ -849,9 +879,10 @@ int handler::rename_table(const char * from, const char * to) DBUG_RETURN(0); } -/* Tell the handler to turn on or off logging to the handler's - recovery log +/* + Tell the handler to turn on or off logging to the handler's recovery log */ + int ha_recovery_logging(THD *thd, bool on) { int error=0; @@ -906,7 +937,6 @@ bool handler::caching_allowed(THD* thd, char* table_key, int ha_create_table(const char *name, HA_CREATE_INFO *create_info, bool update_create_info) - { int error; TABLE table; diff --git a/sql/handler.h b/sql/handler.h index 8c23a3625e0..97ce295d520 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -235,7 +235,8 @@ public: void change_table_ptr(TABLE *table_arg) { table=table_arg; } virtual double scan_time() { return ulonglong2double(data_file_length) / IO_SIZE + 1; } - virtual double read_time(ha_rows rows) { return rows2double(rows); } + virtual double read_time(uint index, uint ranges, ha_rows rows) + { return rows2double(ranges+rows); } virtual bool fast_key_read() { return 0;} virtual key_map keys_to_use_for_scanning() { return 0; } virtual bool has_transactions(){ return 0;} @@ -389,6 +390,7 @@ void ha_resize_key_cache(void); int ha_start_stmt(THD *thd); int ha_report_binlog_offset_and_commit(THD *thd, char *log_file_name, my_off_t end_offset); +int ha_commit_complete(THD *thd); int ha_release_temporary_latches(THD *thd); int ha_commit_trans(THD *thd, THD_TRANS *trans); int ha_rollback_trans(THD *thd, THD_TRANS *trans); diff --git a/sql/init.cc b/sql/init.cc index 8834fd3a89c..50d504068a0 100644 --- a/sql/init.cc +++ b/sql/init.cc @@ -38,13 +38,11 @@ void unireg_init(ulong options) init_my_atof(); /* use our atof */ #endif my_abort_hook=unireg_abort; /* Abort with close of databases */ - f_fyllchar=' '; /* Input fill char */ VOID(strmov(reg_ext,".frm")); for (i=0 ; i < 6 ; i++) // YYMMDDHHMMSS dayord.pos[i]=i; specialflag=SPECIAL_SAME_DB_NAME; - blob_newline='^'; /* Convert newline in blobs to this */ /* Make a tab of powers of 10 */ for (i=0,nr=1.0; i < array_elements(log_10) ; i++) { /* It's used by filesort... */ diff --git a/sql/item.cc b/sql/item.cc index 053a94cb695..42a949287e5 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -90,28 +90,32 @@ bool Item::check_cols(uint c) return 0; } -void Item::set_name(const char *str,uint length, CHARSET_INFO *cs) + +void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) { if (!length) - name= (char*) str; // Empty string, used by AS - else { - while (length && !my_isgraph(cs,*str)) - { // Fix problem with yacc - length--; - str++; - } - if (length && !my_charset_same(cs, system_charset_info)) - { - String tmp; - tmp.copy(str, length, cs, system_charset_info); - name=sql_strmake(tmp.ptr(),min(tmp.length(),MAX_FIELD_WIDTH)); - } - else - name=sql_strmake(str,min(length,MAX_FIELD_WIDTH)); + /* Empty string, used by AS or internal function like last_insert_id() */ + name= (char*) str; + return; } + while (length && !my_isgraph(cs,*str)) + { // Fix problem with yacc + length--; + str++; + } + if (!my_charset_same(cs, system_charset_info)) + { + uint32 res_length; + name= sql_strmake_with_convert(str, length, cs, + MAX_ALIAS_NAME, system_charset_info, + &res_length); + } + else + name=sql_strmake(str, min(length,MAX_ALIAS_NAME)); } + /* This function is only called when comparing items in the WHERE clause */ @@ -1048,6 +1052,7 @@ inline uint char_val(char X) X-'a'+10); } + Item_varbinary::Item_varbinary(const char *str, uint str_length) { name=(char*) str-2; // Lex makes this start with 0x @@ -1447,7 +1452,7 @@ bool Item_insert_value::fix_fields(THD *thd, struct st_table_list *table_list, I Field *field=field_arg->field; /* charset doesn't matter here, it's to avoid sigsegv only */ set_field(new Field_null(0,0,Field::NONE,field->field_name,field->table, - default_charset_info)); + &my_charset_bin)); } return 0; } diff --git a/sql/item.h b/sql/item.h index 470937f8ee7..2d285bbe434 100644 --- a/sql/item.h +++ b/sql/item.h @@ -644,6 +644,7 @@ public: #include "item_row.h" #include "item_cmpfunc.h" #include "item_strfunc.h" +#include "item_geofunc.h" #include "item_timefunc.h" #include "item_uniq.h" #include "item_subselect.h" diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index e2885c8764a..299014689f0 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -90,7 +90,7 @@ static bool convert_constant_item(Field *field, Item **item) bool Item_bool_func2::set_cmp_charset(CHARSET_INFO *cs1, enum coercion co1, CHARSET_INFO *cs2, enum coercion co2) { - if((cs1 == &my_charset_bin) || (cs2 == &my_charset_bin)) + if ((cs1 == &my_charset_bin) || (cs2 == &my_charset_bin)) { cmp_charset= &my_charset_bin; return 0; @@ -114,32 +114,104 @@ bool Item_bool_func2::set_cmp_charset(CHARSET_INFO *cs1, enum coercion co1, { if (co1 == COER_COERCIBLE) { - CHARSET_INFO *c= get_charset_by_csname(cs1->csname,MY_CS_PRIMARY,MYF(0)); - if (c) + CHARSET_INFO *c; + if ((c= get_charset_by_csname(cs1->csname, MY_CS_PRIMARY, MYF(0)))) { cmp_charset= c; return 0; } - else - return 1; } - else - return 1; + return 1; + } + } + return 0; +} + + +bool Item_bool_func2::fix_fields(THD *thd, struct st_table_list *tables, + Item ** ref) +{ + if (Item_int_func::fix_fields(thd, tables, ref)) + return 1; + + /* + We allow to convert to Unicode character sets in some cases. + The conditions when conversion is possible are: + - arguments A and B have different charsets + - A wins according to coercibility rules + - character set of A is superset for character set of B + + If all of the above is true, then it's possible to convert + B into the character set of A, and then compare according + to the collation of A. + */ + + if (args[0] && args[1]) + { + uint strong= 0; + uint weak= 0; + + if ((args[0]->coercibility < args[1]->coercibility) && + !my_charset_same(args[0]->charset(), args[1]->charset()) && + (args[0]->charset()->state & MY_CS_UNICODE)) + { + weak= 1; + } + else if ((args[1]->coercibility < args[0]->coercibility) && + !my_charset_same(args[0]->charset(), args[1]->charset()) && + (args[1]->charset()->state & MY_CS_UNICODE)) + { + strong= 1; + } + + if (strong || weak) + { + Item* conv= 0; + if (args[weak]->type() == STRING_ITEM) + { + String tmp, cstr; + String *ostr= args[weak]->val_str(&tmp); + cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), + args[strong]->charset()); + conv= new Item_string(cstr.ptr(),cstr.length(),cstr.charset(), + args[weak]->coercibility); + ((Item_string*)conv)->str_value.copy(); + } + else + { + conv= new Item_func_conv_charset(args[weak],args[strong]->charset()); + conv->coercibility= args[weak]->coercibility; + } + args[weak]= conv ? conv : args[weak]; + set_cmp_charset(args[0]->charset(), args[0]->coercibility, + args[1]->charset(), args[1]->coercibility); } } + if (!cmp_charset) + { + /* set_cmp_charset() failed */ + my_error(ER_CANT_AGGREGATE_COLLATIONS,MYF(0), + args[0]->charset()->name,coercion_name(args[0]->coercibility), + args[1]->charset()->name,coercion_name(args[1]->coercibility), + func_name()); + return 1; + } return 0; } + void Item_bool_func2::fix_length_and_dec() { max_length= 1; // Function returns 0 or 1 /* As some compare functions are generated after sql_yacc, - we have to check for out of memory conditons here + we have to check for out of memory conditions here */ if (!args[0] || !args[1]) return; + + // Make a special case of compare with fields to get nicer DATE comparisons if (args[0]->type() == FIELD_ITEM) { @@ -149,7 +221,8 @@ void Item_bool_func2::fix_length_and_dec() if (convert_constant_item(field,&args[1])) { cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, - INT_RESULT); // Works for all types. + INT_RESULT); // Works for all types. + cmp_charset= &my_charset_bin; // For test in fix_fields return; } } @@ -163,20 +236,19 @@ void Item_bool_func2::fix_length_and_dec() { cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, INT_RESULT); // Works for all types. + cmp_charset= &my_charset_bin; // For test in fix_fields return; } } } - if (set_cmp_charset(args[0]->charset(), args[0]->coercibility, - args[1]->charset(), args[1]->coercibility)) - { - my_error(ER_CANT_AGGREGATE_COLLATIONS,MYF(0), - args[0]->charset()->name,coercion_name(args[0]->coercibility), - args[1]->charset()->name,coercion_name(args[1]->coercibility), - func_name()); - return; - } set_cmp_func(); + /* + We must set cmp_charset here as we may be called from for an automatic + generated item, like in natural join + */ +end: + set_cmp_charset(args[0]->charset(), args[0]->coercibility, + args[1]->charset(), args[1]->coercibility); } @@ -194,22 +266,22 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) comparators= 0; return 1; } - if ((comparators= (Arg_comparator *) sql_alloc(sizeof(Arg_comparator)*n))) - for (uint i=0; i < n; i++) + if (!(comparators= (Arg_comparator *) sql_alloc(sizeof(Arg_comparator)*n))) + return 1; + for (uint i=0; i < n; i++) + { + if ((*a)->el(i)->cols() != (*b)->el(i)->cols()) { - if ((*a)->el(i)->cols() != (*b)->el(i)->cols()) - { - my_error(ER_CARDINALITY_COL, MYF(0), (*a)->el(i)->cols()); - return 1; - } - comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i)); + my_error(ER_CARDINALITY_COL, MYF(0), (*a)->el(i)->cols()); + return 1; } - else - return 1; + comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i)); + } } return 0; } + int Arg_comparator::compare_string() { String *res1,*res2; @@ -1419,7 +1491,7 @@ bool Item_func_in::nulls_in_row() static int srtcmp_in(const String *x,const String *y) { CHARSET_INFO *cs= x->charset(); - return cs->strnncollsp(cs, + return cs->coll->strnncollsp(cs, (unsigned char *) x->ptr(),x->length(), (unsigned char *) y->ptr(),y->length()); } @@ -1427,7 +1499,7 @@ static int srtcmp_in(const String *x,const String *y) static int bincmp_in(const String *x,const String *y) { CHARSET_INFO *cs= &my_charset_bin; - return cs->strnncollsp(cs, + return cs->coll->strnncollsp(cs, (unsigned char *) x->ptr(),x->length(), (unsigned char *) y->ptr(),y->length()); } @@ -1884,16 +1956,6 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref) if (Item_bool_func2::fix_fields(thd, tlist, ref)) return 1; - if (set_cmp_charset(args[0]->charset(), args[0]->coercibility, - args[1]->charset(), args[1]->coercibility)) - { - my_error(ER_CANT_AGGREGATE_COLLATIONS,MYF(0), - args[0]->charset()->name,coercion_name(args[0]->coercibility), - args[1]->charset()->name,coercion_name(args[1]->coercibility), - func_name()); - return 1; - } - /* We could also do boyer-more for non-const items, but as we would have to recompute the tables for each row it's not worth it. @@ -2301,85 +2363,3 @@ longlong Item_cond_xor::val_int() } return (longlong) result; } - -/**************************************************************** - Classes and functions for spatial relations -*****************************************************************/ - -longlong Item_func_spatial_rel::val_int() -{ - String *res1= args[0]->val_str(&tmp_value1); - String *res2= args[1]->val_str(&tmp_value2); - Geometry g1, g2; - MBR mbr1, mbr2; - - if ((null_value= (args[0]->null_value || - args[1]->null_value || - g1.create_from_wkb(res1->ptr() + SRID_SIZE, - res1->length() - SRID_SIZE) || - g2.create_from_wkb(res2->ptr() + SRID_SIZE, - res2->length() - SRID_SIZE) || - g1.get_mbr(&mbr1) || - g2.get_mbr(&mbr2)))) - return 0; - - switch (spatial_rel) - { - case SP_CONTAINS_FUNC: - return mbr1.contains(&mbr2); - case SP_WITHIN_FUNC: - return mbr1.within(&mbr2); - case SP_EQUALS_FUNC: - return mbr1.equals(&mbr2); - case SP_DISJOINT_FUNC: - return mbr1.disjoint(&mbr2); - case SP_INTERSECTS_FUNC: - return mbr1.intersects(&mbr2); - case SP_TOUCHES_FUNC: - return mbr1.touches(&mbr2); - case SP_OVERLAPS_FUNC: - return mbr1.overlaps(&mbr2); - case SP_CROSSES_FUNC: - return 0; - default: - break; - } - - null_value=1; - return 0; -} - -longlong Item_func_isempty::val_int() -{ - String tmp; - null_value=0; - return args[0]->null_value ? 1 : 0; -} - -longlong Item_func_issimple::val_int() -{ - String tmp; - String *wkb=args[0]->val_str(&tmp); - - if ((null_value= (!wkb || args[0]->null_value ))) - return 0; - /* TODO: Ramil or Holyfoot, add real IsSimple calculation */ - return 0; -} - -longlong Item_func_isclosed::val_int() -{ - String tmp; - String *swkb= args[0]->val_str(&tmp); - Geometry geom; - int isclosed; - - null_value= (!swkb || - args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom,is_closed) || - geom.is_closed(&isclosed)); - - return (longlong) isclosed; -} diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 5e246e3e285..4438b902011 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -116,7 +116,8 @@ protected: public: Item_bool_func2(Item *a,Item *b): - Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1) {} + Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1), cmp_charset(0) {} + bool fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref); void fix_length_and_dec(); void set_cmp_func() { @@ -849,79 +850,3 @@ inline Item *and_conds(Item *a,Item *b) } Item *and_expressions(Item *a, Item *b, Item **org_item); - -/************************************************************** - Spatial relations -***************************************************************/ - -class Item_func_spatial_rel :public Item_bool_func2 -{ - enum Functype spatial_rel; -public: - Item_func_spatial_rel(Item *a,Item *b, enum Functype sp_rel) : - Item_bool_func2(a,b) { spatial_rel = sp_rel; } - longlong val_int(); - enum Functype functype() const - { - switch (spatial_rel) { - case SP_CONTAINS_FUNC: - return SP_WITHIN_FUNC; - case SP_WITHIN_FUNC: - return SP_CONTAINS_FUNC; - default: - return spatial_rel; - } - } - enum Functype rev_functype() const { return spatial_rel; } - const char *func_name() const - { - switch (spatial_rel) { - case SP_CONTAINS_FUNC: - return "contains"; - case SP_WITHIN_FUNC: - return "within"; - case SP_EQUALS_FUNC: - return "equals"; - case SP_DISJOINT_FUNC: - return "disjoint"; - case SP_INTERSECTS_FUNC: - return "intersects"; - case SP_TOUCHES_FUNC: - return "touches"; - case SP_CROSSES_FUNC: - return "crosses"; - case SP_OVERLAPS_FUNC: - return "overlaps"; - default: - return "sp_unknown"; - } - } -}; - - -class Item_func_isempty :public Item_bool_func -{ -public: - Item_func_isempty(Item *a) :Item_bool_func(a) {} - longlong val_int(); - optimize_type select_optimize() const { return OPTIMIZE_NONE; } - const char *func_name() const { return "isempty"; } -}; - -class Item_func_issimple :public Item_bool_func -{ -public: - Item_func_issimple(Item *a) :Item_bool_func(a) {} - longlong val_int(); - optimize_type select_optimize() const { return OPTIMIZE_NONE; } - const char *func_name() const { return "issimple"; } -}; - -class Item_func_isclosed :public Item_bool_func -{ -public: - Item_func_isclosed(Item *a) :Item_bool_func(a) {} - longlong val_int(); - optimize_type select_optimize() const { return OPTIMIZE_NONE; } - const char *func_name() const { return "isclosed"; } -}; diff --git a/sql/item_create.cc b/sql/item_create.cc index 1e547a9c76e..00c98937659 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -321,10 +321,10 @@ Item *create_func_current_user() char buff[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; uint length; - length= (uint) (strxmov(buff, thd->priv_user, "@", thd->host_or_ip, NullS) - + length= (uint) (strxmov(buff, thd->priv_user, "@", thd->priv_host, NullS) - buff); return new Item_string(NullS, thd->memdup(buff, length), length, - default_charset_info); + system_charset_info); } Item *create_func_quarter(Item* a) @@ -437,7 +437,7 @@ Item *create_func_version(void) { return new Item_string(NullS,server_version, (uint) strlen(server_version), - system_charset_info); + system_charset_info, Item::COER_IMPLICIT); } Item *create_func_weekday(Item* a) @@ -457,13 +457,16 @@ Item *create_load_file(Item* a) } -Item *create_func_cast(Item *a, Item_cast cast_type) +Item *create_func_cast(Item *a, Item_cast cast_type, CHARSET_INFO *cs) { Item *res; LINT_INIT(res); switch (cast_type) { case ITEM_CAST_BINARY: res= new Item_func_binary(a); break; - case ITEM_CAST_CHAR: res= new Item_char_typecast(a); break; + case ITEM_CAST_CHAR: + res= (cs == NULL) ? (Item*) new Item_char_typecast(a) : + (Item*) new Item_func_conv_charset(a,cs); + break; case ITEM_CAST_SIGNED_INT: res= new Item_func_signed(a); break; case ITEM_CAST_UNSIGNED_INT: res= new Item_func_unsigned(a); break; case ITEM_CAST_DATE: res= new Item_date_typecast(a); break; diff --git a/sql/item_create.h b/sql/item_create.h index c79fe07b8d4..b679c639244 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -28,7 +28,7 @@ Item *create_func_bit_length(Item* a); Item *create_func_coercibility(Item* a); Item *create_func_ceiling(Item* a); Item *create_func_char_length(Item* a); -Item *create_func_cast(Item *a, Item_cast cast_type); +Item *create_func_cast(Item *a, Item_cast cast_type, CHARSET_INFO *cs); Item *create_func_connection_id(void); Item *create_func_conv(Item* a, Item *b, Item *c); Item *create_func_cos(Item* a); diff --git a/sql/item_func.cc b/sql/item_func.cc index 6af65ece692..6482d81f484 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -40,8 +40,8 @@ eval_const_cond(COND *cond) } -Item_func::Item_func(List<Item> &list): - allowed_arg_cols(1) +Item_func::Item_func(List<Item> &list) + :allowed_arg_cols(1) { arg_count=list.elements; if ((args=(Item**) sql_alloc(sizeof(Item*)*arg_count))) @@ -109,15 +109,18 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { // Print purify happy for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) { + Item *item; + /* We can't yet set item to *arg as fix_fields may change *arg */ if ((*arg)->fix_fields(thd, tables, arg) || (*arg)->check_cols(allowed_arg_cols)) return 1; /* purecov: inspected */ - if ((*arg)->maybe_null) + item= *arg; + if (item->maybe_null) maybe_null=1; - with_sum_func= with_sum_func || (*arg)->with_sum_func; - used_tables_cache|=(*arg)->used_tables(); - const_item_cache&= (*arg)->const_item(); + with_sum_func= with_sum_func || item->with_sum_func; + used_tables_cache|=item->used_tables(); + const_item_cache&= item->const_item(); } } fix_length_and_dec(); @@ -140,14 +143,15 @@ void Item_func::split_sum_func(Item **ref_pointer_array, List<Item> &fields) Item **arg, **arg_end; for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++) { - if ((*arg)->with_sum_func && (*arg)->type() != SUM_FUNC_ITEM) - (*arg)->split_sum_func(ref_pointer_array, fields); - else if ((*arg)->used_tables() || (*arg)->type() == SUM_FUNC_ITEM) + Item *item=* arg; + if (item->with_sum_func && item->type() != SUM_FUNC_ITEM) + item->split_sum_func(ref_pointer_array, fields); + else if (item->used_tables() || item->type() == SUM_FUNC_ITEM) { uint el= fields.elements; - fields.push_front(*arg); - ref_pointer_array[el]= *arg; - *arg= new Item_ref(ref_pointer_array + el, 0, (*arg)->name); + fields.push_front(item); + ref_pointer_array[el]= item; + *arg= new Item_ref(ref_pointer_array + el, 0, item->name); } } } @@ -1250,47 +1254,6 @@ longlong Item_func_find_in_set::val_int() return 0; } -static char nbits[256] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, -}; - -uint count_bits(ulonglong v) -{ -#if SIZEOF_LONG_LONG > 4 - /* The following code is a bit faster on 16 bit machines than if we would - only shift v */ - ulong v2=(ulong) (v >> 32); - return (uint) (uchar) (nbits[(uchar) v] + - nbits[(uchar) (v >> 8)] + - nbits[(uchar) (v >> 16)] + - nbits[(uchar) (v >> 24)] + - nbits[(uchar) (v2)] + - nbits[(uchar) (v2 >> 8)] + - nbits[(uchar) (v2 >> 16)] + - nbits[(uchar) (v2 >> 24)]); -#else - return (uint) (uchar) (nbits[(uchar) v] + - nbits[(uchar) (v >> 8)] + - nbits[(uchar) (v >> 16)] + - nbits[(uchar) (v >> 24)]); -#endif -} - longlong Item_func_bit_count::val_int() { ulonglong value= (ulonglong) args[0]->val_int(); @@ -1299,7 +1262,7 @@ longlong Item_func_bit_count::val_int() null_value=1; /* purecov: inspected */ return 0; /* purecov: inspected */ } - return (longlong) count_bits(value); + return (longlong) my_count_bits(value); } @@ -1373,16 +1336,17 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, arg != arg_end ; arg++,i++) { - if ((*arg)->fix_fields(thd, tables, arg) || (*arg)->check_cols(1)) + Item *item= *arg; + if (item->fix_fields(thd, tables, arg) || item->check_cols(1)) return 1; - if ((*arg)->binary()) + if (item->binary()) func->set_charset(&my_charset_bin); - if ((*arg)->maybe_null) + if (item->maybe_null) func->maybe_null=1; - func->with_sum_func= func->with_sum_func || (*arg)->with_sum_func; - used_tables_cache|=(*arg)->used_tables(); - const_item_cache&=(*arg)->const_item(); - f_args.arg_type[i]=(*arg)->result_type(); + func->with_sum_func= func->with_sum_func || item->with_sum_func; + used_tables_cache|=item->used_tables(); + const_item_cache&=item->const_item(); + f_args.arg_type[i]=item->result_type(); } if (!(buffers=new String[arg_count]) || !(f_args.args= (char**) sql_alloc(arg_count * sizeof(char *))) || @@ -2452,7 +2416,7 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref) used_tables_cache|=item->used_tables(); } /* check that all columns come from the same table */ - if (count_bits(used_tables_cache) != 1) + if (my_count_bits(used_tables_cache) != 1) key=NO_SUCH_KEY; const_item_cache=0; table=((Item_field *)fields.head())->field->table; @@ -2626,10 +2590,7 @@ Item *get_system_var(enum_var_type var_type, LEX_STRING name) char buff[MAX_SYS_VAR_LENGTH+3+8], *pos; if (!(var= find_sys_var(name.str, name.length))) - { - net_printf(thd, ER_UNKNOWN_SYSTEM_VARIABLE, name.str); return 0; - } if (!(item=var->item(thd, var_type))) return 0; // Impossible thd->lex.uncacheable(); @@ -2719,139 +2680,3 @@ longlong Item_func_is_used_lock::val_int() null_value=0; return ull->thread_id; } - - - -/************************************************************************** - Spatial functions -***************************************************************************/ - -longlong Item_func_dimension::val_int() -{ - uint32 dim; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - geom.dimension(&dim)); - return (longlong) dim; -} - -longlong Item_func_numinteriorring::val_int() -{ - uint32 num; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, num_interior_ring) || - geom.num_interior_ring(&num)); - return (longlong) num; -} - -longlong Item_func_numgeometries::val_int() -{ - uint32 num= 0; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, num_geometries) || - geom.num_geometries(&num)); - return (longlong) num; -} - -longlong Item_func_numpoints::val_int() -{ - uint32 num; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, num_points) || - geom.num_points(&num)); - return (longlong) num; -} - - -double Item_func_x::val() -{ - double res; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, get_x) || - geom.get_x(&res)); - return res; -} - - -double Item_func_y::val() -{ - double res; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, get_y) || - geom.get_y(&res)); - return res; -} - - -double Item_func_area::val() -{ - double res; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, area) || - geom.area(&res)); - return res; -} - - -double Item_func_glength::val() -{ - double res; - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, length) || - geom.length(&res)); - return res; -} - - -longlong Item_func_srid::val_int() -{ - String *swkb= args[0]->val_str(&value); - Geometry geom; - - null_value= (!swkb || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE)); - uint32 res= uint4korr(swkb->ptr()); - return (longlong) res; -} diff --git a/sql/item_func.h b/sql/item_func.h index e1d6156c12c..8ef2b85de52 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1037,101 +1037,6 @@ public: }; -class Item_func_dimension :public Item_int_func -{ - String value; -public: - Item_func_dimension(Item *a) :Item_int_func(a) {} - longlong val_int(); - const char *func_name() const { return "dimension"; } - void fix_length_and_dec() { max_length=10; } -}; - - -class Item_func_x :public Item_real_func -{ - String value; -public: - Item_func_x(Item *a) :Item_real_func(a) {} - double val(); - const char *func_name() const { return "x"; } -}; - - -class Item_func_y :public Item_real_func -{ - String value; -public: - Item_func_y(Item *a) :Item_real_func(a) {} - double val(); - const char *func_name() const { return "y"; } -}; - - -class Item_func_numgeometries :public Item_int_func -{ - String value; -public: - Item_func_numgeometries(Item *a) :Item_int_func(a) {} - longlong val_int(); - const char *func_name() const { return "numgeometries"; } - void fix_length_and_dec() { max_length=10; } -}; - - -class Item_func_numinteriorring :public Item_int_func -{ - String value; -public: - Item_func_numinteriorring(Item *a) :Item_int_func(a) {} - longlong val_int(); - const char *func_name() const { return "numinteriorring"; } - void fix_length_and_dec() { max_length=10; } -}; - - -class Item_func_numpoints :public Item_int_func -{ - String value; -public: - Item_func_numpoints(Item *a) :Item_int_func(a) {} - longlong val_int(); - const char *func_name() const { return "numpoints"; } - void fix_length_and_dec() { max_length=10; } -}; - - -class Item_func_area :public Item_real_func -{ - String value; -public: - Item_func_area(Item *a) :Item_real_func(a) {} - double val(); - const char *func_name() const { return "area"; } -}; - - -class Item_func_glength :public Item_real_func -{ - String value; -public: - Item_func_glength(Item *a) :Item_real_func(a) {} - double val(); - const char *func_name() const { return "glength"; } -}; - - -class Item_func_srid: public Item_int_func -{ - String value; -public: - Item_func_srid(Item *a): Item_int_func(a) {} - longlong val_int(); - const char *func_name() const { return "srid"; } - void fix_length_and_dec() { max_length= 10; } -}; - - class Item_func_match_nl :public Item_func_match { public: diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc new file mode 100644 index 00000000000..fa858922c1b --- /dev/null +++ b/sql/item_geofunc.cc @@ -0,0 +1,653 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +/* This file defines all spatial functions */ + +#ifdef __GNUC__ +#pragma implementation // gcc: Class implementation +#endif + +#include "mysql_priv.h" +#include "sql_acl.h" +#include <m_ctype.h> + +String *Item_func_geometry_from_text::val_str(String *str) +{ + Geometry geom; + String arg_val; + String *wkt= args[0]->val_str(&arg_val); + GTextReadStream trs(wkt->ptr(), wkt->length()); + uint32 srid; + + if ((arg_count == 2) && !args[1]->null_value) + srid= args[1]->val_int(); + else + srid= 0; + + if (str->reserve(SRID_SIZE, 512)) + return 0; + str->length(0); + str->q_append(srid); + if ((null_value=(args[0]->null_value || geom.create_from_wkt(&trs, str, 0)))) + return 0; + return str; +} + + +void Item_func_geometry_from_text::fix_length_and_dec() +{ + max_length=MAX_BLOB_WIDTH; +} + + +String *Item_func_geometry_from_wkb::val_str(String *str) +{ + String arg_val; + String *wkb= args[0]->val_str(&arg_val); + Geometry geom; + uint32 srid; + + if ((arg_count == 2) && !args[1]->null_value) + srid= args[1]->val_int(); + else + srid= 0; + + if (str->reserve(SRID_SIZE, 512)) + return 0; + str->length(0); + str->q_append(srid); + if ((null_value= (args[0]->null_value || + geom.create_from_wkb(wkb->ptr(), wkb->length())))) + return 0; + + str->append(*wkb); + return str; +} + + +void Item_func_geometry_from_wkb::fix_length_and_dec() +{ + max_length=MAX_BLOB_WIDTH; +} + + +String *Item_func_as_text::val_str(String *str) +{ + String arg_val; + String *swkb= args[0]->val_str(&arg_val); + Geometry geom; + + if ((null_value= (args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE)))) + return 0; + + str->length(0); + + if ((null_value= geom.as_wkt(str))) + return 0; + + return str; +} + +void Item_func_as_text::fix_length_and_dec() +{ + max_length=MAX_BLOB_WIDTH; +} + +String *Item_func_as_wkb::val_str(String *str) +{ + String arg_val; + String *swkb= args[0]->val_str(&arg_val); + Geometry geom; + + if ((null_value= (args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE)))) + return 0; + + str->copy(swkb->ptr() + SRID_SIZE, swkb->length() - SRID_SIZE, + &my_charset_bin); + return str; +} + +void Item_func_as_wkb::fix_length_and_dec() +{ + max_length= MAX_BLOB_WIDTH; +} + +String *Item_func_geometry_type::val_str(String *str) +{ + String *swkb= args[0]->val_str(str); + Geometry geom; + + if ((null_value= (args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE)))) + return 0; + str->copy(geom.get_class_info()->m_name, + strlen(geom.get_class_info()->m_name), + default_charset()); + return str; +} + + +String *Item_func_envelope::val_str(String *str) +{ + String arg_val; + String *swkb= args[0]->val_str(&arg_val); + Geometry geom; + + if ((null_value= args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE))) + return 0; + + uint32 srid= uint4korr(swkb->ptr()); + str->length(0); + if (str->reserve(SRID_SIZE, 512)) + return 0; + str->q_append(srid); + return (null_value= geom.envelope(str)) ? 0 : str; +} + + +String *Item_func_centroid::val_str(String *str) +{ + String arg_val; + String *swkb= args[0]->val_str(&arg_val); + Geometry geom; + + if ((null_value= args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, centroid))) + return 0; + + if (str->reserve(SRID_SIZE, 512)) + return 0; + str->length(0); + uint32 srid= uint4korr(swkb->ptr()); + str->q_append(srid); + + return (null_value= geom.centroid(str)) ? 0 : str; +} + + +/* + Spatial decomposition functions +*/ + +String *Item_func_spatial_decomp::val_str(String *str) +{ + String arg_val; + String *swkb= args[0]->val_str(&arg_val); + Geometry geom; + + if ((null_value= (args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE)))) + return 0; + + null_value= 1; + if (str->reserve(SRID_SIZE, 512)) + return 0; + str->length(0); + uint32 srid= uint4korr(swkb->ptr()); + str->q_append(srid); + switch(decomp_func) + { + case SP_STARTPOINT: + if (!GEOM_METHOD_PRESENT(geom,start_point) || geom.start_point(str)) + goto ret; + break; + + case SP_ENDPOINT: + if (!GEOM_METHOD_PRESENT(geom,end_point) || geom.end_point(str)) + goto ret; + break; + + case SP_EXTERIORRING: + if (!GEOM_METHOD_PRESENT(geom,exterior_ring) || geom.exterior_ring(str)) + goto ret; + break; + + default: + goto ret; + } + null_value= 0; + +ret: + return null_value ? 0 : str; +} + + +String *Item_func_spatial_decomp_n::val_str(String *str) +{ + String arg_val; + String *swkb= args[0]->val_str(&arg_val); + long n= (long) args[1]->val_int(); + Geometry geom; + + if ((null_value= (args[0]->null_value || args[1]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE)))) + return 0; + + null_value= 1; + if (str->reserve(SRID_SIZE, 512)) + return 0; + str->length(0); + uint32 srid= uint4korr(swkb->ptr()); + str->q_append(srid); + switch(decomp_func_n) + { + case SP_POINTN: + if (!GEOM_METHOD_PRESENT(geom,point_n) || geom.point_n(n,str)) + goto ret; + break; + + case SP_GEOMETRYN: + if (!GEOM_METHOD_PRESENT(geom,geometry_n) || geom.geometry_n(n,str)) + goto ret; + break; + + case SP_INTERIORRINGN: + if (!GEOM_METHOD_PRESENT(geom,interior_ring_n) || + geom.interior_ring_n(n,str)) + goto ret; + break; + + default: + goto ret; + } + null_value= 0; + +ret: + return null_value ? 0 : str; +} + + +/* + Functions to concatinate various spatial objects +*/ + + +/* +* Concatinate doubles into Point +*/ + + +String *Item_func_point::val_str(String *str) +{ + double x= args[0]->val(); + double y= args[1]->val(); + + if ( (null_value= (args[0]->null_value || + args[1]->null_value || + str->realloc(1 + 4 + 8 + 8)))) + return 0; + + str->length(0); + str->q_append((char)Geometry::wkbNDR); + str->q_append((uint32)Geometry::wkbPoint); + str->q_append(x); + str->q_append(y); + return str; +} + + +/* + Concatinates various items into various collections + with checkings for valid wkb type of items. + For example, MultiPoint can be a collection of Points only. + coll_type contains wkb type of target collection. + item_type contains a valid wkb type of items. + In the case when coll_type is wkbGeometryCollection, + we do not check wkb type of items, any is valid. +*/ + +String *Item_func_spatial_collection::val_str(String *str) +{ + String arg_value; + uint i; + + null_value= 1; + + str->length(0); + if (str->reserve(1 + 4 + 4, 512)) + return 0; + + str->q_append((char) Geometry::wkbNDR); + str->q_append((uint32) coll_type); + str->q_append((uint32) arg_count); + + for (i= 0; i < arg_count; ++i) + { + String *res= args[i]->val_str(&arg_value); + if (args[i]->null_value) + goto ret; + + if ( coll_type == Geometry::wkbGeometryCollection ) + { + /* + In the case of GeometryCollection we don't need + any checkings for item types, so just copy them + into target collection + */ + if ((null_value= str->reserve(res->length(), 512))) + goto ret; + + str->q_append(res->ptr(), res->length()); + } + else + { + enum Geometry::wkbType wkb_type; + uint32 len=res->length(); + const char *data= res->ptr() + 1; + + /* + In the case of named collection we must to + check that items are of specific type, let's + do this checking now + */ + + if (len < 5) + goto ret; + wkb_type= (Geometry::wkbType) uint4korr(data); + data+= 4; + len-= 5; + if (wkb_type != item_type) + goto ret; + + switch (coll_type) { + case Geometry::wkbMultiPoint: + case Geometry::wkbMultiLineString: + case Geometry::wkbMultiPolygon: + if (len < WKB_HEADER_SIZE) + goto ret; + + data-= WKB_HEADER_SIZE; + len+= WKB_HEADER_SIZE; + if (str->reserve(len, 512)) + goto ret; + str->q_append(data, len); + break; + + case Geometry::wkbLineString: + if (str->reserve(POINT_DATA_SIZE, 512)) + goto ret; + str->q_append(data, POINT_DATA_SIZE); + break; + + case Geometry::wkbPolygon: + { + uint32 n_points; + double x1, y1, x2, y2; + + if (len < 4 + 2 * POINT_DATA_SIZE) + goto ret; + + uint32 llen= len; + const char *ldata= data; + + n_points= uint4korr(data); + data+= 4; + float8get(x1, data); + data+= 8; + float8get(y1, data); + data+= 8; + + data+= (n_points - 2) * POINT_DATA_SIZE; + + float8get(x2, data); + float8get(y2, data + 8); + + if ((x1 != x2) || (y1 != y2)) + goto ret; + + if (str->reserve(llen, 512)) + goto ret; + str->q_append(ldata, llen); + } + break; + + default: + goto ret; + } + } + } + + if (str->length() > current_thd->variables.max_allowed_packet) + goto ret; + + null_value = 0; + +ret: + return null_value ? 0 : str; +} + +/* + Functions for spatial relations +*/ + +longlong Item_func_spatial_rel::val_int() +{ + String *res1= args[0]->val_str(&tmp_value1); + String *res2= args[1]->val_str(&tmp_value2); + Geometry g1, g2; + MBR mbr1, mbr2; + + if ((null_value= (args[0]->null_value || + args[1]->null_value || + g1.create_from_wkb(res1->ptr() + SRID_SIZE, + res1->length() - SRID_SIZE) || + g2.create_from_wkb(res2->ptr() + SRID_SIZE, + res2->length() - SRID_SIZE) || + g1.get_mbr(&mbr1) || + g2.get_mbr(&mbr2)))) + return 0; + + switch (spatial_rel) + { + case SP_CONTAINS_FUNC: + return mbr1.contains(&mbr2); + case SP_WITHIN_FUNC: + return mbr1.within(&mbr2); + case SP_EQUALS_FUNC: + return mbr1.equals(&mbr2); + case SP_DISJOINT_FUNC: + return mbr1.disjoint(&mbr2); + case SP_INTERSECTS_FUNC: + return mbr1.intersects(&mbr2); + case SP_TOUCHES_FUNC: + return mbr1.touches(&mbr2); + case SP_OVERLAPS_FUNC: + return mbr1.overlaps(&mbr2); + case SP_CROSSES_FUNC: + return 0; + default: + break; + } + + null_value=1; + return 0; +} + +longlong Item_func_isempty::val_int() +{ + String tmp; + null_value=0; + return args[0]->null_value ? 1 : 0; +} + +longlong Item_func_issimple::val_int() +{ + String tmp; + String *wkb=args[0]->val_str(&tmp); + + if ((null_value= (!wkb || args[0]->null_value ))) + return 0; + /* TODO: Ramil or Holyfoot, add real IsSimple calculation */ + return 0; +} + +longlong Item_func_isclosed::val_int() +{ + String tmp; + String *swkb= args[0]->val_str(&tmp); + Geometry geom; + int isclosed; + + null_value= (!swkb || + args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom,is_closed) || + geom.is_closed(&isclosed)); + + return (longlong) isclosed; +} + +/* + Numerical functions +*/ + +longlong Item_func_dimension::val_int() +{ + uint32 dim; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + geom.dimension(&dim)); + return (longlong) dim; +} + +longlong Item_func_numinteriorring::val_int() +{ + uint32 num; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, num_interior_ring) || + geom.num_interior_ring(&num)); + return (longlong) num; +} + +longlong Item_func_numgeometries::val_int() +{ + uint32 num= 0; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, num_geometries) || + geom.num_geometries(&num)); + return (longlong) num; +} + +longlong Item_func_numpoints::val_int() +{ + uint32 num; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + args[0]->null_value || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, num_points) || + geom.num_points(&num)); + return (longlong) num; +} + +double Item_func_x::val() +{ + double res; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, get_x) || + geom.get_x(&res)); + return res; +} + +double Item_func_y::val() +{ + double res; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, get_y) || + geom.get_y(&res)); + return res; +} + +double Item_func_area::val() +{ + double res; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, area) || + geom.area(&res)); + return res; +} + +double Item_func_glength::val() +{ + double res; + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE) || + !GEOM_METHOD_PRESENT(geom, length) || + geom.length(&res)); + return res; +} + +longlong Item_func_srid::val_int() +{ + String *swkb= args[0]->val_str(&value); + Geometry geom; + + null_value= (!swkb || + geom.create_from_wkb(swkb->ptr() + SRID_SIZE, + swkb->length() - SRID_SIZE)); + uint32 res= uint4korr(swkb->ptr()); + return (longlong) res; +} diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h new file mode 100644 index 00000000000..21e94735f31 --- /dev/null +++ b/sql/item_geofunc.h @@ -0,0 +1,360 @@ +/* Copyright (C) 2000-2003 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +/* This file defines all spatial functions */ + +#ifdef __GNUC__ +#pragma interface /* gcc class implementation */ +#endif + +#define SRID_SIZE sizeof(uint32) + +class Item_func_geometry_from_text: public Item_str_func +{ +public: + Item_func_geometry_from_text(Item *a) :Item_str_func(a) {} + Item_func_geometry_from_text(Item *a, Item *srid) :Item_str_func(a, srid) {} + const char *func_name() const { return "geometryfromtext"; } + String *val_str(String *); + void fix_length_and_dec(); +}; + +class Item_func_geometry_from_wkb: public Item_str_func +{ +public: + Item_func_geometry_from_wkb(Item *a): Item_str_func(a) {} + Item_func_geometry_from_wkb(Item *a, Item *srid): Item_str_func(a, srid) {} + const char *func_name() const { return "geometryfromwkb"; } + String *val_str(String *); + void fix_length_and_dec(); +}; + +class Item_func_as_text: public Item_str_func +{ +public: + Item_func_as_text(Item *a): Item_str_func(a) {} + const char *func_name() const { return "astext"; } + String *val_str(String *); + void fix_length_and_dec(); +}; + +class Item_func_as_wkb: public Item_str_func +{ +public: + Item_func_as_wkb(Item *a): Item_str_func(a) {} + const char *func_name() const { return "aswkb"; } + String *val_str(String *); + void fix_length_and_dec(); +}; + +class Item_func_geometry_type: public Item_str_func +{ +public: + Item_func_geometry_type(Item *a): Item_str_func(a) {} + String *val_str(String *); + const char *func_name() const { return "geometrytype"; } + void fix_length_and_dec() + { + max_length=20; // "GeometryCollection" is the most long + }; +}; + +class Item_func_centroid: public Item_str_func +{ +public: + Item_func_centroid(Item *a): Item_str_func(a) {} + const char *func_name() const { return "centroid"; } + String *val_str(String *); + void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} +}; + +class Item_func_envelope: public Item_str_func +{ +public: + Item_func_envelope(Item *a): Item_str_func(a) {} + const char *func_name() const { return "envelope"; } + String *val_str(String *); + void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} +}; + +class Item_func_point: public Item_str_func +{ +public: + Item_func_point(Item *a, Item *b): Item_str_func(a, b) {} + Item_func_point(Item *a, Item *b, Item *srid): Item_str_func(a, b, srid) {} + const char *func_name() const { return "point"; } + String *val_str(String *); + void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} +}; + +class Item_func_spatial_decomp: public Item_str_func +{ + enum Functype decomp_func; +public: + Item_func_spatial_decomp(Item *a, Item_func::Functype ft) : + Item_str_func(a) { decomp_func = ft; } + const char *func_name() const + { + switch (decomp_func) + { + case SP_STARTPOINT: + return "startpoint"; + case SP_ENDPOINT: + return "endpoint"; + case SP_EXTERIORRING: + return "exteriorring"; + default: + return "spatial_decomp_unknown"; + } + } + String *val_str(String *); + void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} +}; + +class Item_func_spatial_decomp_n: public Item_str_func +{ + enum Functype decomp_func_n; +public: + Item_func_spatial_decomp_n(Item *a, Item *b, Item_func::Functype ft): + Item_str_func(a, b) { decomp_func_n = ft; } + const char *func_name() const + { + switch (decomp_func_n) + { + case SP_POINTN: + return "pointn"; + case SP_GEOMETRYN: + return "geometryn"; + case SP_INTERIORRINGN: + return "interiorringn"; + default: + return "spatial_decomp_n_unknown"; + } + } + String *val_str(String *); + void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} +}; + +class Item_func_spatial_collection: public Item_str_func +{ + String tmp_value; + enum Geometry::wkbType coll_type; + enum Geometry::wkbType item_type; +public: + Item_func_spatial_collection( + List<Item> &list, enum Geometry::wkbType ct, enum Geometry::wkbType it): + Item_str_func(list) + { + coll_type=ct; + item_type=it; + } + String *val_str(String *); + void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} + const char *func_name() const { return "multipoint"; } +}; + +#ifdef HAVE_COMPRESS + +class Item_func_compress: public Item_str_func +{ + String buffer; +public: + Item_func_compress(Item *a):Item_str_func(a){} + String *val_str(String *); + void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} + const char *func_name() const{return "compress";} +}; + +class Item_func_uncompress: public Item_str_func +{ + String buffer; +public: + Item_func_uncompress(Item *a): Item_str_func(a){} + String *val_str(String *); + void fix_length_and_dec(){max_length= MAX_BLOB_WIDTH;} + const char *func_name() const{return "uncompress";} +}; + +#endif + +/* + Spatial relations +*/ + +class Item_func_spatial_rel: public Item_bool_func2 +{ + enum Functype spatial_rel; +public: + Item_func_spatial_rel(Item *a,Item *b, enum Functype sp_rel) : + Item_bool_func2(a,b) { spatial_rel = sp_rel; } + longlong val_int(); + enum Functype functype() const + { + switch (spatial_rel) { + case SP_CONTAINS_FUNC: + return SP_WITHIN_FUNC; + case SP_WITHIN_FUNC: + return SP_CONTAINS_FUNC; + default: + return spatial_rel; + } + } + enum Functype rev_functype() const { return spatial_rel; } + const char *func_name() const + { + switch (spatial_rel) { + case SP_CONTAINS_FUNC: + return "contains"; + case SP_WITHIN_FUNC: + return "within"; + case SP_EQUALS_FUNC: + return "equals"; + case SP_DISJOINT_FUNC: + return "disjoint"; + case SP_INTERSECTS_FUNC: + return "intersects"; + case SP_TOUCHES_FUNC: + return "touches"; + case SP_CROSSES_FUNC: + return "crosses"; + case SP_OVERLAPS_FUNC: + return "overlaps"; + default: + return "sp_unknown"; + } + } +}; + +class Item_func_isempty: public Item_bool_func +{ +public: + Item_func_isempty(Item *a): Item_bool_func(a) {} + longlong val_int(); + optimize_type select_optimize() const { return OPTIMIZE_NONE; } + const char *func_name() const { return "isempty"; } +}; + +class Item_func_issimple: public Item_bool_func +{ +public: + Item_func_issimple(Item *a): Item_bool_func(a) {} + longlong val_int(); + optimize_type select_optimize() const { return OPTIMIZE_NONE; } + const char *func_name() const { return "issimple"; } +}; + +class Item_func_isclosed: public Item_bool_func +{ +public: + Item_func_isclosed(Item *a): Item_bool_func(a) {} + longlong val_int(); + optimize_type select_optimize() const { return OPTIMIZE_NONE; } + const char *func_name() const { return "isclosed"; } +}; + +class Item_func_dimension: public Item_int_func +{ + String value; +public: + Item_func_dimension(Item *a): Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "dimension"; } + void fix_length_and_dec() { max_length=10; } +}; + +class Item_func_x: public Item_real_func +{ + String value; +public: + Item_func_x(Item *a): Item_real_func(a) {} + double val(); + const char *func_name() const { return "x"; } +}; + + +class Item_func_y: public Item_real_func +{ + String value; +public: + Item_func_y(Item *a): Item_real_func(a) {} + double val(); + const char *func_name() const { return "y"; } +}; + + +class Item_func_numgeometries: public Item_int_func +{ + String value; +public: + Item_func_numgeometries(Item *a): Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "numgeometries"; } + void fix_length_and_dec() { max_length=10; } +}; + + +class Item_func_numinteriorring: public Item_int_func +{ + String value; +public: + Item_func_numinteriorring(Item *a): Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "numinteriorring"; } + void fix_length_and_dec() { max_length=10; } +}; + + +class Item_func_numpoints: public Item_int_func +{ + String value; +public: + Item_func_numpoints(Item *a): Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "numpoints"; } + void fix_length_and_dec() { max_length=10; } +}; + + +class Item_func_area: public Item_real_func +{ + String value; +public: + Item_func_area(Item *a): Item_real_func(a) {} + double val(); + const char *func_name() const { return "area"; } +}; + + +class Item_func_glength: public Item_real_func +{ + String value; +public: + Item_func_glength(Item *a): Item_real_func(a) {} + double val(); + const char *func_name() const { return "glength"; } +}; + + +class Item_func_srid: public Item_int_func +{ + String value; +public: + Item_func_srid(Item *a): Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "srid"; } + void fix_length_and_dec() { max_length= 10; } +}; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 8aaf9f944e8..3c4b5070850 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -27,9 +27,6 @@ #include "mysql_priv.h" #include "sql_acl.h" #include <m_ctype.h> -#ifdef HAVE_CRYPT_H -#include <crypt.h> -#endif #ifdef HAVE_OPENSSL #include <openssl/des.h> #endif /* HAVE_OPENSSL */ @@ -931,7 +928,7 @@ void Item_str_func::left_right_max_length() max_length=args[0]->max_length; if (args[1]->const_item()) { - int length=(int) args[1]->val_int(); + int length=(int) args[1]->val_int()*charset()->mbmaxlen; if (length <= 0) max_length=0; else @@ -942,6 +939,7 @@ void Item_str_func::left_right_max_length() void Item_func_left::fix_length_and_dec() { + set_charset(args[0]->charset(), args[0]->coercibility); left_right_max_length(); } @@ -968,6 +966,7 @@ String *Item_func_right::val_str(String *str) void Item_func_right::fix_length_and_dec() { + set_charset(args[0]->charset(), args[0]->coercibility); left_right_max_length(); } @@ -1012,7 +1011,7 @@ void Item_func_substr::fix_length_and_dec() } if (arg_count == 3 && args[2]->const_item()) { - int32 length= (int32) args[2]->val_int(); + int32 length= (int32) args[2]->val_int() * default_charset_info->mbmaxlen; if (length <= 0) max_length=0; /* purecov: inspected */ else @@ -1462,10 +1461,12 @@ String *Item_func_database::val_str(String *str) { THD *thd= current_thd; if (!thd->db) + { str->length(0); + str->set_charset(system_charset_info); + } else - str->copy((const char*) thd->db,(uint) strlen(thd->db), - system_charset_info, default_charset()); + str->copy((const char*) thd->db,(uint) strlen(thd->db),system_charset_info); return str; } @@ -1474,7 +1475,7 @@ String *Item_func_database::val_str(String *str) String *Item_func_user::val_str(String *str) { THD *thd=current_thd; - CHARSET_INFO *cs= default_charset(); + CHARSET_INFO *cs= system_charset_info; const char *host= thd->host_or_ip; uint res_length; @@ -1488,7 +1489,7 @@ String *Item_func_user::val_str(String *str) null_value=1; return 0; } - res_length=cs->snprintf(cs, (char*)str->ptr(), res_length, "%s@%s", + res_length=cs->cset->snprintf(cs, (char*)str->ptr(), res_length, "%s@%s", thd->user, host); str->length(res_length); str->set_charset(cs); @@ -1591,15 +1592,17 @@ String *Item_func_format::val_str(String *str) str_length=str->length(); if (nr < 0) str_length--; // Don't count sign - length=str->length()+(diff=(str_length- dec-1)/3); - if (diff) + + /* We need this test to handle 'nan' values */ + if (str_length >= dec+4) { char *tmp,*pos; - str=copy_if_not_alloced(&tmp_str,str,length); + length= str->length()+(diff=(str_length- dec-1)/3); + str= copy_if_not_alloced(&tmp_str,str,length); str->length(length); - tmp=(char*) str->ptr()+length - dec-1; - for (pos=(char*) str->ptr()+length ; pos != tmp; pos--) - pos[0]=pos[- (int) diff]; + tmp= (char*) str->ptr()+length - dec-1; + for (pos= (char*) str->ptr()+length ; pos != tmp; pos--) + pos[0]= pos[-(int) diff]; while (diff) { pos[0]=pos[-(int) diff]; pos--; @@ -2130,7 +2133,7 @@ String *Item_func_conv_charset3::val_str(String *str) while (1) { - cnvres=from_charset->mb_wc(from_charset,&wc,s,se); + cnvres=from_charset->cset->mb_wc(from_charset,&wc,s,se); if (cnvres>0) { s+=cnvres; @@ -2144,7 +2147,7 @@ String *Item_func_conv_charset3::val_str(String *str) break; outp: - cnvres=to_charset->wc_mb(to_charset,wc,d,de); + cnvres=to_charset->cset->wc_mb(to_charset,wc,d,de); if (cnvres>0) { d+=cnvres; @@ -2184,7 +2187,7 @@ void Item_func_set_collation::fix_length_and_dec() const char *colname; String tmp, *str= args[1]->val_str(&tmp); colname= str->c_ptr(); - if (!strncmp(colname,"BINARY",6)) + if (colname == binary_keyword) set_collation= get_charset_by_csname(args[0]->charset()->csname, MY_CS_BINSORT,MYF(0)); else @@ -2254,7 +2257,7 @@ String *Item_func_hex::val_str(String *str) if ((null_value= args[0]->null_value)) return 0; ptr= longlong2str(dec,ans,16); - if (str->copy(ans,(uint32) (ptr-ans),default_charset_info)) + if (str->copy(ans,(uint32) (ptr-ans),default_charset())) return &empty_string; // End of memory return str; } @@ -2363,7 +2366,7 @@ String* Item_func_export_set::val_str(String* str) } break; case 3: - sep_buf.set(",", 1, default_charset_info); + sep_buf.set(",", 1, default_charset()); sep = &sep_buf; } null_value=0; @@ -2519,428 +2522,6 @@ null: return 0; } - -/******************************************************* -General functions for spatial objects -********************************************************/ - -String *Item_func_geometry_from_text::val_str(String *str) -{ - Geometry geom; - String arg_val; - String *wkt= args[0]->val_str(&arg_val); - GTextReadStream trs(wkt->ptr(), wkt->length()); - uint32 srid; - - if ((arg_count == 2) && !args[1]->null_value) - srid= args[1]->val_int(); - else - srid= 0; - - if (str->reserve(SRID_SIZE, 512)) - return 0; - str->length(0); - str->q_append(srid); - if ((null_value=(args[0]->null_value || geom.create_from_wkt(&trs, str, 0)))) - return 0; - return str; -} - - -void Item_func_geometry_from_text::fix_length_and_dec() -{ - max_length=MAX_BLOB_WIDTH; -} - - -String *Item_func_geometry_from_wkb::val_str(String *str) -{ - String arg_val; - String *wkb= args[0]->val_str(&arg_val); - Geometry geom; - uint32 srid; - - if ((arg_count == 2) && !args[1]->null_value) - srid= args[1]->val_int(); - else - srid= 0; - - if (str->reserve(SRID_SIZE, 512)) - return 0; - str->length(0); - str->q_append(srid); - if ((null_value= (args[0]->null_value || - geom.create_from_wkb(wkb->ptr(), wkb->length())))) - return 0; - - str->append(*wkb); - return str; -} - - -void Item_func_geometry_from_wkb::fix_length_and_dec() -{ - max_length=MAX_BLOB_WIDTH; -} - - -String *Item_func_as_text::val_str(String *str) -{ - String arg_val; - String *swkb= args[0]->val_str(&arg_val); - Geometry geom; - - if ((null_value= (args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE)))) - return 0; - - str->length(0); - - if ((null_value= geom.as_wkt(str))) - return 0; - - return str; -} - -void Item_func_as_text::fix_length_and_dec() -{ - max_length=MAX_BLOB_WIDTH; -} - -String *Item_func_as_wkb::val_str(String *str) -{ - String arg_val; - String *swkb= args[0]->val_str(&arg_val); - Geometry geom; - - if ((null_value= (args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE)))) - return 0; - - str->copy(swkb->ptr() + SRID_SIZE, swkb->length() - SRID_SIZE, - &my_charset_bin); - return str; -} - -void Item_func_as_wkb::fix_length_and_dec() -{ - max_length= MAX_BLOB_WIDTH; -} - -String *Item_func_geometry_type::val_str(String *str) -{ - String *swkb= args[0]->val_str(str); - Geometry geom; - - if ((null_value= (args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE)))) - return 0; - str->copy(geom.get_class_info()->m_name, - strlen(geom.get_class_info()->m_name), - default_charset_info); - return str; -} - - -String *Item_func_envelope::val_str(String *str) -{ - String arg_val; - String *swkb= args[0]->val_str(&arg_val); - Geometry geom; - - if ((null_value= args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE))) - return 0; - - uint32 srid= uint4korr(swkb->ptr()); - str->length(0); - if (str->reserve(SRID_SIZE, 512)) - return 0; - str->q_append(srid); - return (null_value= geom.envelope(str)) ? 0 : str; -} - - -String *Item_func_centroid::val_str(String *str) -{ - String arg_val; - String *swkb= args[0]->val_str(&arg_val); - Geometry geom; - - if ((null_value= args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE) || - !GEOM_METHOD_PRESENT(geom, centroid))) - return 0; - - if (str->reserve(SRID_SIZE, 512)) - return 0; - str->length(0); - uint32 srid= uint4korr(swkb->ptr()); - str->q_append(srid); - - return (null_value= geom.centroid(str)) ? 0 : str; -} - - -/*********************************************** - Spatial decomposition functions -***********************************************/ - -String *Item_func_spatial_decomp::val_str(String *str) -{ - String arg_val; - String *swkb= args[0]->val_str(&arg_val); - Geometry geom; - - if ((null_value= (args[0]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE)))) - return 0; - - null_value= 1; - if (str->reserve(SRID_SIZE, 512)) - return 0; - str->length(0); - uint32 srid= uint4korr(swkb->ptr()); - str->q_append(srid); - switch(decomp_func) - { - case SP_STARTPOINT: - if (!GEOM_METHOD_PRESENT(geom,start_point) || geom.start_point(str)) - goto ret; - break; - - case SP_ENDPOINT: - if (!GEOM_METHOD_PRESENT(geom,end_point) || geom.end_point(str)) - goto ret; - break; - - case SP_EXTERIORRING: - if (!GEOM_METHOD_PRESENT(geom,exterior_ring) || geom.exterior_ring(str)) - goto ret; - break; - - default: - goto ret; - } - null_value= 0; - -ret: - return null_value ? 0 : str; -} - - -String *Item_func_spatial_decomp_n::val_str(String *str) -{ - String arg_val; - String *swkb= args[0]->val_str(&arg_val); - long n= (long) args[1]->val_int(); - Geometry geom; - - if ((null_value= (args[0]->null_value || args[1]->null_value || - geom.create_from_wkb(swkb->ptr() + SRID_SIZE, - swkb->length() - SRID_SIZE)))) - return 0; - - null_value= 1; - if (str->reserve(SRID_SIZE, 512)) - return 0; - str->length(0); - uint32 srid= uint4korr(swkb->ptr()); - str->q_append(srid); - switch(decomp_func_n) - { - case SP_POINTN: - if (!GEOM_METHOD_PRESENT(geom,point_n) || geom.point_n(n,str)) - goto ret; - break; - - case SP_GEOMETRYN: - if (!GEOM_METHOD_PRESENT(geom,geometry_n) || geom.geometry_n(n,str)) - goto ret; - break; - - case SP_INTERIORRINGN: - if (!GEOM_METHOD_PRESENT(geom,interior_ring_n) || - geom.interior_ring_n(n,str)) - goto ret; - break; - - default: - goto ret; - } - null_value= 0; - -ret: - return null_value ? 0 : str; -} - - - -/*********************************************** -Functions to concatinate various spatial objects -************************************************/ - - -/* -* Concatinate doubles into Point -*/ - - -String *Item_func_point::val_str(String *str) -{ - double x= args[0]->val(); - double y= args[1]->val(); - - if ( (null_value= (args[0]->null_value || - args[1]->null_value || - str->realloc(1 + 4 + 8 + 8)))) - return 0; - - str->length(0); - str->q_append((char)Geometry::wkbNDR); - str->q_append((uint32)Geometry::wkbPoint); - str->q_append(x); - str->q_append(y); - return str; -} - - -/* - Concatinates various items into various collections - with checkings for valid wkb type of items. - For example, MultiPoint can be a collection of Points only. - coll_type contains wkb type of target collection. - item_type contains a valid wkb type of items. - In the case when coll_type is wkbGeometryCollection, - we do not check wkb type of items, any is valid. -*/ - -String *Item_func_spatial_collection::val_str(String *str) -{ - String arg_value; - uint i; - - null_value= 1; - - str->length(0); - if (str->reserve(1 + 4 + 4, 512)) - return 0; - - str->q_append((char) Geometry::wkbNDR); - str->q_append((uint32) coll_type); - str->q_append((uint32) arg_count); - - for (i= 0; i < arg_count; ++i) - { - String *res= args[i]->val_str(&arg_value); - if (args[i]->null_value) - goto ret; - - if ( coll_type == Geometry::wkbGeometryCollection ) - { - /* - In the case of GeometryCollection we don't need - any checkings for item types, so just copy them - into target collection - */ - if ((null_value= str->reserve(res->length(), 512))) - goto ret; - - str->q_append(res->ptr(), res->length()); - } - else - { - enum Geometry::wkbType wkb_type; - uint32 len=res->length(); - const char *data= res->ptr() + 1; - - /* - In the case of named collection we must to - check that items are of specific type, let's - do this checking now - */ - - if (len < 5) - goto ret; - wkb_type= (Geometry::wkbType) uint4korr(data); - data+= 4; - len-= 5; - if (wkb_type != item_type) - goto ret; - - switch (coll_type) { - case Geometry::wkbMultiPoint: - case Geometry::wkbMultiLineString: - case Geometry::wkbMultiPolygon: - if (len < WKB_HEADER_SIZE) - goto ret; - - data-= WKB_HEADER_SIZE; - len+= WKB_HEADER_SIZE; - if (str->reserve(len, 512)) - goto ret; - str->q_append(data, len); - break; - - case Geometry::wkbLineString: - if (str->reserve(POINT_DATA_SIZE, 512)) - goto ret; - str->q_append(data, POINT_DATA_SIZE); - break; - - case Geometry::wkbPolygon: - { - uint32 n_points; - double x1, y1, x2, y2; - - if (len < 4 + 2 * POINT_DATA_SIZE) - goto ret; - - uint32 llen= len; - const char *ldata= data; - - n_points= uint4korr(data); - data+= 4; - float8get(x1, data); - data+= 8; - float8get(y1, data); - data+= 8; - - data+= (n_points - 2) * POINT_DATA_SIZE; - - float8get(x2, data); - float8get(y2, data + 8); - - if ((x1 != x2) || (y1 != y2)) - goto ret; - - if (str->reserve(llen, 512)) - goto ret; - str->q_append(ldata, llen); - } - break; - - default: - goto ret; - } - } - } - - if (str->length() > current_thd->variables.max_allowed_packet) - goto ret; - - null_value = 0; - -ret: - return null_value ? 0 : str; -} - #ifdef HAVE_COMPRESS #include "../zlib/zlib.h" diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index abe2a5355be..65aad3a3fff 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -333,12 +333,12 @@ public: class Item_func_database :public Item_str_func { public: - Item_func_database() {} + Item_func_database() { coercibility= COER_IMPLICIT; } String *val_str(String *); void fix_length_and_dec() { - max_length= MAX_FIELD_NAME * default_charset()->mbmaxlen; - set_charset(default_charset()); + max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; + set_charset(system_charset_info); } const char *func_name() const { return "database"; } }; @@ -346,12 +346,12 @@ public: class Item_func_user :public Item_str_func { public: - Item_func_user() {} + Item_func_user() { coercibility= COER_IMPLICIT; } String *val_str(String *); void fix_length_and_dec() { - max_length= (USERNAME_LENGTH+HOSTNAME_LENGTH+1)*default_charset()->mbmaxlen; - set_charset(default_charset()); + max_length= (USERNAME_LENGTH+HOSTNAME_LENGTH+1)*system_charset_info->mbmaxlen; + set_charset(system_charset_info); } const char *func_name() const { return "user"; } }; @@ -628,242 +628,3 @@ public: set_charset(default_charset()); }; }; - - -/******************************************************* -Spatial functions -********************************************************/ - -#define SRID_SIZE sizeof(uint32) - -class Item_func_geometry_from_text :public Item_str_func -{ -public: - Item_func_geometry_from_text(Item *a) :Item_str_func(a) {} - Item_func_geometry_from_text(Item *a, Item *srid) :Item_str_func(a, srid) {} - const char *func_name() const { return "geometryfromtext"; } - String *val_str(String *); - void fix_length_and_dec(); -}; - -class Item_func_geometry_from_wkb: public Item_str_func -{ -public: - Item_func_geometry_from_wkb(Item *a) :Item_str_func(a) {} - Item_func_geometry_from_wkb(Item *a, Item *srid) :Item_str_func(a, srid) {} - const char *func_name() const { return "geometryfromwkb"; } - String *val_str(String *); - void fix_length_and_dec(); -}; - -class Item_func_as_text :public Item_str_func -{ -public: - Item_func_as_text(Item *a) :Item_str_func(a) {} - const char *func_name() const { return "astext"; } - String *val_str(String *); - void fix_length_and_dec(); -}; - -class Item_func_as_wkb :public Item_str_func -{ -public: - Item_func_as_wkb(Item *a) :Item_str_func(a) {} - const char *func_name() const { return "aswkb"; } - String *val_str(String *); - void fix_length_and_dec(); -}; - -class Item_func_geometry_type :public Item_str_func -{ -public: - Item_func_geometry_type(Item *a) :Item_str_func(a) {} - String *val_str(String *); - const char *func_name() const { return "geometrytype"; } - void fix_length_and_dec() - { - max_length=20; // "GeometryCollection" is the most long - }; -}; - -class Item_func_centroid :public Item_str_func -{ -public: - Item_func_centroid(Item *a) :Item_str_func(a) {} - const char *func_name() const { return "centroid"; } - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} -}; - -class Item_func_envelope :public Item_str_func -{ -public: - Item_func_envelope(Item *a) :Item_str_func(a) {} - const char *func_name() const { return "envelope"; } - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} -}; - -class Item_func_point :public Item_str_func -{ -public: - Item_func_point(Item *a, Item *b) :Item_str_func(a, b) {} - Item_func_point(Item *a, Item *b, Item *srid) :Item_str_func(a, b, srid) {} - const char *func_name() const { return "point"; } - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} -}; - -class Item_func_spatial_decomp :public Item_str_func -{ - enum Functype decomp_func; -public: - Item_func_spatial_decomp(Item *a, Item_func::Functype ft) : - Item_str_func(a) { decomp_func = ft; } - const char *func_name() const - { - switch (decomp_func) - { - case SP_STARTPOINT: - return "startpoint"; - case SP_ENDPOINT: - return "endpoint"; - case SP_EXTERIORRING: - return "exteriorring"; - default: - return "spatial_decomp_unknown"; - } - } - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} -}; - -class Item_func_spatial_decomp_n :public Item_str_func -{ - enum Functype decomp_func_n; -public: - Item_func_spatial_decomp_n(Item *a, Item *b, Item_func::Functype ft) : - Item_str_func(a, b) { decomp_func_n = ft; } - const char *func_name() const - { - switch (decomp_func_n) - { - case SP_POINTN: - return "pointn"; - case SP_GEOMETRYN: - return "geometryn"; - case SP_INTERIORRINGN: - return "interiorringn"; - default: - return "spatial_decomp_n_unknown"; - } - } - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} -}; - - -class Item_func_spatial_collection :public Item_str_func -{ - String tmp_value; - enum Geometry::wkbType coll_type; - enum Geometry::wkbType item_type; -public: - Item_func_spatial_collection( - List<Item> &list, enum Geometry::wkbType ct, enum Geometry::wkbType it) : - Item_str_func(list) - { - coll_type=ct; - item_type=it; - } - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "multipoint"; } -}; - -#ifdef HAVE_COMPRESS - -class Item_func_compress : public Item_str_func -{ - String buffer; -public: - Item_func_compress(Item *a):Item_str_func(a){} - String *val_str(String *); - void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} - const char *func_name() const{return "compress";} -}; - -class Item_func_uncompress : public Item_str_func -{ - String buffer; -public: - Item_func_uncompress(Item *a):Item_str_func(a){} - String *val_str(String *); - void fix_length_and_dec(){max_length= MAX_BLOB_WIDTH;} - const char *func_name() const{return "uncompress";} -}; - -#endif - -/* -class Item_func_multipoint :public Item_str_func -{ - String tmp_value; -public: - Item_func_multipoint(List<Item> &list) :Item_str_func(list) {} - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "multipoint"; } -}; - -class Item_func_linestring :public Item_str_func -{ - String tmp_value; -public: - Item_func_linestring(List<Item> &list) :Item_str_func(list) {} - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "linestring"; } -}; - -class Item_func_multilinestring :public Item_str_func -{ - String tmp_value; -public: - Item_func_multilinestring(List<Item> &list) :Item_str_func(list) {} - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "multilinestring"; } -}; - -class Item_func_polygon :public Item_str_func -{ - String tmp_value; -public: - Item_func_polygon(List<Item> &list) :Item_str_func(list) {} - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "polygon"; } -}; - -class Item_func_multipolygon :public Item_str_func -{ - String tmp_value; -public: - Item_func_multipolygon(List<Item> &list) :Item_str_func(list) {} - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "multipolygon"; } -}; - -class Item_func_geometrycollection :public Item_str_func -{ - String tmp_value; -public: - Item_func_geometrycollection(List<Item> &list) :Item_str_func(list) {} - String *val_str(String *); - void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;} - const char *func_name() const { return "geometrycollection"; } -}; - -*/ diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index c749fba616f..8c9b3eeebde 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -79,8 +79,10 @@ void Item_subselect::select_transformer(THD *thd, st_select_lex_unit *unit) } -bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) +bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) { + thd= thd_param; + if (substitution) { (*ref)= substitution; @@ -115,6 +117,20 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) return res; } +bool Item_subselect::exec() +{ + MEM_ROOT *old_root= my_pthread_getspecific_ptr(MEM_ROOT*, THR_MALLOC); + if (&thd->mem_root != old_root) + { + my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root); + int res= engine->exec(); + my_pthread_setspecific_ptr(THR_MALLOC, old_root); + return (res); + } + else + return engine->exec(); +} + Item::Type Item_subselect::type() const { return SUBSELECT_ITEM; @@ -253,12 +269,12 @@ bool Item_singlerow_subselect::null_inside() void Item_singlerow_subselect::bring_value() { - engine->exec(); + exec(); } double Item_singlerow_subselect::val () { - if (!engine->exec() && !value->null_value) + if (!exec() && !value->null_value) { null_value= 0; return value->val(); @@ -272,7 +288,7 @@ double Item_singlerow_subselect::val () longlong Item_singlerow_subselect::val_int () { - if (!engine->exec() && !value->null_value) + if (!exec() && !value->null_value) { null_value= 0; return value->val_int(); @@ -286,7 +302,7 @@ longlong Item_singlerow_subselect::val_int () String *Item_singlerow_subselect::val_str (String *str) { - if (!engine->exec() && !value->null_value) + if (!exec() && !value->null_value) { null_value= 0; return value->val_str(str); @@ -354,7 +370,7 @@ void Item_exists_subselect::fix_length_and_dec() double Item_exists_subselect::val () { - if (engine->exec()) + if (exec()) { reset(); return 0; @@ -364,7 +380,7 @@ double Item_exists_subselect::val () longlong Item_exists_subselect::val_int () { - if (engine->exec()) + if (exec()) { reset(); return 0; @@ -374,7 +390,7 @@ longlong Item_exists_subselect::val_int () String *Item_exists_subselect::val_str(String *str) { - if (engine->exec()) + if (exec()) { reset(); return 0; @@ -385,7 +401,7 @@ String *Item_exists_subselect::val_str(String *str) double Item_in_subselect::val () { - if (engine->exec()) + if (exec()) { reset(); null_value= 1; @@ -398,7 +414,7 @@ double Item_in_subselect::val () longlong Item_in_subselect::val_int () { - if (engine->exec()) + if (exec()) { reset(); null_value= 1; @@ -411,7 +427,7 @@ longlong Item_in_subselect::val_int () String *Item_in_subselect::val_str(String *str) { - if (engine->exec()) + if (exec()) { reset(); null_value= 1; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index fc4dad5a6b3..3ed3f2af0e9 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -36,6 +36,8 @@ class Item_subselect :public Item_result_field my_bool engine_owner; /* Is this item owner of engine */ my_bool value_assigned; /* value already assigned to subselect */ protected: + /* thread handler, will be assigned in fix_fields only */ + THD *thd; /* substitution instead of subselect in case of optimization */ Item *substitution; /* engine that perform execution of subselect (single select or union) */ @@ -81,6 +83,7 @@ public: return null_value; } bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref); + bool exec(); virtual void fix_length_and_dec(); table_map used_tables() const; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 60976ab993a..e5be3809230 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -219,12 +219,14 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) void Item_sum_sum::reset() { - null_value=0; sum=0.0; Item_sum_sum::add(); + null_value=1; sum=0.0; Item_sum_sum::add(); } bool Item_sum_sum::add() { sum+=args[0]->val(); + if (!args[0]->null_value) + null_value= 0; return 0; } @@ -641,8 +643,10 @@ void Item_sum_sum::reset_field() { double nr=args[0]->val(); // Nulls also return 0 float8store(result_field->ptr,nr); - null_value=0; - result_field->set_notnull(); + if (args[0]->null_value) + result_field->set_null(); + else + result_field->set_notnull(); } @@ -698,7 +702,10 @@ void Item_sum_sum::update_field(int offset) float8get(old_nr,res+offset); nr=args[0]->val(); if (!args[0]->null_value) + { old_nr+=nr; + result_field->set_notnull(); + } float8store(res,old_nr); } diff --git a/sql/item_sum.h b/sql/item_sum.h index e306a42c6bc..7deec8de564 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -99,9 +99,6 @@ public: class Item_sum_int :public Item_sum_num { - void fix_length_and_dec() - { decimals=0; max_length=21; maybe_null=null_value=0; } - public: Item_sum_int(Item *item_par) :Item_sum_num(item_par) {} Item_sum_int(List<Item> &list) :Item_sum_num(list) {} @@ -109,6 +106,8 @@ public: double val() { return (double) val_int(); } String *val_str(String*str); enum Item_result result_type () const { return INT_RESULT; } + void fix_length_and_dec() + { decimals=0; max_length=21; maybe_null=null_value=0; } }; @@ -127,6 +126,7 @@ class Item_sum_sum :public Item_sum_num double val(); void reset_field(); void update_field(int offset); + void no_rows_in_result() {} const char *func_name() const { return "sum"; } Item *copy_or_same(THD* thd) { return new Item_sum_sum(thd, *this); } }; @@ -449,6 +449,8 @@ class Item_sum_bit :public Item_sum_int void reset(); longlong val_int(); void reset_field(); + void fix_length_and_dec() + { decimals=0; max_length=21; unsigned_flag=1; maybe_null=null_value=0; } }; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 997247b6141..61c869cddba 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -511,7 +511,7 @@ void Item_func_curtime::fix_length_and_dec() (ulong) (((uint) start->tm_min)*100L+ (uint) start->tm_sec)); - buff_length=cs->snprintf(cs,buff,sizeof(buff),"%02d:%02d:%02d", + buff_length=cs->cset->snprintf(cs,buff,sizeof(buff),"%02d:%02d:%02d", (int) start->tm_hour, (int) start->tm_min, (int) start->tm_sec); @@ -543,7 +543,7 @@ void Item_func_now::fix_length_and_dec() (ulong) (((uint) start->tm_min)*100L+ (uint) start->tm_sec))); - buff_length= (uint) cs->snprintf(cs,buff, sizeof(buff), + buff_length= (uint) cs->cset->snprintf(cs,buff, sizeof(buff), "%04d-%02d-%02d %02d:%02d:%02d", ((int) (start->tm_year+1900)) % 10000, (int) start->tm_mon+1, @@ -950,7 +950,7 @@ String *Item_func_from_unixtime::val_str(String *str) l=20*cs->mbmaxlen+32; if (str->alloc(l)) return str; /* purecov: inspected */ - l=cs->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d %02d:%02d:%02d", + l=cs->cset->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d %02d:%02d:%02d", (int) start->tm_year+1900, (int) start->tm_mon+1, (int) start->tm_mday, @@ -1134,7 +1134,7 @@ String *Item_date_add_interval::val_str(String *str) l=11*cs->mbmaxlen+32; if (str->alloc(l)) goto null_date; - l=cs->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d", + l=cs->cset->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d", ltime.year,ltime.month,ltime.day); str->length(l); } @@ -1143,7 +1143,7 @@ String *Item_date_add_interval::val_str(String *str) l=20*cs->mbmaxlen+32; if (str->alloc(l)) goto null_date; - l=cs->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d %02d:%02d:%02d", + l=cs->cset->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d %02d:%02d:%02d", ltime.year,ltime.month,ltime.day, ltime.hour,ltime.minute,ltime.second); str->length(l); diff --git a/sql/lex.h b/sql/lex.h index f85431aadf7..e89c9f51520 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -430,6 +430,7 @@ static SYMBOL sql_functions[] = { { "AES_DECRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_decrypt)}, { "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)}, { "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)}, + { "ASBINARY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_wkb)}, { "ASTEXT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_text)}, { "ASWKB", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_wkb)}, { "ATAN", SYM(ATAN),0,0}, diff --git a/sql/log.cc b/sql/log.cc index c9e20bc0cc9..c05d52bdc5d 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -317,7 +317,10 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, DBUG_RETURN(0); err: - sql_print_error("Could not use %s for logging (error %d)", log_name, errno); + sql_print_error("Could not use %s for logging (error %d). \ +Turning logging off for the whole duration of the MySQL server process. \ +To turn it on again: fix the cause, \ +shutdown the MySQL server and restart it.", log_name, errno); if (file >= 0) my_close(file,MYF(0)); if (index_file_nr >= 0) @@ -1157,6 +1160,8 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command, bool MYSQL_LOG::write(Log_event* event_info) { + THD *thd=event_info->thd; + bool called_handler_commit=0; bool error=0; bool should_rotate = 0; DBUG_ENTER("MYSQL_LOG::write(event)"); @@ -1171,7 +1176,6 @@ bool MYSQL_LOG::write(Log_event* event_info) /* In most cases this is only called if 'is_open()' is true */ if (is_open()) { - THD *thd=event_info->thd; const char *local_db = event_info->get_db(); #ifdef USING_TRANSACTIONS IO_CACHE *file = ((event_info->get_cache_stmt()) ? @@ -1268,24 +1272,35 @@ bool MYSQL_LOG::write(Log_event* event_info) the table handler commit here, protected by the LOCK_log mutex, because otherwise the transactions may end up in a different order in the table handler log! + + Note that we will NOT call ha_report_binlog_offset_and_commit() if + there are binlog events cached in the transaction cache. That is + because then the log event which we write to the binlog here is + not a transactional event. In versions < 4.0.13 before this fix this + caused an InnoDB transaction to be committed if in the middle there + was a MyISAM event! */ - if (file == &log_file) + if (file == &log_file) // we are writing to the real log (disk) { - /* - LOAD DATA INFILE in AUTOCOMMIT=1 mode writes to the binlog - chunks also before it is successfully completed. We only report - the binlog write and do the commit inside the transactional table - handler if the log event type is appropriate. - */ - - if (event_info->get_type_code() == QUERY_EVENT - || event_info->get_type_code() == EXEC_LOAD_EVENT) + if (opt_using_transactions && !my_b_tell(&thd->transaction.trans_log)) { - error = ha_report_binlog_offset_and_commit(thd, log_file_name, - file->pos_in_file); + /* + LOAD DATA INFILE in AUTOCOMMIT=1 mode writes to the binlog + chunks also before it is successfully completed. We only report + the binlog write and do the commit inside the transactional table + handler if the log event type is appropriate. + */ + + if (event_info->get_type_code() == QUERY_EVENT + || event_info->get_type_code() == EXEC_LOAD_EVENT) + { + error = ha_report_binlog_offset_and_commit(thd, log_file_name, + file->pos_in_file); + called_handler_commit=1; + } } - + /* we wrote to the real log, check automatic rotation */ should_rotate= (my_b_tell(file) >= (my_off_t) max_binlog_size); } @@ -1309,6 +1324,16 @@ err: } pthread_mutex_unlock(&LOCK_log); + + /* + Flush the transactional handler log file now that we have released + LOCK_log; the flush is placed here to eliminate the bottleneck on the + group commit + */ + + if (called_handler_commit) + ha_commit_complete(thd); + #ifdef HAVE_REPLICATION if (should_rotate && expire_logs_days) { @@ -1316,7 +1341,6 @@ err: if (purge_time >= 0) error= purge_logs_before_date(purge_time); } - #endif DBUG_RETURN(error); } @@ -1423,6 +1447,13 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache) } VOID(pthread_mutex_unlock(&LOCK_log)); + + /* Flush the transactional handler log file now that we have released + LOCK_log; the flush is placed here to eliminate the bottleneck on the + group commit */ + + ha_commit_complete(thd); + DBUG_RETURN(0); err: diff --git a/sql/log_event.cc b/sql/log_event.cc index 530e878b458..fb690efc364 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -26,11 +26,10 @@ #define log_cs &my_charset_latin1 -/***************************************************************************** - +/* my_b_safe_write() +*/ - ****************************************************************************/ inline int my_b_safe_write(IO_CACHE* file, const byte *buf, int len) { @@ -45,11 +44,11 @@ inline int my_b_safe_write(IO_CACHE* file, const byte *buf, return my_b_write(file, buf,len); } -/***************************************************************************** +/* pretty_print_str() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT static void pretty_print_str(FILE* file, char* str, int len) { @@ -75,11 +74,11 @@ static void pretty_print_str(FILE* file, char* str, int len) } #endif // MYSQL_CLIENT -/***************************************************************************** +/* ignored_error_code() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) inline int ignored_error_code(int err_code) { @@ -87,11 +86,10 @@ inline int ignored_error_code(int err_code) } #endif -/***************************************************************************** - +/* pretty_print_str() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT static char* pretty_print_str(char* packet, char* str, int len) { @@ -117,13 +115,13 @@ static char* pretty_print_str(char* packet, char* str, int len) *pos++= '\''; return pos; } -#endif // !MYSQL_CLIENT +#endif /* !MYSQL_CLIENT */ -/***************************************************************************** +/* slave_load_file_stem() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) static inline char* slave_load_file_stem(char*buf, uint file_id, int event_server_id) @@ -138,8 +136,7 @@ static inline char* slave_load_file_stem(char*buf, uint file_id, } #endif -/***************************************************************************** - +/* cleanup_load_tmpdir() Delete all temporary files used for SQL_LOAD. @@ -148,8 +145,8 @@ static inline char* slave_load_file_stem(char*buf, uint file_id, - When we get a 'server start' event, we should only remove the files associated with the server id that just started. Easily fixable by adding server_id as a prefix to the log files. +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) static void cleanup_load_tmpdir() { @@ -170,22 +167,22 @@ static void cleanup_load_tmpdir() } #endif -/***************************************************************************** +/* write_str() +*/ - ****************************************************************************/ static bool write_str(IO_CACHE *file, char *str, byte length) { return (my_b_safe_write(file, &length, 1) || my_b_safe_write(file, (byte*) str, (int) length)); } -/***************************************************************************** +/* read_str() +*/ - ****************************************************************************/ static inline int read_str(char * &buf, char *buf_end, char * &str, uint8 &len) { @@ -198,19 +195,14 @@ static inline int read_str(char * &buf, char *buf_end, char * &str, } -/***************************************************************************** - ***************************************************************************** - - Log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Log_event methods +**************************************************************************/ +/* Log_event::get_type_str() +*/ - ****************************************************************************/ const char* Log_event::get_type_str() { switch(get_type_code()) { @@ -232,11 +224,11 @@ const char* Log_event::get_type_str() } } -/***************************************************************************** +/* Log_event::Log_event() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) :temp_buf(0), exec_time(0), cached_event_len(0), flags(flags_arg), @@ -258,13 +250,13 @@ Log_event::Log_event() when= time(NULL); log_pos= 0; } -#endif // !MYSQL_CLIENT +#endif /* !MYSQL_CLIENT */ -/***************************************************************************** +/* Log_event::Log_event() +*/ - ****************************************************************************/ Log_event::Log_event(const char* buf, bool old_format) :temp_buf(0), cached_event_len(0), cache_stmt(0) { @@ -285,15 +277,13 @@ Log_event::Log_event(const char* buf, bool old_format) #endif } - #ifndef MYSQL_CLIENT #ifdef HAVE_REPLICATION -/***************************************************************************** - +/* Log_event::exec_event() +*/ - ****************************************************************************/ int Log_event::exec_event(struct st_relay_log_info* rli) { /* @@ -324,15 +314,15 @@ int Log_event::exec_event(struct st_relay_log_info* rli) - then it will be MyISAM on the slave - but as opt_using_transactions is true, the slave will believe he is transactional with the MyISAM table. And problems will come when one - does START SLAVE; STOP SLAVE; START SLAVE; (the slave will resume at BEGIN - whereas there has not been any rollback). This is the problem of + does START SLAVE; STOP SLAVE; START SLAVE; (the slave will resume at + BEGIN whereas there has not been any rollback). This is the problem of using opt_using_transactions instead of a finer "does the slave support _the_transactional_handler_used_on_the_master_". More generally, we'll have problems when a query mixes a transactional handler and MyISAM and STOP SLAVE is issued in the middle of the - "transaction". START SLAVE will resume at BEGIN while the MyISAM table has - already been updated. + "transaction". START SLAVE will resume at BEGIN while the MyISAM table + has already been updated. */ if ((thd->options & OPTION_BEGIN) && opt_using_transactions) @@ -346,24 +336,22 @@ int Log_event::exec_event(struct st_relay_log_info* rli) return 0; } -/***************************************************************************** +/* Log_event::pack_info() +*/ - ****************************************************************************/ void Log_event::pack_info(Protocol *protocol) { protocol->store("", &my_charset_bin); } -/***************************************************************************** - +/* Log_event::net_send() Only called by SHOW BINLOG EVENTS - - ****************************************************************************/ +*/ int Log_event::net_send(Protocol *protocol, const char* log_name, my_off_t pos) { @@ -384,11 +372,11 @@ int Log_event::net_send(Protocol *protocol, const char* log_name, my_off_t pos) } #endif /* HAVE_REPLICATION */ -/***************************************************************************** +/* Log_event::init_show_field_list() +*/ - ****************************************************************************/ void Log_event::init_show_field_list(List<Item>* field_list) { field_list->push_back(new Item_empty_string("Log_name", 20)); @@ -404,21 +392,20 @@ void Log_event::init_show_field_list(List<Item>* field_list) #endif // !MYSQL_CLIENT -/***************************************************************************** - +/* Log_event::write() +*/ - ****************************************************************************/ int Log_event::write(IO_CACHE* file) { return (write_header(file) || write_data(file)) ? -1 : 0; } -/***************************************************************************** +/* Log_event::write_header() +*/ - ****************************************************************************/ int Log_event::write_header(IO_CACHE* file) { char buf[LOG_EVENT_HEADER_LEN]; @@ -439,11 +426,10 @@ int Log_event::write_header(IO_CACHE* file) } -/***************************************************************************** - +/* Log_event::read_log_event() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT int Log_event::read_log_event(IO_CACHE* file, String* packet, pthread_mutex_t* log_lock) @@ -510,13 +496,13 @@ end: #define LOCK_MUTEX #endif -/***************************************************************************** - +/* Log_event::read_log_event() - Allocates memory--the caller is responsible for clean-up + NOTE: + Allocates memory; The caller is responsible for clean-up +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Log_event* Log_event::read_log_event(IO_CACHE* file, pthread_mutex_t* log_lock, @@ -588,11 +574,11 @@ data_len=%d,event_type=%d",error,data_len,head[EVENT_TYPE_OFFSET]); return res; } -/***************************************************************************** +/* Log_event::read_log_event() +*/ - ****************************************************************************/ Log_event* Log_event::read_log_event(const char* buf, int event_len, const char **error, bool old_format) { @@ -657,9 +643,18 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len, } if (!ev || !ev->is_valid()) { - *error= "Found invalid event in binary log"; delete ev; +#ifdef MYSQL_CLIENT + if (!force_opt) + { + *error= "Found invalid event in binary log"; + return 0; + } + ev= new Unknown_log_event(buf, old_format); +#else + *error= "Found invalid event in binary log"; return 0; +#endif } ev->cached_event_len = event_len; return ev; @@ -667,11 +662,10 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len, #ifdef MYSQL_CLIENT -/***************************************************************************** - +/* Log_event::print_header() +*/ - ****************************************************************************/ void Log_event::print_header(FILE* file) { char llbuff[22]; @@ -681,11 +675,10 @@ void Log_event::print_header(FILE* file) llstr(log_pos,llbuff)); } -/***************************************************************************** - +/* Log_event::print_timestamp() +*/ - ****************************************************************************/ void Log_event::print_timestamp(FILE* file, time_t* ts) { struct tm *res; @@ -709,11 +702,10 @@ void Log_event::print_timestamp(FILE* file, time_t* ts) #endif // MYSQL_CLIENT -/***************************************************************************** - +/* Log_event::set_log_pos() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT void Log_event::set_log_pos(MYSQL_LOG* log) { @@ -723,21 +715,16 @@ void Log_event::set_log_pos(MYSQL_LOG* log) #endif // !MYSQL_CLIENT - -/***************************************************************************** - ***************************************************************************** - - Query_log_event methods - - ***************************************************************************** - ****************************************************************************/ +/************************************************************************** + Query_log_event methods +**************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) -/***************************************************************************** +/* Query_log_event::pack_info() +*/ - ****************************************************************************/ void Query_log_event::pack_info(Protocol *protocol) { char *buf, *pos; @@ -761,21 +748,21 @@ void Query_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** +/* Query_log_event::write() +*/ - ****************************************************************************/ int Query_log_event::write(IO_CACHE* file) { return query ? Log_event::write(file) : -1; } -/***************************************************************************** +/* Query_log_event::write_data() +*/ - ****************************************************************************/ int Query_log_event::write_data(IO_CACHE* file) { if (!query) @@ -792,11 +779,11 @@ int Query_log_event::write_data(IO_CACHE* file) my_b_safe_write(file, (byte*) query, q_len)) ? -1 : 0; } -/***************************************************************************** +/* Query_log_event::Query_log_event() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length, bool using_trans) @@ -812,13 +799,12 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, exec_time = (ulong) (end_time - thd->start_time); db_len = (db) ? (uint32) strlen(db) : 0; } -#endif // MYSQL_CLIENT - -/***************************************************************************** +#endif /* MYSQL_CLIENT */ +/* Query_log_event::Query_log_event() +*/ - ****************************************************************************/ Query_log_event::Query_log_event(const char* buf, int event_len, bool old_format) :Log_event(buf, old_format),data_buf(0), query(NULL), db(NULL) @@ -854,11 +840,11 @@ Query_log_event::Query_log_event(const char* buf, int event_len, *((char*)query+q_len) = 0; } -/***************************************************************************** +/* Query_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Query_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -889,13 +875,13 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) my_fwrite(file, (byte*) query, q_len, MYF(MY_NABP | MY_WME)); fprintf(file, ";\n"); } -#endif // MYSQL_CLIENT +#endif /* MYSQL_CLIENT */ -/***************************************************************************** +/* Query_log_event::exec_event() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Query_log_event::exec_event(struct st_relay_log_info* rli) { @@ -996,19 +982,14 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) #endif -/***************************************************************************** - ***************************************************************************** - - Start_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Start_log_event methods +**************************************************************************/ +/* Start_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Start_log_event::pack_info(Protocol *protocol) { @@ -1021,11 +1002,11 @@ void Start_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** +/* Start_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Start_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -1035,17 +1016,16 @@ void Start_log_event::print(FILE* file, bool short_form, char* last_db) print_header(file); fprintf(file, "\tStart: binlog v %d, server v %s created ", binlog_version, server_version); - print_timestamp(file, (time_t*)&created); + print_timestamp(file, &created); fputc('\n', file); fflush(file); } -#endif // MYSQL_CLIENT - -/***************************************************************************** +#endif /* MYSQL_CLIENT */ +/* Start_log_event::Start_log_event() +*/ - ****************************************************************************/ Start_log_event::Start_log_event(const char* buf, bool old_format) :Log_event(buf, old_format) @@ -1057,11 +1037,11 @@ Start_log_event::Start_log_event(const char* buf, created = uint4korr(buf+ST_CREATED_OFFSET); } -/***************************************************************************** +/* Start_log_event::write_data() +*/ - ****************************************************************************/ int Start_log_event::write_data(IO_CACHE* file) { char buff[START_HEADER_LEN]; @@ -1071,8 +1051,7 @@ int Start_log_event::write_data(IO_CACHE* file) return (my_b_safe_write(file, (byte*) buff, sizeof(buff)) ? -1 : 0); } -/***************************************************************************** - +/* Start_log_event::exec_event() The master started @@ -1080,6 +1059,10 @@ int Start_log_event::write_data(IO_CACHE* file) IMPLEMENTATION - To handle the case where the master died without a stop event, we clean up all temporary tables + locks that we got. + However, we don't clean temporary tables if the master was 3.23 + (this is because a 3.23 master writes a Start_log_event at every + binlog rotation; if we were not careful we would remove temp tables + on the slave when FLUSH LOGS is issued on the master). TODO - Remove all active user locks @@ -1087,36 +1070,37 @@ int Start_log_event::write_data(IO_CACHE* file) in the middle while writing the transaction to the binary log. In this case we should stop the slave. - ****************************************************************************/ +*/ + #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Start_log_event::exec_event(struct st_relay_log_info* rli) { DBUG_ENTER("Start_log_event::exec_event"); - /* All temporary tables was deleted on the master */ - close_temporary_tables(thd); - /* - If we have old format, load_tmpdir is cleaned up by the I/O thread - */ + if (!rli->mi->old_format) + { + /* + If 4.0 master, all temporary tables have been deleted on the master; + if 3.23 master, this is far from sure. + */ + close_temporary_tables(thd); + /* + If we have old format, load_tmpdir is cleaned up by the I/O thread + */ cleanup_load_tmpdir(); + } DBUG_RETURN(Log_event::exec_event(rli)); } -#endif - - -/***************************************************************************** - ***************************************************************************** - - Load_log_event methods - - ***************************************************************************** - ****************************************************************************/ +#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */ -/***************************************************************************** +/************************************************************************** + Load_log_event methods +**************************************************************************/ +/* Load_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Load_log_event::pack_info(Protocol *protocol) { @@ -1224,13 +1208,13 @@ void Load_log_event::pack_info(Protocol *protocol) protocol->store(buf, pos-buf, &my_charset_bin); my_free(buf, MYF(MY_ALLOW_ZERO_PTR)); } -#endif +#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */ -/***************************************************************************** +/* Load_log_event::write_data_header() +*/ - ****************************************************************************/ int Load_log_event::write_data_header(IO_CACHE* file) { char buf[LOAD_HEADER_LEN]; @@ -1243,11 +1227,11 @@ int Load_log_event::write_data_header(IO_CACHE* file) return my_b_safe_write(file, (byte*)buf, LOAD_HEADER_LEN); } -/***************************************************************************** +/* Load_log_event::write_data_body() +*/ - ****************************************************************************/ int Load_log_event::write_data_body(IO_CACHE* file) { if (sql_ex.write_data(file)) @@ -1263,11 +1247,11 @@ int Load_log_event::write_data_body(IO_CACHE* file) my_b_safe_write(file, (byte*)fname, fname_len)); } -/***************************************************************************** +/* Load_log_event::Load_log_event() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex, const char *db_arg, const char *table_name_arg, @@ -1347,16 +1331,16 @@ Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex, field_lens = (const uchar*)field_lens_buf.ptr(); fields = fields_buf.ptr(); } -#endif // !MYSQL_CLIENT - -/***************************************************************************** +#endif /* !MYSQL_CLIENT */ +/* Load_log_event::Load_log_event() - The caller must do buf[event_len] = 0 before he starts using the - constructed event. + NOTE + The caller must do buf[event_len] = 0 before he starts using the + constructed event. +*/ - ****************************************************************************/ Load_log_event::Load_log_event(const char *buf, int event_len, bool old_format) :Log_event(buf, old_format),num_fields(0),fields(0), @@ -1368,11 +1352,11 @@ Load_log_event::Load_log_event(const char *buf, int event_len, copy_log_event(buf, event_len, old_format); } -/***************************************************************************** +/* Load_log_event::copy_log_event() +*/ - ****************************************************************************/ int Load_log_event::copy_log_event(const char *buf, ulong event_len, bool old_format) { @@ -1417,11 +1401,11 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, return 0; } -/***************************************************************************** +/* Load_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Load_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -1510,13 +1494,13 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db) fprintf(file, ";\n"); } -#endif /* #ifdef MYSQL_CLIENT */ +#endif /* MYSQL_CLIENT */ -/***************************************************************************** +/* Load_log_event::set_fields() +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT void Load_log_event::set_fields(List<Item> &field_list) { @@ -1653,12 +1637,11 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, close_thread_tables(thd); if (thd->query_error) { - int sql_error = thd->net.last_errno; + int sql_error= thd->net.last_errno; if (!sql_error) - sql_error = ER_UNKNOWN_ERROR; - + sql_error= ER_UNKNOWN_ERROR; slave_print_error(rli,sql_error, - "Slave: Error '%s' running load data infile ", + "Error '%s' running LOAD DATA INFILE", ER_SAFE(sql_error)); free_root(&thd->mem_root,0); return 1; @@ -1667,7 +1650,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, if (thd->is_fatal_error) { - sql_print_error("Slave: Fatal error running LOAD DATA INFILE "); + sql_print_error("Fatal error running LOAD DATA INFILE"); return 1; } @@ -1676,19 +1659,14 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, #endif -/***************************************************************************** - ***************************************************************************** - - Rotate_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Rotate_log_event methods +**************************************************************************/ +/* Rotate_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Rotate_log_event::pack_info(Protocol *protocol) { @@ -1707,11 +1685,11 @@ void Rotate_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** +/* Rotate_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Rotate_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -1732,11 +1710,11 @@ void Rotate_log_event::print(FILE* file, bool short_form, char* last_db) } #endif // MYSQL_CLIENT -/***************************************************************************** +/* Rotate_log_event::Rotate_log_event() +*/ - ****************************************************************************/ Rotate_log_event::Rotate_log_event(const char* buf, int event_len, bool old_format) :Log_event(buf, old_format),new_log_ident(NULL),alloced(0) @@ -1768,11 +1746,11 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len, alloced = 1; } -/***************************************************************************** +/* Rotate_log_event::write_data() +*/ - ****************************************************************************/ int Rotate_log_event::write_data(IO_CACHE* file) { char buf[ROTATE_HEADER_LEN]; @@ -1781,8 +1759,8 @@ int Rotate_log_event::write_data(IO_CACHE* file) my_b_safe_write(file, (byte*)new_log_ident, (uint) ident_len)); } -/***************************************************************************** +/* Rotate_log_event::exec_event() Got a rotate log even from the master @@ -1796,8 +1774,8 @@ int Rotate_log_event::write_data(IO_CACHE* file) RETURN VALUES 0 ok +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Rotate_log_event::exec_event(struct st_relay_log_info* rli) { @@ -1818,19 +1796,14 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli) #endif -/***************************************************************************** - ***************************************************************************** - - Intvar_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Intvar_log_event methods +**************************************************************************/ +/* Intvar_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Intvar_log_event::pack_info(Protocol *protocol) { @@ -1842,11 +1815,11 @@ void Intvar_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** +/* Intvar_log_event::Intvar_log_event() +*/ - ****************************************************************************/ Intvar_log_event::Intvar_log_event(const char* buf, bool old_format) :Log_event(buf, old_format) { @@ -1855,11 +1828,11 @@ Intvar_log_event::Intvar_log_event(const char* buf, bool old_format) val = uint8korr(buf+I_VAL_OFFSET); } -/***************************************************************************** +/* Intvar_log_event::get_var_type_name() +*/ - ****************************************************************************/ const char* Intvar_log_event::get_var_type_name() { switch(type) { @@ -1869,11 +1842,11 @@ const char* Intvar_log_event::get_var_type_name() } } -/***************************************************************************** +/* Intvar_log_event::write_data() +*/ - ****************************************************************************/ int Intvar_log_event::write_data(IO_CACHE* file) { char buf[9]; @@ -1882,11 +1855,11 @@ int Intvar_log_event::write_data(IO_CACHE* file) return my_b_safe_write(file, (byte*) buf, sizeof(buf)); } -/***************************************************************************** +/* Intvar_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Intvar_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -1912,13 +1885,13 @@ void Intvar_log_event::print(FILE* file, bool short_form, char* last_db) fprintf(file, "%s=%s;\n", msg, llstr(val,llbuff)); fflush(file); } -#endif // MYSQL_CLIENT +#endif -/***************************************************************************** +/* Intvar_log_event::exec_event() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT) int Intvar_log_event::exec_event(struct st_relay_log_info* rli) { @@ -1937,9 +1910,9 @@ int Intvar_log_event::exec_event(struct st_relay_log_info* rli) #endif -/**************************************************************************** +/************************************************************************** Rand_log_event methods -****************************************************************************/ +**************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Rand_log_event::pack_info(Protocol *protocol) @@ -1999,9 +1972,9 @@ int Rand_log_event::exec_event(struct st_relay_log_info* rli) #endif // !MYSQL_CLIENT -/*************************************************************************** +/************************************************************************** User_var_log_event methods -***************************************************************************/ +**************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void User_var_log_event::pack_info(Protocol* protocol) @@ -2129,11 +2102,10 @@ int User_var_log_event::write_data(IO_CACHE* file) } -/***************************************************************************** - +/* User_var_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void User_var_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -2176,11 +2148,11 @@ void User_var_log_event::print(FILE* file, bool short_form, char* last_db) } #endif -/***************************************************************************** +/* User_var_log_event::exec_event() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int User_var_log_event::exec_event(struct st_relay_log_info* rli) { @@ -2231,10 +2203,21 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli) #endif // !MYSQL_CLIENT -/**************************************************************************** +/************************************************************************** Slave_log_event methods -****************************************************************************/ +**************************************************************************/ + #ifdef HAVE_REPLICATION +#ifdef MYSQL_CLIENT +void Unknown_log_event::print(FILE* file, bool short_form, char* last_db) +{ + if (short_form) + return; + print_header(file); + fputc('\n', file); + fprintf(file, "# %s", "Unknown event\n"); +} +#endif #ifndef MYSQL_CLIENT void Slave_log_event::pack_info(Protocol *protocol) @@ -2367,19 +2350,14 @@ int Slave_log_event::exec_event(struct st_relay_log_info* rli) #endif // !MYSQL_CLIENT -/***************************************************************************** - ***************************************************************************** - - Stop_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Stop_log_event methods +**************************************************************************/ +/* Stop_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Stop_log_event::print(FILE* file, bool short_form, char* last_db) { @@ -2392,8 +2370,8 @@ void Stop_log_event::print(FILE* file, bool short_form, char* last_db) } #endif // MYSQL_CLIENT -/***************************************************************************** +/* Stop_log_event::exec_event() The master stopped. Clean up all temporary tables + locks that the @@ -2401,12 +2379,18 @@ void Stop_log_event::print(FILE* file, bool short_form, char* last_db) TODO - Remove all active user locks +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT int Stop_log_event::exec_event(struct st_relay_log_info* rli) { - // do not clean up immediately after rotate event + /* + do not clean up immediately after rotate event; + QQ: this should be a useless test: the only case when it is false is when + shutdown occurred just after FLUSH LOGS. It has nothing to do with Rotate? + By the way, immediately after a Rotate the I/O thread does not write + the Stop to the relay log, so we won't come here in that case. + */ if (rli->group_master_log_pos > BIN_LOG_HEADER_SIZE) { close_temporary_tables(thd); @@ -2423,23 +2407,18 @@ int Stop_log_event::exec_event(struct st_relay_log_info* rli) flush_relay_log_info(rli); return 0; } -#endif // !MYSQL_CLIENT +#endif /* !MYSQL_CLIENT */ #endif /* HAVE_REPLICATION */ -/***************************************************************************** - ***************************************************************************** - - Create_file_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Create_file_log_event methods +**************************************************************************/ +/* Create_file_log_event ctor +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Create_file_log_event:: Create_file_log_event(THD* thd_arg, sql_exchange* ex, @@ -2455,11 +2434,11 @@ Create_file_log_event(THD* thd_arg, sql_exchange* ex, } #endif // !MYSQL_CLIENT -/***************************************************************************** +/* Create_file_log_event::write_data_body() +*/ - ****************************************************************************/ int Create_file_log_event::write_data_body(IO_CACHE* file) { int res; @@ -2469,11 +2448,11 @@ int Create_file_log_event::write_data_body(IO_CACHE* file) my_b_safe_write(file, (byte*) block, block_len)); } -/***************************************************************************** +/* Create_file_log_event::write_data_header() +*/ - ****************************************************************************/ int Create_file_log_event::write_data_header(IO_CACHE* file) { int res; @@ -2484,11 +2463,11 @@ int Create_file_log_event::write_data_header(IO_CACHE* file) return my_b_safe_write(file, buf, CREATE_FILE_HEADER_LEN); } -/***************************************************************************** +/* Create_file_log_event::write_base() +*/ - ****************************************************************************/ int Create_file_log_event::write_base(IO_CACHE* file) { int res; @@ -2498,11 +2477,11 @@ int Create_file_log_event::write_base(IO_CACHE* file) return res; } -/***************************************************************************** +/* Create_file_log_event ctor +*/ - ****************************************************************************/ Create_file_log_event::Create_file_log_event(const char* buf, int len, bool old_format) :Load_log_event(buf,0,old_format),fake_base(0),block(0),inited_from_old(0) @@ -2529,11 +2508,11 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len, } } -/***************************************************************************** +/* Create_file_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Create_file_log_event::print(FILE* file, bool short_form, char* last_db, bool enable_local) @@ -2563,11 +2542,11 @@ void Create_file_log_event::print(FILE* file, bool short_form, } #endif // MYSQL_CLIENT -/***************************************************************************** +/* Create_file_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Create_file_log_event::pack_info(Protocol *protocol) { @@ -2586,11 +2565,11 @@ void Create_file_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** +/* Create_file_log_event::exec_event() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Create_file_log_event::exec_event(struct st_relay_log_info* rli) { @@ -2651,19 +2630,14 @@ err: #endif -/***************************************************************************** - ***************************************************************************** - - Append_block_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Append_block_log_event methods +**************************************************************************/ +/* Append_block_log_event ctor +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Append_block_log_event::Append_block_log_event(THD* thd_arg, char* block_arg, uint block_len_arg, @@ -2672,13 +2646,13 @@ Append_block_log_event::Append_block_log_event(THD* thd_arg, char* block_arg, block_len(block_len_arg), file_id(thd_arg->file_id) { } -#endif // !MYSQL_CLIENT +#endif -/***************************************************************************** +/* Append_block_log_event ctor +*/ - ****************************************************************************/ Append_block_log_event::Append_block_log_event(const char* buf, int len) :Log_event(buf, 0),block(0) { @@ -2689,11 +2663,11 @@ Append_block_log_event::Append_block_log_event(const char* buf, int len) block_len = len - APPEND_BLOCK_EVENT_OVERHEAD; } -/***************************************************************************** +/* Append_block_log_event::write_data() +*/ - ****************************************************************************/ int Append_block_log_event::write_data(IO_CACHE* file) { byte buf[APPEND_BLOCK_HEADER_LEN]; @@ -2702,11 +2676,11 @@ int Append_block_log_event::write_data(IO_CACHE* file) my_b_safe_write(file, (byte*) block, block_len)); } -/***************************************************************************** +/* Append_block_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Append_block_log_event::print(FILE* file, bool short_form, char* last_db) @@ -2720,11 +2694,11 @@ void Append_block_log_event::print(FILE* file, bool short_form, } #endif // MYSQL_CLIENT -/***************************************************************************** +/* Append_block_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Append_block_log_event::pack_info(Protocol *protocol) { @@ -2737,11 +2711,11 @@ void Append_block_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** +/* Append_block_log_event::exec_event() +*/ - ****************************************************************************/ #if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Append_block_log_event::exec_event(struct st_relay_log_info* rli) { @@ -2773,31 +2747,25 @@ err: #endif -/***************************************************************************** - ***************************************************************************** - - Delete_file_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Delete_file_log_event methods +**************************************************************************/ +/* Delete_file_log_event ctor +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Delete_file_log_event::Delete_file_log_event(THD *thd_arg, bool using_trans) :Log_event(thd_arg, 0, using_trans),file_id(thd_arg->file_id) { } -#endif // !MYSQL_CLIENT - -/***************************************************************************** +#endif +/* Delete_file_log_event ctor +*/ - ****************************************************************************/ Delete_file_log_event::Delete_file_log_event(const char* buf, int len) :Log_event(buf, 0),file_id(0) { @@ -2806,11 +2774,11 @@ Delete_file_log_event::Delete_file_log_event(const char* buf, int len) file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + AB_FILE_ID_OFFSET); } -/***************************************************************************** +/* Delete_file_log_event::write_data() +*/ - ****************************************************************************/ int Delete_file_log_event::write_data(IO_CACHE* file) { byte buf[DELETE_FILE_HEADER_LEN]; @@ -2818,11 +2786,11 @@ int Delete_file_log_event::write_data(IO_CACHE* file) return my_b_safe_write(file, buf, DELETE_FILE_HEADER_LEN); } -/***************************************************************************** +/* Delete_file_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Delete_file_log_event::print(FILE* file, bool short_form, char* last_db) @@ -2835,11 +2803,10 @@ void Delete_file_log_event::print(FILE* file, bool short_form, } #endif // MYSQL_CLIENT -/***************************************************************************** - +/* Delete_file_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Delete_file_log_event::pack_info(Protocol *protocol) { @@ -2850,11 +2817,10 @@ void Delete_file_log_event::pack_info(Protocol *protocol) } #endif -/***************************************************************************** - +/* Delete_file_log_event::exec_event() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Delete_file_log_event::exec_event(struct st_relay_log_info* rli) { @@ -2871,31 +2837,26 @@ int Delete_file_log_event::exec_event(struct st_relay_log_info* rli) #endif -/***************************************************************************** - ***************************************************************************** - - Execute_load_log_event methods - - ***************************************************************************** - ****************************************************************************/ - -/***************************************************************************** +/************************************************************************** + Execute_load_log_event methods +**************************************************************************/ +/* Execute_load_log_event ctor +*/ - ****************************************************************************/ #ifndef MYSQL_CLIENT Execute_load_log_event::Execute_load_log_event(THD *thd_arg, bool using_trans) :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id) { } -#endif // !MYSQL_CLIENT +#endif -/***************************************************************************** +/* Execute_load_log_event ctor +*/ - ****************************************************************************/ Execute_load_log_event::Execute_load_log_event(const char* buf, int len) :Log_event(buf, 0), file_id(0) { @@ -2904,11 +2865,11 @@ Execute_load_log_event::Execute_load_log_event(const char* buf, int len) file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + EL_FILE_ID_OFFSET); } -/***************************************************************************** +/* Execute_load_log_event::write_data() +*/ - ****************************************************************************/ int Execute_load_log_event::write_data(IO_CACHE* file) { byte buf[EXEC_LOAD_HEADER_LEN]; @@ -2916,11 +2877,11 @@ int Execute_load_log_event::write_data(IO_CACHE* file) return my_b_safe_write(file, buf, EXEC_LOAD_HEADER_LEN); } -/***************************************************************************** +/* Execute_load_log_event::print() +*/ - ****************************************************************************/ #ifdef MYSQL_CLIENT void Execute_load_log_event::print(FILE* file, bool short_form, char* last_db) @@ -2932,13 +2893,12 @@ void Execute_load_log_event::print(FILE* file, bool short_form, fprintf(file, "#Exec_load: file_id=%d\n", file_id); } -#endif // MYSQL_CLIENT - -/***************************************************************************** +#endif +/* Execute_load_log_event::pack_info() +*/ - ****************************************************************************/ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) void Execute_load_log_event::pack_info(Protocol *protocol) { @@ -2948,11 +2908,10 @@ void Execute_load_log_event::pack_info(Protocol *protocol) protocol->store(buf, (int32) length, &my_charset_bin); } -/***************************************************************************** +/* Execute_load_log_event::exec_event() - - ****************************************************************************/ +*/ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) { @@ -3017,22 +2976,17 @@ err: return error ? error : Log_event::exec_event(rli); } -#endif - - -/***************************************************************************** - ***************************************************************************** - - sql_ex_info methods +#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */ - ***************************************************************************** - ****************************************************************************/ -/***************************************************************************** +/************************************************************************** + sql_ex_info methods +**************************************************************************/ +/* sql_ex_info::write_data() +*/ - ****************************************************************************/ int sql_ex_info::write_data(IO_CACHE* file) { if (new_format()) @@ -3058,11 +3012,11 @@ int sql_ex_info::write_data(IO_CACHE* file) } } -/***************************************************************************** +/* sql_ex_info::init() +*/ - ****************************************************************************/ char* sql_ex_info::init(char* buf,char* buf_end,bool use_new_format) { cached_new_format = use_new_format; diff --git a/sql/log_event.h b/sql/log_event.h index 62b5873fabb..1d2fc741fa8 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -227,10 +227,11 @@ struct sql_ex_info enum Log_event_type { - START_EVENT = 1, QUERY_EVENT =2, STOP_EVENT=3, ROTATE_EVENT = 4, - INTVAR_EVENT=5, LOAD_EVENT=6, SLAVE_EVENT=7, CREATE_FILE_EVENT=8, - APPEND_BLOCK_EVENT=9, EXEC_LOAD_EVENT=10, DELETE_FILE_EVENT=11, - NEW_LOAD_EVENT=12, RAND_EVENT=13, USER_VAR_EVENT=14 + UNKNOWN_EVENT= 0, START_EVENT= 1, QUERY_EVENT= 2, STOP_EVENT= 3, + ROTATE_EVENT= 4, INTVAR_EVENT= 5, LOAD_EVENT=6, SLAVE_EVENT= 7, + CREATE_FILE_EVENT= 8, APPEND_BLOCK_EVENT= 9, EXEC_LOAD_EVENT= 10, + DELETE_FILE_EVENT= 11, NEW_LOAD_EVENT= 12, RAND_EVENT= 13, + USER_VAR_EVENT= 14 }; enum Int_event_type @@ -524,14 +525,14 @@ extern char server_version[SERVER_VERSION_LENGTH]; class Start_log_event: public Log_event { public: - uint32 created; + time_t created; uint16 binlog_version; char server_version[ST_SERVER_VER_LEN]; #ifndef MYSQL_CLIENT Start_log_event() :Log_event(), binlog_version(BINLOG_VERSION) { - created = (uint32) when; + created = (time_t) when; memcpy(server_version, ::server_version, ST_SERVER_VER_LEN); } #ifdef HAVE_REPLICATION @@ -887,4 +888,18 @@ public: int write_data(IO_CACHE* file); }; +#ifdef MYSQL_CLIENT +class Unknown_log_event: public Log_event +{ +public: + Unknown_log_event(const char* buf, bool old_format): + Log_event(buf, old_format) + {} + ~Unknown_log_event() {} + void print(FILE* file, bool short_form= 0, char* last_db= 0); + Log_event_type get_type_code() { return UNKNOWN_EVENT;} + bool is_valid() { return 1; } +}; +#endif + #endif /* _log_event_h */ diff --git a/sql/mini_client.cc b/sql/mini_client.cc deleted file mode 100644 index afcee5fbb02..00000000000 --- a/sql/mini_client.cc +++ /dev/null @@ -1,1422 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or - (at your option) any later version. - - 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 */ - -/* - mini MySQL client to be included into the server to do server to server - commincation by Sasha Pachev - - Note: all file-global symbols must begin with mc_ , even the static ones, just - in case we decide to make them external at some point -*/ - -#include <my_global.h> - -#ifdef HAVE_EXTERNAL_CLIENT - -/* my_pthread must be included early to be able to fix things */ -#if defined(THREAD) -#include <my_pthread.h> /* because of signal() */ -#endif -#include <thr_alarm.h> -#include <mysql_embed.h> -#include <mysql_com.h> -#include <violite.h> -#include <my_sys.h> -#include <mysys_err.h> -#include <m_string.h> -#include <m_ctype.h> -#include "mysql.h" -#include "mini_client.h" -#include "mysql_version.h" -#include "mysqld_error.h" -#include "errmsg.h" -#include <assert.h> - -#if defined( OS2) && defined(MYSQL_SERVER) -#undef ER -#define ER CER -#endif - -extern "C" { // Because of SCO 3.2V4.2 -#include <sys/stat.h> -#include <signal.h> -#ifdef HAVE_PWD_H -#include <pwd.h> -#endif -#if !defined(MSDOS) && !defined(__WIN__) -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#ifdef HAVE_SELECT_H -# include <select.h> -#endif -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif -#endif /*!defined(MSDOS) && !defined(__WIN__) */ -#ifdef HAVE_SYS_UN_H -# include <sys/un.h> -#endif -#ifndef INADDR_NONE -#define INADDR_NONE -1 -#endif -} - -static void mc_free_rows(MYSQL_DATA *cur); -void mc_end_server(MYSQL *mysql); -static int mc_sock_connect(File s, const struct sockaddr *name, uint namelen, uint to); -static void mc_free_old_query(MYSQL *mysql); -static int mc_send_file_to_server(MYSQL *mysql, const char *filename); -static int mc_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, - ulong *lengths); -static MYSQL_DATA *mc_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, - uint fields); - - - -#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \ - CLIENT_LOCAL_FILES | CLIENT_SECURE_CONNECTION) - - -#if defined(MSDOS) || defined(__WIN__) -#define perror(A) -#else -#include <errno.h> -#define SOCKET_ERROR -1 -#endif - -#ifdef __WIN__ -static my_bool is_NT(void) -{ - char *os=getenv("OS"); - return (os && !strcmp(os, "Windows_NT")) ? 1 : 0; -} -#endif - -extern ulong slave_net_timeout; - -/* -** Create a named pipe connection -*/ - -#ifdef __WIN__ - -HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, - char **arg_unix_socket) -{ - HANDLE hPipe=INVALID_HANDLE_VALUE; - char szPipeName [ 257 ]; - DWORD dwMode; - int i; - my_bool testing_named_pipes=0; - char *host= *arg_host, *unix_socket= *arg_unix_socket; - - if (!host || !strcmp(host,LOCAL_HOST)) - host=LOCAL_HOST_NAMEDPIPE; - - sprintf(szPipeName, "\\\\%s\\pipe\\%s", host, unix_socket); - DBUG_PRINT("info",("Server name: '%s'. Named Pipe: %s", - host, unix_socket)); - - for (i=0 ; i < 100 ; i++) /* Don't retry forever */ - { - if ((hPipe = CreateFile(szPipeName, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL )) != INVALID_HANDLE_VALUE) - break; - if (GetLastError() != ERROR_PIPE_BUSY) - { - net->last_errno=CR_NAMEDPIPEOPEN_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - /* wait for for an other instance */ - if (! WaitNamedPipe(szPipeName, connect_timeout*1000) ) - { - net->last_errno=CR_NAMEDPIPEWAIT_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - } - if (hPipe == INVALID_HANDLE_VALUE) - { - net->last_errno=CR_NAMEDPIPEOPEN_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - dwMode = PIPE_READMODE_BYTE | PIPE_WAIT; - if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) ) - { - CloseHandle( hPipe ); - net->last_errno=CR_NAMEDPIPESETSTATE_ERROR; - sprintf(net->last_error,ER(net->last_errno),host, unix_socket, - (ulong) GetLastError()); - return INVALID_HANDLE_VALUE; - } - *arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */ - return (hPipe); -} -#endif - - -/**************************************************************************** -** Init MySQL structure or allocate one -****************************************************************************/ - -MYSQL *mc_mysql_init(MYSQL *mysql) -{ - init_client_errs(); - if (!mysql) - { - if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) - return 0; - mysql->free_me=1; - mysql->net.vio = 0; - } - else - bzero((char*) (mysql),sizeof(*(mysql))); -#ifdef __WIN__ - mysql->options.connect_timeout=20; -#endif - mysql->net.read_timeout = slave_net_timeout; - return mysql; -} - -/************************************************************************** -** Shut down connection -**************************************************************************/ - -void -mc_end_server(MYSQL *mysql) -{ - DBUG_ENTER("mc_end_server"); - if (mysql->net.vio != 0) - { - DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio))); - vio_delete(mysql->net.vio); - mysql->net.vio= 0; /* Marker */ - } - net_end(&mysql->net); - mc_free_old_query(mysql); - DBUG_VOID_RETURN; -} - -static void mc_free_old_query(MYSQL *mysql) -{ - DBUG_ENTER("mc_free_old_query"); - if (mysql->fields) - free_root(&mysql->field_alloc,MYF(0)); - else - init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ - mysql->fields=0; - mysql->field_count=0; /* For API */ - DBUG_VOID_RETURN; -} - - -/**************************************************************************** -* A modified version of connect(). mc_sock_connect() allows you to specify -* a timeout value, in seconds, that we should wait until we -* derermine we can't connect to a particular host. If timeout is 0, -* mc_sock_connect() will behave exactly like connect(). -* -* Base version coded by Steve Bernacki, Jr. <steve@navinet.net> -*****************************************************************************/ - -static int mc_sock_connect(my_socket s, const struct sockaddr *name, - uint namelen, uint to) -{ -#if defined(__WIN__) || defined(OS2) - return connect(s, (struct sockaddr*) name, namelen); -#else - int flags, res, s_err; - SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint); - fd_set sfds; - struct timeval tv; - - /* If they passed us a timeout of zero, we should behave - * exactly like the normal connect() call does. - */ - - if (to == 0) - return connect(s, (struct sockaddr*) name, namelen); - - flags = fcntl(s, F_GETFL, 0); /* Set socket to not block */ -#ifdef O_NONBLOCK - fcntl(s, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ -#endif - - res = connect(s, (struct sockaddr*) name, namelen); - s_err = errno; /* Save the error... */ - fcntl(s, F_SETFL, flags); - if ((res != 0) && (s_err != EINPROGRESS)) - { - errno = s_err; /* Restore it */ - return(-1); - } - if (res == 0) /* Connected quickly! */ - return(0); - - /* Otherwise, our connection is "in progress." We can use - * the select() call to wait up to a specified period of time - * for the connection to suceed. If select() returns 0 - * (after waiting howevermany seconds), our socket never became - * writable (host is probably unreachable.) Otherwise, if - * select() returns 1, then one of two conditions exist: - * - * 1. An error occured. We use getsockopt() to check for this. - * 2. The connection was set up sucessfully: getsockopt() will - * return 0 as an error. - * - * Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> - * who posted this method of timing out a connect() in - * comp.unix.programmer on August 15th, 1997. - */ - - FD_ZERO(&sfds); - FD_SET(s, &sfds); - tv.tv_sec = (long) to; - tv.tv_usec = 0; -#ifdef HPUX10 - res = select(s+1, NULL, (int*) &sfds, NULL, &tv); -#else - res = select(s+1, NULL, &sfds, NULL, &tv); -#endif /* HPUX10 */ - if (res <= 0) /* Never became writable */ - return(-1); - - /* select() returned something more interesting than zero, let's - * see if we have any errors. If the next two statements pass, - * we've got an open socket! - */ - - s_err=0; - if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) - return(-1); - - if (s_err) - { // getsockopt() could succeed - errno = s_err; - return(-1); // but return an error... - } - return(0); /* It's all good! */ -#endif -} - -/***************************************************************************** -** read a packet from server. Give error message if socket was down -** or packet is an error message -*****************************************************************************/ - -ulong -mc_net_safe_read(MYSQL *mysql) -{ - NET *net= &mysql->net; - ulong len=0; - - if (net->vio != 0) - len=my_net_read(net); - - if (len == packet_error || len == 0) - { - DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", - vio_description(net->vio),len)); - if (socket_errno != SOCKET_EINTR) - { - mc_end_server(mysql); - if (net->last_errno != ER_NET_PACKET_TOO_LARGE) - { - net->last_errno=CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - } - else - strmov(net->last_error, "Packet too large - increase \ -max_allowed_packet on this server"); - } - return(packet_error); - } - if (net->read_pos[0] == 255) - { - if (len > 3) - { - char *pos=(char*) net->read_pos+1; - if (mysql->protocol_version > 9) - { /* New client protocol */ - net->last_errno=uint2korr(pos); - pos+=2; - len-=2; - if (!net->last_errno) - net->last_errno = CR_UNKNOWN_ERROR; - } - else - { - net->last_errno=CR_UNKNOWN_ERROR; - len--; - } - (void) strmake(net->last_error,(char*) pos, - min(len,sizeof(net->last_error)-1)); - } - else - { - net->last_errno=CR_UNKNOWN_ERROR; - (void) strmov(net->last_error,ER(net->last_errno)); - } - DBUG_PRINT("error",("Got error: %d (%s)", net->last_errno, - net->last_error)); - return(packet_error); - } - return len; -} - - -char *mc_mysql_error(MYSQL *mysql) -{ - return (mysql)->net.last_error; -} - -int mc_mysql_errno(MYSQL *mysql) -{ - return (mysql)->net.last_errno; -} - - -my_bool mc_mysql_reconnect(MYSQL *mysql) -{ - MYSQL tmp_mysql; - DBUG_ENTER("mc_mysql_reconnect"); - - if (!mysql->reconnect) - { - mysql->net.last_errno=CR_SERVER_GONE_ERROR; - strmov(mysql->net.last_error, ER(mysql->net.last_errno)); - DBUG_RETURN(1); - } - mc_mysql_init(&tmp_mysql); - tmp_mysql.options=mysql->options; - if (!mc_mysql_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, - mysql->db, mysql->port, mysql->unix_socket, - mysql->client_flag, mysql->net.read_timeout)) - { - mysql->net.last_errno= tmp_mysql.net.last_errno; - strmov(mysql->net.last_error, tmp_mysql.net.last_error); - DBUG_RETURN(1); - } - tmp_mysql.free_me=mysql->free_me; - mysql->free_me=0; - bzero((char*) &mysql->options,sizeof(&mysql->options)); - mc_mysql_close(mysql); - *mysql=tmp_mysql; - net_clear(&mysql->net); - mysql->affected_rows= ~(my_ulonglong) 0; - DBUG_RETURN(0); -} - - - -int -mc_simple_command(MYSQL *mysql,enum enum_server_command command, - const char *arg, uint length, my_bool skipp_check) -{ - NET *net= &mysql->net; - int result= -1; - - if (mysql->net.vio == 0) - { /* Do reconnect if possible */ - if (mc_mysql_reconnect(mysql)) - goto end; - } - if (mysql->status != MYSQL_STATUS_READY) - { - strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); - goto end; - } - - mysql->net.last_error[0]=0; - mysql->net.last_errno=0; - mysql->net.report_error=0; - mysql->info=0; - mysql->affected_rows= ~(my_ulonglong) 0; - net_clear(net); /* Clear receive buffer */ - if (!arg) - arg=""; - - if (net_write_command(net, (uchar) command, NullS, 0, arg, length)) - { - DBUG_PRINT("error",("Can't send command to server. Error: %d", - socket_errno)); - mc_end_server(mysql); - if (mc_mysql_reconnect(mysql)) - goto end; - if (net_write_command(net,(uchar) command, NullS, 0, arg, length)) - { - net->last_errno=CR_SERVER_GONE_ERROR; - strmov(net->last_error,ER(net->last_errno)); - goto end; - } - } - result=0; - if (!skipp_check) - result= ((mysql->packet_length=mc_net_safe_read(mysql)) == packet_error ? - -1 : 0); - end: - return result; -} - - -MYSQL * -mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, - const char *passwd, const char *db, - uint port, const char *unix_socket,uint client_flag, - uint net_read_timeout) -{ - char buff[NAME_LEN+USERNAME_LENGTH+100],*end,*host_info; - char password_hash[SCRAMBLE41_LENGTH]; - my_socket sock; - ulong ip_addr; - struct sockaddr_in sock_addr; - ulong pkt_length; - NET *net= &mysql->net; - thr_alarm_t alarmed; - ALARM alarm_buff; - ulong max_allowed_packet; - -#ifdef __WIN__ - HANDLE hPipe=INVALID_HANDLE_VALUE; -#endif -#ifdef HAVE_SYS_UN_H - struct sockaddr_un UNIXaddr; -#endif - DBUG_ENTER("mc_mysql_connect"); - DBUG_PRINT("enter",("host: %s db: %s user: %s connect_time_out: %u read_timeout: %u", - host ? host : "(Null)", - db ? db : "(Null)", - user ? user : "(Null)", - net_read_timeout, - (uint) slave_net_timeout)); - net->vio = 0; /* If something goes wrong */ - mysql->charset=default_charset_info; /* Set character set */ - if (!port) - port = MYSQL_PORT; /* Should always be set by mysqld */ - if (!unix_socket) - unix_socket=MYSQL_UNIX_ADDR; - - mysql->reconnect=1; /* Reconnect as default */ - mysql->server_status=SERVER_STATUS_AUTOCOMMIT; - if (!mysql->options.connect_timeout) - mysql->options.connect_timeout= net_read_timeout; - - /* - ** Grab a socket and connect it to the server - */ - -#if defined(HAVE_SYS_UN_H) - if ((!host || !strcmp(host,LOCAL_HOST)) && unix_socket) - { - host=LOCAL_HOST; - host_info=(char*) ER(CR_LOCALHOST_CONNECTION); - DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); - if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) - { - net->last_errno=CR_SOCKET_CREATE_ERROR; - sprintf(net->last_error,ER(net->last_errno),socket_errno); - goto error; - } - net->vio = vio_new(sock, VIO_TYPE_SOCKET, TRUE); - bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); - UNIXaddr.sun_family = AF_UNIX; - strmov(UNIXaddr.sun_path, unix_socket); - if (mc_sock_connect(sock, - my_reinterpret_cast(struct sockaddr *) (&UNIXaddr), - sizeof(UNIXaddr), - mysql->options.connect_timeout) <0) - { - DBUG_PRINT("error",("Got error %d on connect to local server", - socket_errno)); - net->last_errno=CR_CONNECTION_ERROR; - sprintf(net->last_error,ER(net->last_errno),unix_socket,socket_errno); - goto error; - } - } - else -#elif defined(__WIN__) - { - if ((unix_socket || - !host && is_NT() || - host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) || - mysql->options.named_pipe || !have_tcpip)) - { - sock=0; - if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout, - (char**) &host, (char**) &unix_socket)) == - INVALID_HANDLE_VALUE) - { - DBUG_PRINT("error", - ("host: '%s' socket: '%s' named_pipe: %d have_tcpip: %d", - host ? host : "<null>", - unix_socket ? unix_socket : "<null>", - (int) mysql->options.named_pipe, - (int) have_tcpip)); - if (mysql->options.named_pipe || - (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || - (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) - goto error; /* User only requested named pipes */ - /* Try also with TCP/IP */ - } - else - { - net->vio=vio_new_win32pipe(hPipe); - sprintf(host_info=buff, ER(CR_NAMEDPIPE_CONNECTION), host, - unix_socket); - } - } - } - if (hPipe == INVALID_HANDLE_VALUE) -#endif - { - unix_socket=0; /* This is not used */ - if (!host) - host=LOCAL_HOST; - sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host); - DBUG_PRINT("info",("Server name: '%s'. TCP sock: %d", host,port)); - thr_alarm_init(&alarmed); - thr_alarm(&alarmed, net_read_timeout, &alarm_buff); - sock = (my_socket) socket(AF_INET,SOCK_STREAM,0); - thr_end_alarm(&alarmed); - if (sock == SOCKET_ERROR) - { - net->last_errno=CR_IPSOCK_ERROR; - sprintf(net->last_error,ER(net->last_errno),socket_errno); - goto error; - } - net->vio = vio_new(sock,VIO_TYPE_TCPIP,FALSE); - bzero((char*) &sock_addr,sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - - /* - ** The server name may be a host name or IP address - */ - - if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) - { - memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); - } - else - { - int tmp_errno; - struct hostent tmp_hostent,*hp; - char buff2[GETHOSTBYNAME_BUFF_SIZE]; - hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), - &tmp_errno); - if (!hp) - { - net->last_errno=CR_UNKNOWN_HOST; - sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno); - my_gethostbyname_r_free(); - goto error; - } - memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length); - my_gethostbyname_r_free(); - } - sock_addr.sin_port = (ushort) htons((ushort) port); - if (mc_sock_connect(sock, - my_reinterpret_cast(struct sockaddr *) (&sock_addr), - sizeof(sock_addr), - mysql->options.connect_timeout) <0) - { - DBUG_PRINT("error",("Got error %d on connect to '%s'", - socket_errno,host)); - net->last_errno= CR_CONN_HOST_ERROR; - sprintf(net->last_error ,ER(CR_CONN_HOST_ERROR), host, socket_errno); - goto error; - } - } - - if (!net->vio || my_net_init(net, net->vio)) - { - vio_delete(net->vio); - net->vio = 0; - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - vio_keepalive(net->vio,TRUE); - net->read_timeout=slave_net_timeout; - /* Get version info */ - mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ - if (mysql->options.connect_timeout && - vio_poll_read(net->vio, mysql->options.connect_timeout)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - if ((pkt_length=mc_net_safe_read(mysql)) == packet_error) - goto error; - - /* Check if version of protocol matches current one */ - - mysql->protocol_version= net->read_pos[0]; - DBUG_DUMP("packet",(char*) net->read_pos,10); - DBUG_PRINT("info",("mysql protocol version %d, server=%d", - PROTOCOL_VERSION, mysql->protocol_version)); - if (mysql->protocol_version != PROTOCOL_VERSION && - mysql->protocol_version != PROTOCOL_VERSION-1) - { - net->last_errno= CR_VERSION_ERROR; - sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version, - PROTOCOL_VERSION); - goto error; - } - end=strend((char*) net->read_pos+1); - mysql->thread_id=uint4korr(end+1); - end+=5; - strmake(mysql->scramble_buff,end,8); - end+=9; - if (pkt_length >= (uint) (end+1 - (char*) net->read_pos)) - mysql->server_capabilities=uint2korr(end); - if (pkt_length >= (uint) (end+18 - (char*) net->read_pos)) - { - /* New protocol with 16 bytes to describe server characteristics */ - mysql->server_language=end[2]; - mysql->server_status=uint2korr(end+3); - } - - /* Save connection information */ - if (!user) user=""; - if (!passwd) passwd=""; - if (!my_multi_malloc(MYF(0), - &mysql->host_info, (uint) strlen(host_info)+1, - &mysql->host, (uint) strlen(host)+1, - &mysql->unix_socket, - unix_socket ? (uint) strlen(unix_socket)+1 : (uint) 1, - &mysql->server_version, - (uint) (end - (char*) net->read_pos), - NullS) || - !(mysql->user=my_strdup(user,MYF(0))) || - !(mysql->passwd=my_strdup(passwd,MYF(0)))) - { - strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY)); - goto error; - } - strmov(mysql->host_info,host_info); - strmov(mysql->host,host); - if (unix_socket) - strmov(mysql->unix_socket,unix_socket); - else - mysql->unix_socket=0; - strmov(mysql->server_version,(char*) net->read_pos+1); - mysql->port=port; - client_flag|=mysql->options.client_flag; - DBUG_PRINT("info",("Server version = '%s' capabilites: %ld", - mysql->server_version,mysql->server_capabilities)); - - /* Send client information for access check */ - client_flag|=CLIENT_CAPABILITIES; - -#ifdef HAVE_OPENSSL - if (mysql->options.ssl_key || mysql->options.ssl_cert || - mysql->options.ssl_ca || mysql->options.ssl_capath || - mysql->options.ssl_cipher) - mysql->options.use_ssl= 1; - if (mysql->options.use_ssl) - client_flag|=CLIENT_SSL; -#endif /* HAVE_OPENSSL */ - - if (db) - client_flag|=CLIENT_CONNECT_WITH_DB; -#ifdef HAVE_COMPRESS - if ((mysql->server_capabilities & CLIENT_COMPRESS) && - (mysql->options.compress || (client_flag & CLIENT_COMPRESS))) - client_flag|=CLIENT_COMPRESS; /* We will use compression */ - else -#endif - client_flag&= ~CLIENT_COMPRESS; - -#ifdef HAVE_OPENSSL - if ((mysql->server_capabilities & CLIENT_SSL) && - (mysql->options.use_ssl || (client_flag & CLIENT_SSL))) - { - DBUG_PRINT("info", ("Changing IO layer to SSL")); - client_flag |= CLIENT_SSL; - } - else - { - if (client_flag & CLIENT_SSL) - { - DBUG_PRINT("info", ("Leaving IO layer intact because server doesn't support SSL")); - } - client_flag &= ~CLIENT_SSL; - } -#endif /* HAVE_OPENSSL */ - - int2store(buff,client_flag); - mysql->client_flag=client_flag; - -#ifdef HAVE_OPENSSL - /* - Oops.. are we careful enough to not send ANY information without - encryption? - */ - if (client_flag & CLIENT_SSL) - { - if (my_net_write(net,buff,(uint) (2)) || net_flush(net)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - /* Do the SSL layering. */ - DBUG_PRINT("info", ("IO layer change in progress...")); - DBUG_PRINT("info", ("IO context %p",((struct st_VioSSLConnectorFd*)mysql->connector_fd)->ssl_context_)); - sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd),mysql->net.vio, (long)(mysql->options.connect_timeout)); - DBUG_PRINT("info", ("IO layer change done!")); - } -#endif /* HAVE_OPENSSL */ - max_allowed_packet=mysql->net.max_packet_size; - int3store(buff+2,max_allowed_packet); - - - if (user && user[0]) - strmake(buff+5,user,32); - else - { - user = getenv("USER"); - if (!user) user = "mysql"; - strmov((char*) buff+5, user ); - } - - DBUG_PRINT("info",("user: %s",buff+5)); - - /* - We always start with old type handshake the only difference is message sent - If server handles secure connection type we'll not send the real scramble - */ - if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) - { - if (passwd[0]) - { - /* Prepare false scramble */ - end=strend(buff+5)+1; - bfill(end, SCRAMBLE_LENGTH, 'x'); - end+=SCRAMBLE_LENGTH; - *end=0; - } - else /* For empty password*/ - { - end=strend(buff+5)+1; - *end=0; /* Store zero length scramble */ - } - } - else - { - /* - Real scramble is only sent to old servers. This can be blocked - by calling mysql_options(MYSQL *, MYSQL_SECURE_CONNECT, (char*) &1); - */ - end=scramble(strend(buff+5)+1, mysql->scramble_buff, passwd, - (my_bool) (mysql->protocol_version == 9)); - - } - /* Add database if needed */ - if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) - { - end=strmake(end+1,db,NAME_LEN); - mysql->db=my_strdup(db,MYF(MY_WME)); - db=0; - } - /* Write authentication package */ - if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - - /* We shall only query sever if it expect us to do so */ - - if ( (pkt_length=mc_net_safe_read(mysql)) == packet_error) - goto error; - - if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) - { - /* This should always happen with new server unless empty password */ - if (pkt_length==24 && net->read_pos[0]) - /* OK/Error message has zero as the first character */ - { - /* Old passwords will have zero at the first byte of hash */ - if (net->read_pos[0] != '*') - { - /* Build full password hash as it is required to decode scramble */ - password_hash_stage1(buff, passwd); - /* Store copy as we'll need it later */ - memcpy(password_hash,buff,SCRAMBLE41_LENGTH); - /* Finally hash complete password using hash we got from server */ - password_hash_stage2(password_hash,(char*)net->read_pos); - /* Decypt and store scramble 4 = hash for stage2 */ - password_crypt((char*)net->read_pos+4,mysql->scramble_buff,password_hash, - SCRAMBLE41_LENGTH); - mysql->scramble_buff[SCRAMBLE41_LENGTH]=0; - /* Encode scramble with password. Recycle buffer */ - password_crypt(mysql->scramble_buff,buff,buff,SCRAMBLE41_LENGTH); - } - else - { - /* Create password to decode scramble */ - create_key_from_old_password(passwd,password_hash); - /* Decypt and store scramble 4 = hash for stage2 */ - password_crypt((char*)net->read_pos+4,mysql->scramble_buff,password_hash, - SCRAMBLE41_LENGTH); - mysql->scramble_buff[SCRAMBLE41_LENGTH]=0; - /* Finally scramble decoded scramble with password */ - scramble(buff, mysql->scramble_buff, passwd,0); - } - /* Write second package of authentication */ - if (my_net_write(net,buff,SCRAMBLE41_LENGTH) || net_flush(net)) - { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); - goto error; - } - /* Read What server thinks about out new auth message report */ - if (mc_net_safe_read(mysql) == packet_error) - goto error; - } - } - - /* End of authentication part of handshake */ - - if (client_flag & CLIENT_COMPRESS) /* We will use compression */ - net->compress=1; - DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); - DBUG_RETURN(mysql); - -error: - DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error)); - { - /* Free alloced memory */ - my_bool free_me=mysql->free_me; - mc_end_server(mysql); - mysql->free_me=0; - mc_mysql_close(mysql); - mysql->free_me=free_me; - } - DBUG_RETURN(0); -} - - -#ifdef HAVE_OPENSSL -/* -************************************************************************** -** Free strings in the SSL structure and clear 'use_ssl' flag. -** NB! Errors are not reported until you do mysql_real_connect. -************************************************************************** -*/ -int -mysql_ssl_clear(MYSQL *mysql) -{ - my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.ssl_key = 0; - mysql->options.ssl_cert = 0; - mysql->options.ssl_ca = 0; - mysql->options.ssl_capath = 0; - mysql->options.ssl_cipher= 0; - mysql->options.use_ssl = FALSE; - my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR)); - mysql->connector_fd = 0; - return 0; -} -#endif /* HAVE_OPENSSL */ - -/************************************************************************* -** Send a QUIT to the server and close the connection -** If handle is alloced by mysql connect free it. -*************************************************************************/ - -void -mc_mysql_close(MYSQL *mysql) -{ - DBUG_ENTER("mysql_close"); - if (mysql) /* Some simple safety */ - { - if (mysql->net.vio != 0) - { - mc_free_old_query(mysql); - mysql->status=MYSQL_STATUS_READY; /* Force command */ - mysql->reconnect=0; - mc_simple_command(mysql,COM_QUIT,NullS,0,1); - mc_end_server(mysql); - } - my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); - /* Clear pointers for better safety */ - mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; - bzero((char*) &mysql->options,sizeof(mysql->options)); -#ifdef HAVE_OPENSSL - mysql_ssl_clear(mysql); -#endif /* HAVE_OPENSSL */ - if (mysql->free_me) - my_free((gptr) mysql,MYF(0)); - } - DBUG_VOID_RETURN; -} - -void mc_mysql_free_result(MYSQL_RES *result) -{ - DBUG_ENTER("mc_mysql_free_result"); - DBUG_PRINT("enter",("mysql_res: %lx",result)); - if (result) - { - if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) - { - DBUG_PRINT("warning",("Not all rows in set were read; Ignoring rows")); - for (;;) - { - ulong pkt_len; - if ((pkt_len=mc_net_safe_read(result->handle)) == packet_error) - break; - if (pkt_len == 1 && result->handle->net.read_pos[0] == 254) - break; /* End of data */ - } - result->handle->status=MYSQL_STATUS_READY; - } - mc_free_rows(result->data); - if (result->fields) - free_root(&result->field_alloc,MYF(0)); - if (result->row) - my_free((gptr) result->row,MYF(0)); - my_free((gptr) result,MYF(0)); - } - DBUG_VOID_RETURN; -} - -static void mc_free_rows(MYSQL_DATA *cur) -{ - if (cur) - { - free_root(&cur->alloc,MYF(0)); - my_free((gptr) cur,MYF(0)); - } -} - -static MYSQL_FIELD * -mc_unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, - my_bool default_value, my_bool long_flag_protocol) -{ - MYSQL_ROWS *row; - MYSQL_FIELD *field,*result; - DBUG_ENTER("unpack_fields"); - - field=result=(MYSQL_FIELD*) alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); - if (!result) - DBUG_RETURN(0); - - for (row=data->data; row ; row = row->next,field++) - { - field->table= strdup_root(alloc,(char*) row->data[0]); - field->name= strdup_root(alloc,(char*) row->data[1]); - field->length= (uint) uint3korr(row->data[2]); - field->type= (enum enum_field_types) (uchar) row->data[3][0]; - if (long_flag_protocol) - { - field->flags= uint2korr(row->data[4]); - field->decimals=(uint) (uchar) row->data[4][2]; - } - else - { - field->flags= (uint) (uchar) row->data[4][0]; - field->decimals=(uint) (uchar) row->data[4][1]; - } - if (INTERNAL_NUM_FIELD(field)) - field->flags|= NUM_FLAG; - if (default_value && row->data[5]) - field->def=strdup_root(alloc,(char*) row->data[5]); - else - field->def=0; - field->max_length= 0; - } - mc_free_rows(data); /* Free old data */ - DBUG_RETURN(result); -} - -int mc_mysql_send_query(MYSQL* mysql, const char* query, uint length) -{ - return mc_simple_command(mysql, COM_QUERY, query, length, 1); -} - - -int mc_mysql_read_query_result(MYSQL *mysql) -{ - uchar *pos; - ulong field_count; - MYSQL_DATA *fields; - ulong length; - DBUG_ENTER("mc_mysql_read_query_result"); - - if ((length = mc_net_safe_read(mysql)) == packet_error) - DBUG_RETURN(-1); - mc_free_old_query(mysql); /* Free old result */ -get_info: - pos=(uchar*) mysql->net.read_pos; - if ((field_count= net_field_length(&pos)) == 0) - { - mysql->affected_rows= net_field_length_ll(&pos); - mysql->insert_id= net_field_length_ll(&pos); - if (mysql->server_capabilities & CLIENT_TRANSACTIONS) - { - mysql->server_status=uint2korr(pos); pos+=2; - } - if (pos < mysql->net.read_pos+length && net_field_length(&pos)) - mysql->info=(char*) pos; - DBUG_RETURN(0); - } - if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ - { - int error=mc_send_file_to_server(mysql,(char*) pos); - if ((length=mc_net_safe_read(mysql)) == packet_error || error) - DBUG_RETURN(-1); - goto get_info; /* Get info packet */ - } - if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) - mysql->server_status|= SERVER_STATUS_IN_TRANS; - - mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */ - if (!(fields=mc_read_rows(mysql,(MYSQL_FIELD*) 0,5))) - DBUG_RETURN(-1); - if (!(mysql->fields=mc_unpack_fields(fields,&mysql->field_alloc, - (uint) field_count,0, - (my_bool) test(mysql->server_capabilities & - CLIENT_LONG_FLAG)))) - DBUG_RETURN(-1); - mysql->status=MYSQL_STATUS_GET_RESULT; - mysql->field_count=field_count; - DBUG_RETURN(0); -} - - -int mc_mysql_query(MYSQL *mysql, const char *query, uint length) -{ - DBUG_ENTER("mc_mysql_query"); - DBUG_PRINT("enter",("handle: %lx",mysql)); - DBUG_PRINT("query",("Query = \"%s\"",query)); - DBUG_ASSERT(length == strlen(query)); - if (mc_simple_command(mysql,COM_QUERY,query,length,1)) - DBUG_RETURN(-1); - DBUG_RETURN(mc_mysql_read_query_result(mysql)); -} - - -static int mc_send_file_to_server(MYSQL *mysql, const char *filename) -{ - int fd, readcount, result= -1; - uint packet_length=MY_ALIGN(mysql->net.max_packet-16,IO_SIZE); - char *buf, tmp_name[FN_REFLEN]; - DBUG_ENTER("send_file_to_server"); - - if (!(buf=my_malloc(packet_length,MYF(0)))) - { - strmov(mysql->net.last_error, ER(mysql->net.last_errno=CR_OUT_OF_MEMORY)); - DBUG_RETURN(-1); - } - - fn_format(tmp_name,filename,"","",4); /* Convert to client format */ - if ((fd = my_open(tmp_name,O_RDONLY, MYF(0))) < 0) - { - my_net_write(&mysql->net,"",0); // Server needs one packet - net_flush(&mysql->net); - mysql->net.last_errno=EE_FILENOTFOUND; - my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1, - EE(mysql->net.last_errno),tmp_name, errno); - goto err; - } - - while ((readcount = (int) my_read(fd,(byte*) buf,packet_length,MYF(0))) > 0) - { - if (my_net_write(&mysql->net,buf,readcount)) - { - DBUG_PRINT("error",("Lost connection to MySQL server during LOAD DATA of local file")); - mysql->net.last_errno=CR_SERVER_LOST; - strmov(mysql->net.last_error,ER(mysql->net.last_errno)); - goto err; - } - } - /* Send empty packet to mark end of file */ - if (my_net_write(&mysql->net,"",0) || net_flush(&mysql->net)) - { - mysql->net.last_errno=CR_SERVER_LOST; - sprintf(mysql->net.last_error,ER(mysql->net.last_errno),errno); - goto err; - } - if (readcount < 0) - { - mysql->net.last_errno=EE_READ; /* the errmsg for not entire file read */ - my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1, - tmp_name,errno); - goto err; - } - result=0; // Ok - -err: - if (fd >= 0) - (void) my_close(fd,MYF(0)); - my_free(buf,MYF(0)); - DBUG_RETURN(result); -} - -/* Read all rows (fields or data) from server */ - -static MYSQL_DATA *mc_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, - uint fields) -{ - uint field; - ulong pkt_len; - ulong len; - uchar *cp; - char *to; - MYSQL_DATA *result; - MYSQL_ROWS **prev_ptr,*cur; - NET *net = &mysql->net; - DBUG_ENTER("mc_read_rows"); - - if ((pkt_len=mc_net_safe_read(mysql)) == packet_error) - DBUG_RETURN(0); - if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), - MYF(MY_ZEROFILL)))) - { - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); - DBUG_RETURN(0); - } - init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ - result->alloc.min_malloc=sizeof(MYSQL_ROWS); - prev_ptr= &result->data; - result->rows=0; - result->fields=fields; - - while (*(cp=net->read_pos) != 254 || pkt_len != 1) - { - result->rows++; - if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, - sizeof(MYSQL_ROWS))) || - !(cur->data= ((MYSQL_ROW) - alloc_root(&result->alloc, - (fields+1)*sizeof(char *)+pkt_len)))) - { - mc_free_rows(result); - net->last_errno=CR_OUT_OF_MEMORY; - strmov(net->last_error,ER(net->last_errno)); - DBUG_RETURN(0); - } - *prev_ptr=cur; - prev_ptr= &cur->next; - to= (char*) (cur->data+fields+1); - for (field=0 ; field < fields ; field++) - { - if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH) - { /* null field */ - cur->data[field] = 0; - } - else - { - cur->data[field] = to; - memcpy(to,(char*) cp,len); to[len]=0; - to+=len+1; - cp+=len; - if (mysql_fields) - { - if (mysql_fields[field].max_length < len) - mysql_fields[field].max_length=len; - } - } - } - cur->data[field]=to; /* End of last field */ - if ((pkt_len=mc_net_safe_read(mysql)) == packet_error) - { - mc_free_rows(result); - DBUG_RETURN(0); - } - } - *prev_ptr=0; /* last pointer is null */ - DBUG_PRINT("exit",("Got %d rows",result->rows)); - DBUG_RETURN(result); -} - - -/* -** Read one row. Uses packet buffer as storage for fields. -** When next packet is read, the previous field values are destroyed -*/ - - -static int mc_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, - ulong *lengths) -{ - uint field; - ulong pkt_len,len; - uchar *pos; - uchar *prev_pos; - - if ((pkt_len=mc_net_safe_read(mysql)) == packet_error) - return -1; - if (pkt_len == 1 && mysql->net.read_pos[0] == 254) - return 1; /* End of data */ - prev_pos= 0; /* allowed to write at packet[-1] */ - pos=mysql->net.read_pos; - for (field=0 ; field < fields ; field++) - { - if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH) - { /* null field */ - row[field] = 0; - *lengths++=0; - } - else - { - row[field] = (char*) pos; - pos+=len; - *lengths++=len; - } - if (prev_pos) - *prev_pos=0; /* Terminate prev field */ - prev_pos= pos; - } - row[field]=(char*) prev_pos+1; /* End of last field */ - *prev_pos=0; /* Terminate last field */ - return 0; -} - -my_ulonglong mc_mysql_num_rows(MYSQL_RES *res) -{ - return res->row_count; -} - -unsigned int mc_mysql_num_fields(MYSQL_RES *res) -{ - return res->field_count; -} - -void mc_mysql_data_seek(MYSQL_RES *result, my_ulonglong row) -{ - MYSQL_ROWS *tmp=0; - DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row)); - if (result->data) - for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; - result->current_row=0; - result->data_cursor = tmp; -} - -MYSQL_ROW STDCALL mc_mysql_fetch_row(MYSQL_RES *res) -{ - DBUG_ENTER("mc_mysql_fetch_row"); - if (!res->data) - { /* Unbufferred fetch */ - if (!res->eof) - { - if (!(mc_read_one_row(res->handle,res->field_count,res->row, - res->lengths))) - { - res->row_count++; - DBUG_RETURN(res->current_row=res->row); - } - else - { - DBUG_PRINT("info",("end of data")); - res->eof=1; - res->handle->status=MYSQL_STATUS_READY; - } - } - DBUG_RETURN((MYSQL_ROW) NULL); - } - { - MYSQL_ROW tmp; - if (!res->data_cursor) - { - DBUG_PRINT("info",("end of data")); - DBUG_RETURN(res->current_row=(MYSQL_ROW) NULL); - } - tmp = res->data_cursor->data; - res->data_cursor = res->data_cursor->next; - DBUG_RETURN(res->current_row=tmp); - } -} - -int mc_mysql_select_db(MYSQL *mysql, const char *db) -{ - int error; - DBUG_ENTER("mysql_select_db"); - DBUG_PRINT("enter",("db: '%s'",db)); - - if ((error=mc_simple_command(mysql,COM_INIT_DB,db,(uint) strlen(db),0))) - DBUG_RETURN(error); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); - mysql->db=my_strdup(db,MYF(MY_WME)); - DBUG_RETURN(0); -} - - -MYSQL_RES *mc_mysql_store_result(MYSQL *mysql) -{ - MYSQL_RES *result; - DBUG_ENTER("mysql_store_result"); - - if (!mysql->fields) - DBUG_RETURN(0); - if (mysql->status != MYSQL_STATUS_GET_RESULT) - { - strmov(mysql->net.last_error, - ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); - DBUG_RETURN(0); - } - mysql->status=MYSQL_STATUS_READY; /* server is ready */ - if (!(result=(MYSQL_RES*) my_malloc(sizeof(MYSQL_RES)+ - sizeof(ulong)*mysql->field_count, - MYF(MY_ZEROFILL)))) - { - mysql->net.last_errno=CR_OUT_OF_MEMORY; - strmov(mysql->net.last_error, ER(mysql->net.last_errno)); - DBUG_RETURN(0); - } - result->eof=1; /* Marker for buffered */ - result->lengths=(ulong*) (result+1); - if (!(result->data=mc_read_rows(mysql,mysql->fields,mysql->field_count))) - { - my_free((gptr) result,MYF(0)); - DBUG_RETURN(0); - } - mysql->affected_rows= result->row_count= result->data->rows; - result->data_cursor= result->data->data; - result->fields= mysql->fields; - result->field_alloc= mysql->field_alloc; - result->field_count= mysql->field_count; - result->current_field=0; - result->current_row=0; /* Must do a fetch first */ - mysql->fields=0; /* fields is now in result */ - DBUG_RETURN(result); /* Data fetched */ -} - -#endif /* HAVE_EXTERNAL_CLIENT */ diff --git a/sql/mini_client.h b/sql/mini_client.h deleted file mode 100644 index 24c13646170..00000000000 --- a/sql/mini_client.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or - (at your option) any later version. - - 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 */ - -#ifndef _MINI_CLIENT_H -#define _MINI_CLIENT_H - - -MYSQL* mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, - const char *passwd, const char *db, - uint port, const char *unix_socket,uint client_flag, - uint net_read_timeout); -int mc_simple_command(MYSQL *mysql,enum enum_server_command command, - const char *arg, uint length, my_bool skipp_check); -void mc_mysql_close(MYSQL *mysql); -MYSQL *mc_mysql_init(MYSQL *mysql); -void mc_mysql_debug(const char *debug); -ulong mc_net_safe_read(MYSQL *mysql); -char *mc_mysql_error(MYSQL *mysql); -int mc_mysql_errno(MYSQL *mysql); -my_bool mc_mysql_reconnect(MYSQL* mysql); -int mc_mysql_send_query(MYSQL* mysql, const char* query, uint length); -int mc_mysql_read_query_result(MYSQL *mysql); -int mc_mysql_query(MYSQL *mysql, const char *query, uint length); -MYSQL_RES * mc_mysql_store_result(MYSQL *mysql); -void mc_mysql_free_result(MYSQL_RES *result); -void mc_mysql_data_seek(MYSQL_RES *result, my_ulonglong row); -my_ulonglong mc_mysql_num_rows(MYSQL_RES *res); -unsigned int mc_mysql_num_fields(MYSQL_RES *res); -MYSQL_ROW STDCALL mc_mysql_fetch_row(MYSQL_RES *res); -int mc_mysql_select_db(MYSQL *mysql, const char *db); -void mc_end_server(MYSQL *mysql); - -#endif diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index ea6e544a1fd..a59f1d4b81a 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -45,6 +45,10 @@ char *sql_strdup(const char *str); char *sql_strmake(const char *str,uint len); gptr sql_memdup(const void * ptr,unsigned size); void sql_element_free(void *ptr); +char *sql_strmake_with_convert(const char *str, uint32 arg_length, + CHARSET_INFO *from_cs, + uint32 max_res_length, + CHARSET_INFO *to_cs, uint32 *result_length); void kill_one_thread(THD *thd, ulong id); bool net_request_file(NET* net, const char* fname); char* query_table_status(THD *thd,const char *db,const char *table_name); @@ -368,14 +372,19 @@ void mysql_execute_command(THD *thd); bool do_command(THD *thd); bool dispatch_command(enum enum_server_command command, THD *thd, char* packet, uint packet_length); +#ifndef EMBEDDED_LIBRARY bool check_stack_overrun(THD *thd,char *dummy); +#else +#define check_stack_overrun(A, B) 0 +#endif + bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog); void table_cache_init(void); void table_cache_free(void); uint cached_tables(void); void kill_mysql(void); -void close_connection(NET *net,uint errcode=0,bool lock=1); +void close_connection(THD *thd, uint errcode, bool lock); bool check_access(THD *thd, ulong access, const char *db=0, ulong *save_priv=0, bool no_grant=0, bool no_errors=0); bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables, @@ -624,8 +633,8 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table, bool return_if_owned_by_thd=0); bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables); void copy_field_from_tmp_record(Field *field,int offset); -int fill_record(List<Item> &fields,List<Item> &values); -int fill_record(Field **field,List<Item> &values); +int fill_record(List<Item> &fields,List<Item> &values, bool ignore_errors); +int fill_record(Field **field,List<Item> &values, bool ignore_errors); OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild); /* sql_calc.cc */ @@ -678,11 +687,11 @@ bool open_log(MYSQL_LOG *log, const char *hostname, extern time_t start_time; extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH], - mysql_real_data_home[], *charsets_list, *opt_mysql_tmpdir; + mysql_real_data_home[], *opt_mysql_tmpdir; #define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list)) extern MY_TMPDIR mysql_tmpdir_list; extern const char *command_name[]; -extern const char *first_keyword, *localhost, *delayed_user; +extern const char *first_keyword, *localhost, *delayed_user, *binary_keyword; extern const char **errmesg; /* Error messages */ extern const char *myisam_recover_options_str; extern uchar *days_in_month; @@ -690,7 +699,6 @@ extern char language[LIBLEN],reg_ext[FN_EXTLEN]; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file; extern char log_error_file[FN_REFLEN]; -extern char blob_newline; extern double log_10[32]; extern ulonglong keybuff_size; extern ulong refresh_version,flush_version, thread_id,query_id,opened_tables; @@ -736,11 +744,11 @@ extern uint volatile thread_count, thread_running, global_read_lock; extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types; extern my_bool opt_safe_show_db, opt_local_infile, lower_case_table_names; extern my_bool opt_slave_compressed_protocol, use_temp_pool; +extern my_bool opt_readonly; extern my_bool opt_enable_named_pipe; extern my_bool opt_old_passwords, use_old_passwords; extern char *shared_memory_base_name; extern bool opt_enable_shared_memory; -extern char f_fyllchar; extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log; extern FILE *bootstrap_file; @@ -869,6 +877,7 @@ bool check_db_name(char *db); bool check_column_name(const char *name); bool check_table_name(const char *name, uint length); char *get_field(MEM_ROOT *mem, Field *field); +bool get_field(MEM_ROOT *mem, Field *field, class String *res); int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr); /* from hostname.cc */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f73bd6721f0..7011f6dcd36 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -46,7 +46,7 @@ #define MAIN_THD #define SIGNAL_THD -#ifdef PURIFY +#ifdef HAVE_purify #define IF_PURIFY(A,B) (A) #else #define IF_PURIFY(A,B) (B) @@ -116,7 +116,7 @@ int deny_severity = LOG_WARNING; #define my_fromhost(A) fromhost() #define my_hosts_access(A) hosts_access() #define my_eval_client(A) eval_client() -#endif +#endif /* __STDC__ */ #endif /* HAVE_LIBWRAP */ #ifdef HAVE_SYS_MMAN_H @@ -128,8 +128,8 @@ int deny_severity = LOG_WARNING; #include <library.h> #include <monitor.h> -event_handle_t eh; -Report_t ref; +static event_handle_t eh; +static Report_t ref; #endif /* __NETWARE__ */ #ifdef _AIX41 @@ -169,6 +169,7 @@ inline void reset_floating_point_exceptions() #else #define THR_KILL_SIGNAL SIGUSR2 // Can't use this with LinuxThreads #endif +#define MYSQL_KILL_SIGNAL SIGTERM #ifdef HAVE_GLIBC2_STYLE_GETHOSTBYNAME_R #include <sys/types.h> @@ -183,229 +184,95 @@ inline void reset_floating_point_exceptions() extern "C" int gethostname(char *name, int namelen); #endif -#define MYSQL_KILL_SIGNAL SIGTERM - -#ifndef DBUG_OFF -static const char* default_dbug_option=IF_WIN("d:t:i:O,\\mysqld.trace", - "d:t:i:o,/tmp/mysqld.trace"); -#endif - -#ifdef __NT__ -static char szPipeName [ 257 ]; -static SECURITY_ATTRIBUTES saPipeSecurity; -static SECURITY_DESCRIPTOR sdPipeDescriptor; -static HANDLE hPipe = INVALID_HANDLE_VALUE; -#endif -#ifdef __WIN__ -static pthread_cond_t COND_handler_count; -static uint handler_count; -static bool start_mode=0, use_opt_args; -static int opt_argc; -static char **opt_argv; -#endif /* Set prefix for windows binary */ #ifdef __WIN__ #undef MYSQL_SERVER_SUFFIX #ifdef __NT__ -#if defined(HAVE_INNOBASE_DB) || defined(HAVE_BERKELEY_DB) +#if defined(HAVE_BERKELEY_DB) #define MYSQL_SERVER_SUFFIX "-max-nt" #else #define MYSQL_SERVER_SUFFIX "-nt" #endif /* ...DB */ -#elif defined(HAVE_INNOBASE_DB) || defined(HAVE_BERKELEY_DB) +#elif defined(HAVE_BERKELEY_DB) #define MYSQL_SERVER_SUFFIX "-max" #else #define MYSQL_SERVER_SUFFIX "" #endif /* __NT__ */ #endif /* __WIN__ */ -#ifdef HAVE_BERKELEY_DB -SHOW_COMP_OPTION have_berkeley_db=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_berkeley_db=SHOW_OPTION_NO; -#endif -#ifdef HAVE_INNOBASE_DB -SHOW_COMP_OPTION have_innodb=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_innodb=SHOW_OPTION_NO; -#endif -#ifdef HAVE_ISAM -SHOW_COMP_OPTION have_isam=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_isam=SHOW_OPTION_NO; -#endif -#ifdef USE_RAID -SHOW_COMP_OPTION have_raid=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_raid=SHOW_OPTION_NO; -#endif -#ifdef HAVE_OPENSSL -SHOW_COMP_OPTION have_openssl=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_openssl=SHOW_OPTION_NO; -#endif -#ifdef HAVE_BROKEN_REALPATH -SHOW_COMP_OPTION have_symlink=SHOW_OPTION_NO; -#else -SHOW_COMP_OPTION have_symlink=SHOW_OPTION_YES; -#endif -#ifdef HAVE_QUERY_CACHE -SHOW_COMP_OPTION have_query_cache=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_query_cache=SHOW_OPTION_NO; -#endif -#ifdef HAVE_CRYPT -SHOW_COMP_OPTION have_crypt=SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_crypt=SHOW_OPTION_NO; -#endif -#ifdef HAVE_COMPRESS -SHOW_COMP_OPTION have_compress= SHOW_OPTION_YES; -#else -SHOW_COMP_OPTION have_compress= SHOW_OPTION_NO; -#endif -const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"}; +/* Constants */ -bool opt_large_files= sizeof(my_off_t) > 4; +const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"}; +const char *sql_mode_names[] = +{ + "REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", + "SERIALIZE", "ONLY_FULL_GROUP_BY", "NO_UNSIGNED_SUBTRACTION", + "POSTGRESQL", "ORACLE", "MSSQL", "DB2", "SAPDB", "NO_KEY_OPTIONS", + "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", + NullS +}; +TYPELIB sql_mode_typelib= { array_elements(sql_mode_names)-1,"", + sql_mode_names }; +const char *first_keyword= "first", *binary_keyword= "BINARY"; +const char *localhost= "localhost", *delayed_user= "DELAYED"; #if SIZEOF_OFF_T > 4 && defined(BIG_TABLES) #define GET_HA_ROWS GET_ULL #else #define GET_HA_ROWS GET_ULONG #endif -#ifdef HAVE_LIBWRAP -char *libwrapName= NULL; -#endif +bool opt_large_files= sizeof(my_off_t) > 4; +arg_cmp_func Arg_comparator::comparator_matrix[4][2] = +{{&Arg_comparator::compare_string, &Arg_comparator::compare_e_string}, + {&Arg_comparator::compare_real, &Arg_comparator::compare_e_real}, + {&Arg_comparator::compare_int, &Arg_comparator::compare_e_int}, + {&Arg_comparator::compare_row, &Arg_comparator::compare_e_row}}; -/* - Variables to store startup options -*/ -my_bool opt_skip_slave_start = 0; // If set, slave is not autostarted -/* - If set, some standard measures to enforce slave data integrity will not - be performed -*/ -my_bool opt_reckless_slave = 0; +/* Global variables */ -ulong back_log, connect_timeout, concurrency; -char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], time_zone[30]; -char log_error_file[FN_REFLEN]; bool opt_log, opt_update_log, opt_bin_log, opt_slow_log; bool opt_error_log= IF_WIN(1,0); bool opt_disable_networking=0, opt_skip_show_db=0; +bool server_id_supplied = 0; +bool opt_endinfo,using_udf_functions, locked_in_memory; +bool opt_using_transactions, using_update_log; +bool volatile abort_loop, select_thread_in_use, signal_thread_in_use; +bool volatile ready_to_exit, shutdown_in_progress, grant_option; + +my_bool opt_skip_slave_start = 0; // If set, slave is not autostarted +my_bool opt_reckless_slave = 0; my_bool opt_enable_named_pipe= 0; my_bool opt_local_infile, opt_external_locking, opt_slave_compressed_protocol; -uint delay_key_write_options= (uint) DELAY_KEY_WRITE_ON; - -static bool opt_do_pstack = 0; -static ulong opt_specialflag=SPECIAL_ENGLISH; - -static ulong opt_myisam_block_size; -static my_socket unix_sock= INVALID_SOCKET,ip_sock= INVALID_SOCKET; -static my_string opt_logname=0,opt_update_logname=0, - opt_binlog_index_name = 0,opt_slow_logname=0; - -static char* mysql_home_ptr= mysql_home; -static char* pidfile_name_ptr= pidfile_name; -char* log_error_file_ptr= log_error_file; -static pthread_t select_thread; -static my_bool opt_noacl=0, opt_bootstrap=0, opt_myisam_log=0; my_bool opt_safe_user_create = 0, opt_no_mix_types = 0; my_bool lower_case_table_names, opt_old_rpl_compat; my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0; my_bool opt_log_slave_updates= 0, opt_old_passwords=0, use_old_passwords=0; my_bool opt_console= 0, opt_bdb, opt_innodb, opt_isam; +my_bool opt_readonly, use_temp_pool, relay_log_purge; +volatile bool mqh_used = 0; -volatile bool mqh_used = 0; -FILE *bootstrap_file=0; - -static bool kill_in_progress=0, segfaulted= 0; -struct rand_struct sql_rand; // used by sql_class.cc:THD::THD() -static int cleanup_done; -static char **defaults_argv; -char glob_hostname[FN_REFLEN]; - -#include "sslopt-vars.h" -#ifdef HAVE_OPENSSL -char *des_key_file = 0; -struct st_VioSSLAcceptorFd *ssl_acceptor_fd= 0; -#endif /* HAVE_OPENSSL */ - -I_List <i_string_pair> replicate_rewrite_db; -I_List<i_string> replicate_do_db, replicate_ignore_db; -// allow the user to tell us which db to replicate and which to ignore -I_List<i_string> binlog_do_db, binlog_ignore_db; - -/* if we guessed server_id , we need to know about it */ -ulong server_id= 0; // Must be long becasue of set_var.cc -bool server_id_supplied = 0; +uint mysql_port, test_flags, select_errors, dropping_tables, ha_open_options; +uint delay_key_write_options, protocol_version; +uint volatile thread_count, thread_running, kill_cached_threads, wake_thread; -uint mysql_port; -uint test_flags = 0, select_errors=0, dropping_tables=0,ha_open_options=0; -uint volatile thread_count=0, thread_running=0, kill_cached_threads=0, - wake_thread=0; -ulong thd_startup_options=(OPTION_UPDATE_LOG | OPTION_AUTO_IS_NULL | - OPTION_BIN_LOG | OPTION_QUOTE_SHOW_CREATE ); -uint protocol_version=PROTOCOL_VERSION; -struct system_variables global_system_variables; -struct system_variables max_system_variables; -ulonglong keybuff_size; -ulong table_cache_size, - thread_stack, - thread_stack_min,what_to_log= ~ (1L << (uint) COM_TIME), - query_buff_size, - slow_launch_time = 2L, - slave_open_temp_tables=0, - open_files_limit=0, max_binlog_size; -ulong com_stat[(uint) SQLCOM_END], com_other; +ulong back_log, connect_timeout, concurrency; +ulong server_id, thd_startup_options; +ulong table_cache_size, thread_stack, thread_stack_min, what_to_log; +ulong query_buff_size, slow_launch_time, slave_open_temp_tables; +ulong open_files_limit, max_binlog_size; ulong slave_net_timeout; ulong thread_cache_size=0, binlog_cache_size=0, max_binlog_cache_size=0; ulong query_cache_size=0; -#ifdef HAVE_QUERY_CACHE -ulong query_cache_limit= 0; -ulong query_cache_min_res_unit= QUERY_CACHE_MIN_RESULT_DATA_SIZE; -Query_cache query_cache; -#endif -arg_cmp_func Arg_comparator::comparator_matrix[4][2] = -{{&Arg_comparator::compare_string, &Arg_comparator::compare_e_string}, - {&Arg_comparator::compare_real, &Arg_comparator::compare_e_real}, - {&Arg_comparator::compare_int, &Arg_comparator::compare_e_int}, - {&Arg_comparator::compare_row, &Arg_comparator::compare_e_row}}; -#ifdef HAVE_SMEM -char *shared_memory_base_name=default_shared_memory_base_name; -my_bool opt_enable_shared_memory = 0; -#endif - -volatile ulong cached_thread_count=0; - -// replication parameters, if master_host is not NULL, we are a slave -my_string master_user = (char*) "test", master_password = 0, master_host=0, - master_info_file = (char*) "master.info", - relay_log_info_file = (char*) "relay-log.info", - master_ssl_key=0, master_ssl_cert=0, master_ssl_capath=0, master_ssl_cipher=0; -my_string report_user = 0, report_password = 0, report_host=0; - -const char *localhost=LOCAL_HOST; -const char *delayed_user="DELAYED"; -uint master_port = MYSQL_PORT, master_connect_retry = 60; -uint report_port = MYSQL_PORT; -bool master_ssl = 0; - -ulong master_retry_count=0; -ulong bytes_sent = 0L, bytes_received = 0L; - -bool opt_endinfo,using_udf_functions, locked_in_memory; -bool opt_using_transactions, using_update_log; -bool volatile abort_loop, select_thread_in_use, signal_thread_in_use; -bool volatile ready_to_exit, shutdown_in_progress, grant_option; +ulong com_stat[(uint) SQLCOM_END], com_other; +ulong bytes_sent, bytes_received; ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */ -ulong query_id=1L,long_query_count,aborted_threads, - aborted_connects,delayed_insert_timeout,delayed_insert_limit, - delayed_queue_size,delayed_insert_threads,delayed_insert_writes, - delayed_rows_in_use,delayed_insert_errors,flush_time, thread_created; +ulong query_id, long_query_count, aborted_threads, aborted_connects; +ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size; +ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use; +ulong delayed_insert_errors,flush_time, thread_created; ulong filesort_rows, filesort_range_count, filesort_scan_count; ulong filesort_merge_passes; ulong select_range_check_count, select_range_count, select_scan_count; @@ -417,52 +284,51 @@ ulong max_connections,max_insert_delayed_threads,max_used_connections, ulong thread_id=1L,current_pid; ulong slow_launch_threads = 0; ulong expire_logs_days = 0; +ulong rpl_recovery_rank=0; +ulong my_bind_addr; /* the address we bind to */ +volatile ulong cached_thread_count= 0; +ulonglong keybuff_size; + +double log_10[32]; /* 10 potences */ + +time_t start_time; + +char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], time_zone[30]; +char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN]; +char* log_error_file_ptr= log_error_file; char mysql_real_data_home[FN_REFLEN], - language[LIBLEN],reg_ext[FN_EXTLEN], - mysql_charsets_dir[FN_REFLEN], *charsets_list, - blob_newline,f_fyllchar,max_sort_char,*mysqld_user,*mysqld_chroot, - *opt_init_file; -char *language_ptr= language; + language[LIBLEN],reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN], + max_sort_char,*mysqld_user,*mysqld_chroot, *opt_init_file; +char *language_ptr, *default_collation_name, *default_character_set_name; char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home; -#ifndef EMBEDDED_LIBRARY -bool mysql_embedded=0; -#else -bool mysql_embedded=1; -#endif - -static char *opt_bin_logname = 0; -char *opt_relay_logname = 0, *opt_relaylog_index_name=0; char server_version[SERVER_VERSION_LENGTH]=MYSQL_SERVER_VERSION; -const char *first_keyword="first"; +char *mysql_unix_port, *opt_mysql_tmpdir; +char *my_bind_addr_str; const char **errmesg; /* Error messages */ const char *myisam_recover_options_str="OFF"; const char *sql_mode_str="OFF"; -ulong rpl_recovery_rank=0; -my_bool relay_log_purge=1; -my_string mysql_unix_port=NULL, opt_mysql_tmpdir=NULL; -MY_TMPDIR mysql_tmpdir_list; -ulong my_bind_addr; /* the address we bind to */ -char *my_bind_addr_str; -DATE_FORMAT dayord; -double log_10[32]; /* 10 potences */ +FILE *bootstrap_file; + +I_List <i_string_pair> replicate_rewrite_db; +I_List<i_string> replicate_do_db, replicate_ignore_db; +// allow the user to tell us which db to replicate and which to ignore +I_List<i_string> binlog_do_db, binlog_ignore_db; I_List<THD> threads,thread_cache; -time_t start_time; -const char *sql_mode_names[] = -{ - "REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", - "SERIALIZE", "ONLY_FULL_GROUP_BY", "NO_UNSIGNED_SUBTRACTION", - "POSTGRESQL", "ORACLE", "MSSQL", "DB2", "SAPDB", "NO_KEY_OPTIONS", - "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", - NullS -}; -TYPELIB sql_mode_typelib= {array_elements(sql_mode_names)-1,"", - sql_mode_names}; +struct system_variables global_system_variables; +struct system_variables max_system_variables; +MY_TMPDIR mysql_tmpdir_list; +DATE_FORMAT dayord; MY_BITMAP temp_pool; -my_bool use_temp_pool=0; + +SHOW_COMP_OPTION have_berkeley_db, have_innodb, have_isam; +SHOW_COMP_OPTION have_raid, have_openssl, have_symlink, have_query_cache; +SHOW_COMP_OPTION have_crypt, have_compress; + +/* Thread specific variables */ pthread_key(MEM_ROOT*,THR_MALLOC); pthread_key(THD*, THR_THD); @@ -480,24 +346,98 @@ pthread_cond_t COND_thread_cache,COND_flush_thread_cache; pthread_t signal_thread; pthread_attr_t connection_attrib; +/* replication parameters, if master_host is not NULL, we are a slave */ +my_bool master_ssl; +uint master_port= MYSQL_PORT, master_connect_retry = 60; +uint report_port= MYSQL_PORT; +ulong master_retry_count=0; +char *master_user, *master_password, *master_host, *master_info_file; +char *relay_log_info_file, *master_ssl_key, *master_ssl_cert; +char *master_ssl_capath, *master_ssl_cipher, *report_user; +char *report_password, *report_host; +char *opt_relay_logname = 0, *opt_relaylog_index_name=0; + +/* Static variables */ + +static bool kill_in_progress, segfaulted; +static my_bool opt_do_pstack, opt_noacl, opt_bootstrap, opt_myisam_log; +static int cleanup_done; +static ulong opt_specialflag, opt_myisam_block_size; +static char *opt_logname, *opt_update_logname, *opt_binlog_index_name; +static char *opt_slow_logname; +static char *mysql_home_ptr, *pidfile_name_ptr; +static char **defaults_argv; +static char *opt_bin_logname; + +static my_socket unix_sock,ip_sock; +static pthread_t select_thread; +struct rand_struct sql_rand; // used by sql_class.cc:THD::THD() + +/* OS specific variables */ + #ifdef __WIN__ #undef getpid #include <process.h> + +static pthread_cond_t COND_handler_count; +static uint handler_count; +static bool start_mode=0, use_opt_args; +static int opt_argc; +static char **opt_argv; + #if !defined(EMBEDDED_LIBRARY) -HANDLE hEventShutdown; +static HANDLE hEventShutdown; static char shutdown_event_name[40]; #include "nt_servc.h" static NTService Service; // Service object for WinNT -#endif +#endif /* EMBEDDED_LIBRARY */ +#endif /* __WIN__ */ + +#ifdef __NT__ +static char szPipeName [ 257 ]; +static SECURITY_ATTRIBUTES saPipeSecurity; +static SECURITY_DESCRIPTOR sdPipeDescriptor; +static HANDLE hPipe = INVALID_HANDLE_VALUE; #endif #ifdef OS2 pthread_cond_t eventShutdown; #endif +#ifndef EMBEDDED_LIBRARY +bool mysql_embedded=0; +#else +bool mysql_embedded=1; +#endif + +#ifndef DBUG_OFF +static const char* default_dbug_option; +#endif +#ifdef HAVE_LIBWRAP +char *libwrapName= NULL; +#endif +#ifdef HAVE_QUERY_CACHE +ulong query_cache_limit= 0; +ulong query_cache_min_res_unit= QUERY_CACHE_MIN_RESULT_DATA_SIZE; +Query_cache query_cache; +#endif +#ifdef HAVE_SMEM +char *shared_memory_base_name= default_shared_memory_base_name; +my_bool opt_enable_shared_memory; +#endif + +#include "sslopt-vars.h" +#ifdef HAVE_OPENSSL +char *des_key_file; +struct st_VioSSLAcceptorFd *ssl_acceptor_fd; +#endif /* HAVE_OPENSSL */ + + +/* Function declarations */ + static void start_signal_handler(void); extern "C" pthread_handler_decl(signal_hand, arg); -static void set_options(void); +static void mysql_init_variables(void); static void get_options(int argc,char **argv); static int init_thread_environment(); static char *get_relative_path(const char *path); @@ -657,7 +597,6 @@ static void close_connections(void) /* Force remaining threads to die by closing the connection to the client */ - (void) my_net_init(&net, (st_vio*) 0); for (;;) { DBUG_PRINT("quit",("Locking LOCK_thread_count")); @@ -669,17 +608,16 @@ static void close_connections(void) break; } #ifndef __bsdi__ // Bug in BSDI kernel - if ((net.vio=tmp->net.vio) != 0) + if (tmp->net.vio) { sql_print_error(ER(ER_FORCING_CLOSE),my_progname, tmp->thread_id,tmp->user ? tmp->user : ""); - close_connection(&net,0,0); + close_connection(tmp,0,0); } #endif DBUG_PRINT("quit",("Unlocking LOCK_thread_count")); (void) pthread_mutex_unlock(&LOCK_thread_count); } - net_end(&net); /* All threads has now been aborted */ DBUG_PRINT("quit",("Waiting for threads to die (count=%u)",thread_count)); (void) pthread_mutex_lock(&LOCK_thread_count); @@ -823,9 +761,9 @@ static void __cdecl kill_server(int sig_ptr) unireg_end(); #ifdef __NETWARE__ pthread_join(select_thread, NULL); // wait for main thread -#else - pthread_exit(0); /* purecov: deadcode */ #endif /* __NETWARE__ */ + + pthread_exit(0); /* purecov: deadcode */ #endif /* EMBEDDED_LIBRARY */ RETURN_FROM_KILL_SERVER; @@ -883,13 +821,11 @@ void unireg_end(void) { clean_up(1); my_thread_end(); -#ifndef __NETWARE__ -#ifdef SIGNALS_DONT_BREAK_READ +#if defined(SIGNALS_DONT_BREAK_READ) && !defined(__NETWARE__) exit(0); #else pthread_exit(0); // Exit is in main thread #endif -#endif /* __NETWARE__ */ } @@ -941,7 +877,6 @@ void clean_up(bool print_message) #endif if (defaults_argv) free_defaults(defaults_argv); - my_free(charsets_list, MYF(MY_ALLOW_ZERO_PTR)); free_tmpdir(&mysql_tmpdir_list); #ifdef HAVE_REPLICATION my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR)); @@ -954,6 +889,8 @@ void clean_up(bool print_message) end_slave_list(); #endif #ifdef HAVE_OPENSSL + if (ssl_acceptor_fd) + my_free((gptr) ssl_acceptor_fd, MYF(MY_ALLOW_ZERO_PTR)); free_des_key_file(); #endif /* HAVE_OPENSSL */ #ifdef USE_REGEX @@ -1276,19 +1213,20 @@ void yyerror(const char *s) #ifndef EMBEDDED_LIBRARY -void close_connection(NET *net,uint errcode,bool lock) +void close_connection(THD *thd, uint errcode, bool lock) { - st_vio* vio; + st_vio *vio; DBUG_ENTER("close_connection"); DBUG_PRINT("enter",("fd: %s error: '%s'", - net->vio? vio_description(net->vio):"(not connected)", - errcode ? ER(errcode) : "")); + thd->net.vio ? vio_description(thd->net.vio) : + "(not connected)", + errcode ? ER(errcode) : "")); if (lock) (void) pthread_mutex_lock(&LOCK_thread_count); - if ((vio=net->vio) != 0) + if ((vio=thd->net.vio) != 0) { if (errcode) - net_send_error(net,errcode,ER(errcode)); /* purecov: inspected */ + send_error(thd, errcode, ER(errcode)); /* purecov: inspected */ vio_close(vio); /* vio is freed in delete thd */ } if (lock) @@ -1647,6 +1585,7 @@ static void init_signals(void) sa.sa_handler=handle_segfault; #endif sigaction(SIGSEGV, &sa, NULL); + sigaction(SIGABRT, &sa, NULL); #ifdef SIGBUS sigaction(SIGBUS, &sa, NULL); #endif @@ -1732,9 +1671,10 @@ extern "C" void *signal_hand(void *arg __attribute__((unused))) /* Setup alarm handler - The two extra handlers are for slave threads + This should actually be '+ max_number_of_slaves' instead of +10, + but the +10 should be quite safe. */ - init_thr_alarm(max_connections+max_insert_delayed_threads+2); + init_thr_alarm(max_connections+max_insert_delayed_threads+10); #if SIGINT != THR_KILL_SIGNAL (void) sigemptyset(&set); // Setup up SIGINT for debug (void) sigaddset(&set,SIGINT); // For debugging @@ -1997,6 +1937,7 @@ static int init_common_variables(const char *conf_file_name, int argc, max_system_variables.pseudo_thread_id= (ulong)~0; start_time=time((time_t*) 0); + mysql_init_variables(); #ifdef OS2 { @@ -2035,7 +1976,6 @@ static int init_common_variables(const char *conf_file_name, int argc, load_defaults(conf_file_name, groups, &argc, &argv); defaults_argv=argv; - set_options(); get_options(argc,argv); if (init_thread_environment()) return 1; @@ -2088,14 +2028,30 @@ static int init_common_variables(const char *conf_file_name, int argc, #ifdef USE_REGEX regex_init(&my_charset_latin1); #endif - if (!(default_charset_info= get_charset_by_name(sys_charset.value, MYF(MY_WME)))) + if (!(default_charset_info= get_charset_by_csname(default_character_set_name, + MY_CS_PRIMARY, + MYF(MY_WME)))) return 1; - global_system_variables.collation_results= default_charset_info; - global_system_variables.collation_client= default_charset_info; + if (default_collation_name) + { + CHARSET_INFO *default_collation; + default_collation= get_charset_by_name(default_collation_name, MYF(0)); + if (!default_collation || !my_charset_same(default_charset_info, + default_collation)) + { + sql_print_error(ER(ER_COLLATION_CHARSET_MISMATCH), + default_collation_name, + default_charset_info->csname); + return 1; + } + default_charset_info= default_collation; + } + global_system_variables.character_set_server= default_charset_info; + global_system_variables.character_set_database= default_charset_info; + global_system_variables.character_set_results= default_charset_info; + global_system_variables.character_set_client= default_charset_info; global_system_variables.collation_connection= default_charset_info; - charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG)); - if (use_temp_pool && bitmap_init(&temp_pool,1024,1)) return 1; return 0; @@ -2327,7 +2283,9 @@ static void handle_connections_methods() #endif /* __NT__ */ if (have_tcpip && !opt_disable_networking) { +#ifdef __NT__ handler_count++; +#endif if (pthread_create(&hThread,&connection_attrib, handle_connections_sockets, 0)) { @@ -2338,7 +2296,9 @@ static void handle_connections_methods() #ifdef HAVE_SMEM if (opt_enable_shared_memory) { +#ifdef __NT__ handler_count++; +#endif if (pthread_create(&hThread,&connection_attrib, handle_connections_shared_memory, 0)) { @@ -2762,7 +2722,7 @@ static void create_new_thread(THD *thd) if (thread_count - delayed_insert_threads >= max_connections+1 || abort_loop) { DBUG_PRINT("error",("Too many connections")); - close_connection(net,ER_CON_COUNT_ERROR); + close_connection(thd, ER_CON_COUNT_ERROR, 1); delete thd; DBUG_VOID_RETURN; } @@ -2817,7 +2777,7 @@ static void create_new_thread(THD *thd) (void) pthread_mutex_unlock(&LOCK_thread_count); net_printf(thd,ER_CANT_CREATE_THREAD,error); (void) pthread_mutex_lock(&LOCK_thread_count); - close_connection(net,0,0); + close_connection(thd,0,0); delete thd; (void) pthread_mutex_unlock(&LOCK_thread_count); DBUG_VOID_RETURN; @@ -3138,7 +3098,7 @@ extern "C" pthread_handler_decl(handle_connections_namedpipes,arg) if (!(thd->net.vio = vio_new_win32pipe(hConnectedPipe)) || my_net_init(&thd->net, thd->net.vio)) { - close_connection(&thd->net,ER_OUT_OF_RESOURCES); + close_connection(thd, ER_OUT_OF_RESOURCES, 1); delete thd; continue; } @@ -3339,7 +3299,7 @@ Send number of connection to client event_client_read,event_server_wrote,event_server_read)) || my_net_init(&thd->net, thd->net.vio)) { - close_connection(&thd->net,ER_OUT_OF_RESOURCES); + close_connection(thd, ER_OUT_OF_RESOURCES, 1); delete thd; error_allow = TRUE; } @@ -3364,10 +3324,12 @@ error: if (!handle_connect_file_map) CloseHandle(handle_connect_file_map); if (!event_connect_answer) CloseHandle(event_connect_answer); if (!event_connect_request) CloseHandle(event_connect_request); +#ifdef __NT__ pthread_mutex_lock(&LOCK_thread_count); handler_count--; pthread_mutex_unlock(&LOCK_thread_count); pthread_cond_signal(&COND_handler_count); +#endif DBUG_RETURN(0); } #endif /* HAVE_SMEM */ @@ -3468,10 +3430,11 @@ enum options OPT_QUERY_CACHE_TYPE, OPT_RECORD_BUFFER, OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT, OPT_RELAY_LOG_PURGE, OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME, + OPT_READONLY, OPT_SORT_BUFFER, OPT_TABLE_CACHE, OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE, OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK, - OPT_WAIT_TIMEOUT, + OPT_WAIT_TIMEOUT, OPT_MYISAM_REPAIR_THREADS, OPT_INNODB_MIRRORED_LOG_GROUPS, OPT_INNODB_LOG_FILES_IN_GROUP, OPT_INNODB_LOG_FILE_SIZE, @@ -3483,6 +3446,7 @@ enum options OPT_INNODB_LOCK_WAIT_TIMEOUT, OPT_INNODB_THREAD_CONCURRENCY, OPT_INNODB_FORCE_RECOVERY, + OPT_INNODB_MAX_DIRTY_PAGES_PCT, OPT_BDB_CACHE_SIZE, OPT_BDB_LOG_BUFFER_SIZE, OPT_BDB_MAX_LOCK, @@ -3492,7 +3456,8 @@ enum options OPT_OLD_PASSWORDS, OPT_EXPIRE_LOGS_DAYS, OPT_DEFAULT_WEEK_FORMAT, - OPT_GROUP_CONCAT_MAX_LEN + OPT_GROUP_CONCAT_MAX_LEN, + OPT_DEFAULT_COLLATION }; @@ -3579,8 +3544,11 @@ Disable with --skip-bdb (will save memory)", 0, 0, 0, 0, 0, 0}, #endif /* HAVE_OPENSSL */ {"default-character-set", 'C', "Set the default character set", - (gptr*) &sys_charset.value, (gptr*) &sys_charset.value, 0, GET_STR, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + (gptr*) &default_character_set_name, (gptr*) &default_character_set_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + {"default-collation", OPT_DEFAULT_COLLATION, "Set the default collation", + (gptr*) &default_collation_name, (gptr*) &default_collation_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"default-table-type", OPT_TABLE_TYPE, "Set the default table type for tables", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -3649,6 +3617,10 @@ Disable with --skip-bdb (will save memory)", {"innodb_fast_shutdown", OPT_INNODB_FAST_SHUTDOWN, "Speeds up server shutdown process", (gptr*) &innobase_fast_shutdown, (gptr*) &innobase_fast_shutdown, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, + {"innodb_max_dirty_pages_pct", OPT_INNODB_MAX_DIRTY_PAGES_PCT, + "Percentage of dirty pages allowed in bufferpool", (gptr*) &srv_max_buf_pool_modified_pct, + (gptr*) &srv_max_buf_pool_modified_pct, 0, GET_ULONG, REQUIRED_ARG, 90, 0, 100, 0, 0, 0}, + #endif /* End HAVE_INNOBASE_DB */ {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -3667,7 +3639,7 @@ Disable with --skip-bdb (will save memory)", (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0}, {"log-bin", OPT_BIN_LOG, - "Log queries in new binary format (for replication)", + "Log update queries in binary format", (gptr*) &opt_bin_logname, (gptr*) &opt_bin_logname, 0, GET_STR_ALLOC, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"log-bin-index", OPT_BIN_LOG_INDEX, @@ -3721,27 +3693,32 @@ Disable with --skip-bdb (will save memory)", (gptr*) &master_retry_count, (gptr*) &master_retry_count, 0, GET_ULONG, REQUIRED_ARG, 3600*24, 0, 0, 0, 0, 0}, {"master-info-file", OPT_MASTER_INFO_FILE, - "The location of the file that remembers where we left off on the master during the replication process. The default is `master.info' in the data directory. You should not need to change this.", + "The location and name of the file that remembers the master and where the I/O replication \ +thread is in the master's binlogs.", (gptr*) &master_info_file, (gptr*) &master_info_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"master-ssl", OPT_MASTER_SSL, - "Turn SSL on for replication. Be warned that is this is a relatively new feature.", + "Planned to enable the slave to connect to the master using SSL. Does nothing yet.", (gptr*) &master_ssl, (gptr*) &master_ssl, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"master-ssl-key", OPT_MASTER_SSL_KEY, - "Master SSL keyfile name. Only applies if you have enabled master-ssl.", + "Master SSL keyfile name. Only applies if you have enabled master-ssl. Does \ +nothing yet.", (gptr*) &master_ssl_key, (gptr*) &master_ssl_key, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"master-ssl-cert", OPT_MASTER_SSL_CERT, - "Master SSL certificate file name. Only applies if you have enabled master-ssl.", + "Master SSL certificate file name. Only applies if you have enabled \ +master-ssl. Does nothing yet.", (gptr*) &master_ssl_cert, (gptr*) &master_ssl_cert, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"master-ssl-capath", OPT_MASTER_SSL_CAPATH, - "Master SSL CA path. Only applies if you have enabled master-ssl.", + "Master SSL CA path. Only applies if you have enabled master-ssl. \ +Does nothing yet.", (gptr*) &master_ssl_capath, (gptr*) &master_ssl_capath, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"master-ssl-cipher", OPT_MASTER_SSL_CIPHER, - "Master SSL cipher. Only applies if you have enabled master-ssl.", + "Master SSL cipher. Only applies if you have enabled master-ssl. \ +Does nothing yet.", (gptr*) &master_ssl_cipher, (gptr*) &master_ssl_capath, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"myisam-recover", OPT_MYISAM_RECOVER, @@ -3842,10 +3819,13 @@ Disable with --skip-bdb (will save memory)", {"rpl-recovery-rank", OPT_RPL_RECOVERY_RANK, "Undocumented", (gptr*) &rpl_recovery_rank, (gptr*) &rpl_recovery_rank, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"relay-log", OPT_RELAY_LOG, "Undocumented", + {"relay-log", OPT_RELAY_LOG, + "The location and name to use for relay logs", (gptr*) &opt_relay_logname, (gptr*) &opt_relay_logname, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"relay-log-index", OPT_RELAY_LOG_INDEX, "Undocumented", + {"relay-log-index", OPT_RELAY_LOG_INDEX, + "The location and name to use for the file that keeps a list of the last \ +relay logs", (gptr*) &opt_relaylog_index_name, (gptr*) &opt_relaylog_index_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"safe-mode", OPT_SAFE, "Skip some optimize stages (for testing).", @@ -3915,16 +3895,20 @@ Disable with --skip-isam", {"skip-stack-trace", OPT_SKIP_STACK_TRACE, "Don't print a stack trace on failure", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables", + {"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables. Depricated option. Use --skip-symbolic-links instead", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"skip-thread-priority", OPT_SKIP_PRIOR, "Don't give threads different priorities.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"relay-log-info-file", OPT_RELAY_LOG_INFO_FILE, "Undocumented", + {"relay-log-info-file", OPT_RELAY_LOG_INFO_FILE, + "The location and name of the file that remembers where the SQL replication \ +thread is in the relay logs", (gptr*) &relay_log_info_file, (gptr*) &relay_log_info_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #ifdef HAVE_REPLICATION - {"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR, "Undocumented", + {"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR, + "The location where the slave should put its temporary files when \ +replicating a LOAD DATA INFILE command", (gptr*) &slave_load_tmpdir, (gptr*) &slave_load_tmpdir, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"slave-skip-errors", OPT_SLAVE_SKIP_ERRORS, @@ -3965,11 +3949,12 @@ Disable with --skip-isam", {"external-locking", OPT_USE_LOCKING, "Use system (external) locking. With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running", (gptr*) &opt_external_locking, (gptr*) &opt_external_locking, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, -#ifdef USE_SYMDIR - {"use-symbolic-links", 's', "Enable symbolic link support", + {"use-symbolic-links", 's', "Enable symbolic link support. Depricated option; Use --symbolic-links instead", + (gptr*) &my_use_symdir, (gptr*) &my_use_symdir, 0, GET_BOOL, NO_ARG, + IF_PURIFY(0,1), 0, 0, 0, 0, 0}, + {"--symbolic-links", 's', "Enable symbolic link support", (gptr*) &my_use_symdir, (gptr*) &my_use_symdir, 0, GET_BOOL, NO_ARG, IF_PURIFY(0,1), 0, 0, 0, 0, 0}, -#endif {"user", 'u', "Run mysqld daemon as user", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit", 0, 0, 0, GET_NO_ARG, @@ -4147,7 +4132,7 @@ Disable with --skip-isam", (gptr*) &max_connect_errors, (gptr*) &max_connect_errors, 0, GET_ULONG, REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ~0L, 0, 1, 0}, {"max_delayed_threads", OPT_MAX_DELAYED_THREADS, - "Don't start more than this number of threads to handle INSERT DELAYED statements. This option does not yet have effect (on TODO), unless it is set to zero, which means INSERT DELAYED is not used.", + "Don't start more than this number of threads to handle INSERT DELAYED statements. If set to zero, which means INSERT DELAYED is not used.", (gptr*) &max_insert_delayed_threads, (gptr*) &max_insert_delayed_threads, 0, GET_ULONG, REQUIRED_ARG, 20, 0, 16384, 0, 1, 0}, {"max_error_count", OPT_MAX_ERROR_COUNT, @@ -4209,12 +4194,18 @@ Disable with --skip-isam", (gptr*) &global_system_variables.myisam_max_extra_sort_file_size, (gptr*) &max_system_variables.myisam_max_extra_sort_file_size, 0, GET_ULL, REQUIRED_ARG, (ulonglong) MI_MAX_TEMP_LENGTH, - 0, ~0L, 0, 1, 0}, + 0, (ulonglong) MAX_FILE_SIZE, 0, 1, 0}, {"myisam_max_sort_file_size", OPT_MYISAM_MAX_SORT_FILE_SIZE, "Don't use the fast sort index method to created index if the temporary file would get bigger than this!", (gptr*) &global_system_variables.myisam_max_sort_file_size, (gptr*) &max_system_variables.myisam_max_sort_file_size, 0, - GET_ULL, REQUIRED_ARG, (longlong) LONG_MAX, 0, ~0L, 0, 1024*1024, 0}, + GET_ULL, REQUIRED_ARG, (longlong) LONG_MAX, 0, (ulonglong) MAX_FILE_SIZE, + 0, 1024*1024, 0}, + {"myisam_repair_threads", OPT_MYISAM_REPAIR_THREADS, + "Number of threads to use when repairing MyISAM tables. The value of 1 disables parallel repair.", + (gptr*) &global_system_variables.myisam_repair_threads, + (gptr*) &max_system_variables.myisam_repair_threads, 0, + GET_ULONG, REQUIRED_ARG, 1, 1, ~0L, 0, 1, 0}, {"myisam_sort_buffer_size", OPT_MYISAM_SORT_BUFFER_SIZE, "The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.", (gptr*) &global_system_variables.myisam_sort_buff_size, @@ -4289,7 +4280,7 @@ Disable with --skip-isam", (gptr*) &relay_log_purge, 0, GET_BOOL, NO_ARG, 1, 0, 1, 0, 1, 0}, {"relay_log_space_limit", OPT_RELAY_LOG_SPACE_LIMIT, - "Max space to use for all relay logs", + "Maximum space to use for all relay logs", (gptr*) &relay_log_space_limit, (gptr*) &relay_log_space_limit, 0, GET_ULL, REQUIRED_ARG, 0L, 0L, (longlong) ULONG_MAX, 0, 1, 0}, @@ -4303,6 +4294,11 @@ Disable with --skip-isam", (gptr*) &slave_net_timeout, (gptr*) &slave_net_timeout, 0, GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0}, #endif /* HAVE_REPLICATION */ + {"read-only", OPT_READONLY, + "Make all tables readonly, with the expections for replications (slave) threads and users with the SUPER privilege", + (gptr*) &opt_readonly, + (gptr*) &opt_readonly, + 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0}, {"slow_launch_time", OPT_SLOW_LAUNCH_TIME, "If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented.", (gptr*) &slow_launch_time, (gptr*) &slow_launch_time, 0, GET_ULONG, @@ -4544,6 +4540,12 @@ static void use_help(void) static void usage(void) { + if (!(default_charset_info= get_charset_by_csname(default_character_set_name, + MY_CS_PRIMARY, + MYF(MY_WME)))) + exit(1); + if (!default_collation_name) + default_collation_name= (char*) default_charset_info->name; print_version(); puts("\ Copyright (C) 2000 MySQL AB, by Monty and others\n\ @@ -4579,20 +4581,116 @@ To see what values a running MySQL server is using, type\n\ } -static void set_options(void) -{ -#if !defined( my_pthread_setprio ) && !defined( HAVE_PTHREAD_SETSCHEDPARAM ) - opt_specialflag |= SPECIAL_NO_PRIOR; -#endif +/* + Initialize all MySQL global variables to default values + + SYNOPSIS + mysql_init_variables() + + NOTES + The reason to set a lot of global variables to zero is to allow one to + restart the embedded server with a clean environment + It's also needed on some exotic platforms where global variables are + not set to 0 when a program starts. - sys_charset.value= (char*) MYSQL_CHARSET; - (void) strmake(language, LANGUAGE, sizeof(language)-1); - (void) strmake(mysql_real_data_home, get_relative_path(DATADIR), - sizeof(mysql_real_data_home)-1); + We don't need to set numeric variables refered to in my_long_options + as these are initialized by my_getopt. +*/ - /* Set default values for some variables */ - global_system_variables.collation_results= default_charset_info; - global_system_variables.collation_client= default_charset_info; +static void mysql_init_variables(void) +{ + /* Things reset to zero */ + opt_skip_slave_start= opt_reckless_slave = 0; + mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0; + opt_log= opt_update_log= opt_bin_log= opt_slow_log= 0; + opt_disable_networking= opt_skip_show_db=0; + opt_logname= opt_update_logname= opt_binlog_index_name= opt_slow_logname=0; + opt_bootstrap= opt_myisam_log= use_old_passwords= 0; + mqh_used= 0; + segfaulted= kill_in_progress= 0; + cleanup_done= 0; + defaults_argv= 0; + server_id_supplied= 0; + test_flags= select_errors= dropping_tables= ha_open_options=0; + thread_count= thread_running= kill_cached_threads= wake_thread=0; + slave_open_temp_tables= 0; + com_other= 0; + cached_thread_count= 0; + bytes_sent= bytes_received= 0; + opt_endinfo= using_udf_functions= 0; + opt_using_transactions= using_update_log= 0; + abort_loop= select_thread_in_use= signal_thread_in_use= 0; + ready_to_exit= shutdown_in_progress= grant_option= 0; + long_query_count= aborted_threads= aborted_connects= 0; + delayed_insert_threads= delayed_insert_writes= delayed_rows_in_use= 0; + delayed_insert_errors= thread_created= 0; + filesort_rows= filesort_range_count= filesort_scan_count= 0; + filesort_merge_passes= select_range_check_count= select_range_count= 0; + select_scan_count= select_full_range_join_count= select_full_join_count= 0; + specialflag= opened_tables= created_tmp_tables= created_tmp_disk_tables= 0; + max_used_connections= slow_launch_threads = 0; + max_sort_char= 0; + mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0; + errmesg= 0; + mysql_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS; + bzero((gptr) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list)); + bzero((gptr) &com_stat, sizeof(com_stat)); + + /* Things with default values that are not zero */ + delay_key_write_options= (uint) DELAY_KEY_WRITE_ON; + opt_specialflag= SPECIAL_ENGLISH; + unix_sock= ip_sock= INVALID_SOCKET; + mysql_home_ptr= mysql_home; + pidfile_name_ptr= pidfile_name; + log_error_file_ptr= log_error_file; + language_ptr= language; + mysql_data_home= mysql_real_data_home; + thd_startup_options= (OPTION_UPDATE_LOG | OPTION_AUTO_IS_NULL | + OPTION_BIN_LOG | OPTION_QUOTE_SHOW_CREATE); + protocol_version= PROTOCOL_VERSION; + what_to_log= ~ (1L << (uint) COM_TIME); + refresh_version= flush_version= 1L; /* Increments on each reload */ + thread_id= 1L; + strmov(server_version, MYSQL_SERVER_VERSION); + myisam_recover_options_str= sql_mode_str= "OFF"; + my_bind_addr = htonl(INADDR_ANY); + threads.empty(); + thread_cache.empty(); + + /* Initialize structures that is used when processing options */ + replicate_rewrite_db.empty(); + replicate_do_db.empty(); + replicate_ignore_db.empty(); + binlog_do_db.empty(); + binlog_ignore_db.empty(); + + /* Set directory paths */ + strmake(language, LANGUAGE, sizeof(language)-1); + strmake(mysql_real_data_home, get_relative_path(DATADIR), + sizeof(mysql_real_data_home)-1); + mysql_data_home_buff[0]=FN_CURLIB; // all paths are relative from here + mysql_data_home_buff[1]=0; + + /* Replication parameters */ + master_user= (char*) "test"; + master_password= master_host= 0; + master_info_file= (char*) "master.info", + relay_log_info_file= (char*) "relay-log.info", + master_ssl_key= master_ssl_cert= master_ssl_capath= master_ssl_cipher= 0; + report_user= report_password = report_host= 0; /* TO BE DELETED */ + opt_relay_logname= opt_relaylog_index_name= 0; + + /* Variables in libraries */ + charsets_dir= 0; + default_character_set_name= (char*) MYSQL_DEFAULT_CHARSET_NAME; + default_collation_name= (char*) MYSQL_DEFAULT_COLLATION_NAME; + sys_charset_system.value= (char*) system_charset_info->csname; + + /* Set default values for some option variables */ + global_system_variables.character_set_server= default_charset_info; + global_system_variables.character_set_database= default_charset_info; + global_system_variables.character_set_results= default_charset_info; + global_system_variables.character_set_client= default_charset_info; global_system_variables.collation_connection= default_charset_info; global_system_variables.table_type= DB_TYPE_MYISAM; global_system_variables.tx_isolation= ISO_REPEATABLE_READ; @@ -4601,6 +4699,71 @@ static void set_options(void) global_system_variables.max_join_size= (ulonglong) HA_POS_ERROR; max_system_variables.max_join_size= (ulonglong) HA_POS_ERROR; + /* Variables that depends on compile options */ +#ifndef DBUG_OFF + default_dbug_option=IF_WIN("d:t:i:O,\\mysqld.trace", + "d:t:i:o,/tmp/mysqld.trace"); +#endif + opt_error_log= IF_WIN(1,0); +#ifdef HAVE_BERKELEY_DB + have_berkeley_db= SHOW_OPTION_YES; +#else + have_berkeley_db= SHOW_OPTION_NO; +#endif +#ifdef HAVE_INNOBASE_DB + have_innodb=SHOW_OPTION_YES; +#else + have_innodb=SHOW_OPTION_NO; +#endif +#ifdef HAVE_ISAM + have_isam=SHOW_OPTION_YES; +#else + have_isam=SHOW_OPTION_NO; +#endif +#ifdef USE_RAID + have_raid=SHOW_OPTION_YES; +#else + have_raid=SHOW_OPTION_NO; +#endif +#ifdef HAVE_OPENSSL + have_openssl=SHOW_OPTION_YES; +#else + have_openssl=SHOW_OPTION_NO; +#endif +#ifdef HAVE_BROKEN_REALPATH + have_symlink=SHOW_OPTION_NO; +#else + have_symlink=SHOW_OPTION_YES; +#endif +#ifdef HAVE_QUERY_CACHE + have_query_cache=SHOW_OPTION_YES; +#else + have_query_cache=SHOW_OPTION_NO; +#endif +#ifdef HAVE_CRYPT + have_crypt=SHOW_OPTION_YES; +#else + have_crypt=SHOW_OPTION_NO; +#endif +#ifdef HAVE_COMPRESS + SHOW_COMP_OPTION have_compress= SHOW_OPTION_YES; +#else + SHOW_COMP_OPTION have_compress= SHOW_OPTION_NO; +#endif +#ifdef HAVE_LIBWRAP + libwrapName= NullS; +#endif +#ifdef HAVE_OPENSSL + des_key_file = 0; + ssl_acceptor_fd= 0; +#endif +#ifdef HAVE_SMEM + shared_memory_base_name= default_shared_memory_base_name; +#endif +#if !defined(my_pthread_setprio) && !defined(HAVE_PTHREAD_SETSCHEDPARAM) + opt_specialflag |= SPECIAL_NO_PRIOR; +#endif + #if defined(__WIN__) || defined(__NETWARE__) /* Allow Win32 and NetWare users to move MySQL anywhere */ { @@ -4615,10 +4778,6 @@ static void set_options(void) tmpenv = DEFAULT_MYSQL_HOME; (void) strmake(mysql_home, tmpenv, sizeof(mysql_home)-1); #endif - - my_disable_locking=myisam_single_user= 1; - opt_external_locking=0; - my_bind_addr = htonl( INADDR_ANY ); } @@ -4643,6 +4802,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'b': strmake(mysql_home,argument,sizeof(mysql_home)-1); break; + case 'C': + default_collation_name= 0; + break; case 'l': opt_log=1; break; @@ -4844,9 +5006,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE; myisam_concurrent_insert=0; myisam_recover_options= HA_RECOVER_NONE; - my_disable_symlinks=1; my_use_symdir=0; - have_symlink=SHOW_OPTION_DISABLED; ha_open_options&= ~(HA_OPEN_ABORT_IF_CRASHED | HA_OPEN_DELAY_KEY_WRITE); #ifdef HAVE_QUERY_CACHE query_cache_size=0; @@ -4893,9 +5053,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), test_flags|=TEST_NO_STACKTRACE; break; case (int) OPT_SKIP_SYMLINKS: - my_disable_symlinks=1; my_use_symdir=0; - have_symlink=SHOW_OPTION_DISABLED; break; case (int) OPT_BIND_ADDRESS: if (argument && my_isdigit(mysqld_charset, argument[0])) @@ -5141,6 +5299,11 @@ static void get_options(int argc,char **argv) if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) exit(ho_error); + if (argc > 0) + { + fprintf(stderr, "%s: Too many arguments.\nUse --help to get a list of available options\n", my_progname); + exit(ho_error); + } #if defined(HAVE_BROKEN_REALPATH) my_use_symdir=0; @@ -5167,11 +5330,9 @@ static void get_options(int argc,char **argv) my_disable_locking= myisam_single_user= test(opt_external_locking == 0); my_default_record_cache_size=global_system_variables.read_buff_size; myisam_max_temp_length= - (my_off_t) min(global_system_variables.myisam_max_sort_file_size, - (ulonglong) MAX_FILE_SIZE); + (my_off_t) global_system_variables.myisam_max_sort_file_size; myisam_max_extra_temp_length= - (my_off_t) min(global_system_variables.myisam_max_extra_sort_file_size, - (ulonglong) MAX_FILE_SIZE); + (my_off_t) global_system_variables.myisam_max_extra_sort_file_size; /* Set global variables based on startup options */ myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size); diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 550fb772fce..8271d971782 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -48,13 +48,6 @@ can't normally do this the client should have a bigger max_allowed_packet. */ -#ifdef MYSQL_SERVER -#define USE_QUERY_CACHE -extern uint test_flags; -extern void query_cache_insert(NET *net, const char *packet, ulong length); -#else -#endif - #if defined(__WIN__) || !defined(MYSQL_SERVER) /* The following is because alarms doesn't work on windows. */ #define NO_ALARM @@ -63,16 +56,23 @@ extern void query_cache_insert(NET *net, const char *packet, ulong length); #ifndef NO_ALARM #include "my_pthread.h" void sql_print_error(const char *format,...); -extern ulong bytes_sent, bytes_received; -extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; #else -#undef statistic_add -#define statistic_add(A,B,C) #define DONT_USE_THR_ALARM #endif /* NO_ALARM */ #include "thr_alarm.h" +#ifdef MYSQL_SERVER +#define USE_QUERY_CACHE +extern uint test_flags; +extern void query_cache_insert(NET *net, const char *packet, ulong length); +extern ulong bytes_sent, bytes_received; +extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; +#else +#undef statistic_add +#define statistic_add(A,B,C) +#endif + #define TEST_BLOCKING 8 #define MAX_PACKET_LENGTH (256L*256L*256L-1) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 7526772cd09..6c1c49e23fc 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -283,7 +283,7 @@ typedef struct st_qsel_param { KEY_PART *key_parts,*key_parts_end,*key[MAX_KEY]; MEM_ROOT *mem_root; table_map prev_tables,read_tables,current_table; - uint baseflag,keys,max_key_part; + uint baseflag, keys, max_key_part, range_count; uint real_keynr[MAX_KEY]; char min_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH], max_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH]; @@ -379,8 +379,8 @@ SQL_SELECT::~SQL_SELECT() #undef index // Fix for Unixware 7 QUICK_SELECT::QUICK_SELECT(TABLE *table,uint key_nr,bool no_alloc) - :dont_free(0),error(0),index(key_nr),max_used_key_length(0),head(table), - it(ranges),range(0) + :dont_free(0),error(0),index(key_nr),max_used_key_length(0), + used_key_parts(0), head(table), it(ranges),range(0) { if (!no_alloc) { @@ -709,8 +709,10 @@ int SQL_SELECT::test_quick_select(key_map keys_to_use, table_map prev_tables, (double) keys_per_block); } else - found_read_time= head->file->read_time(found_records)+ - (double) found_records / TIME_FOR_COMPARE; + found_read_time= (head->file->read_time(keynr, + param.range_count, + found_records)+ + (double) found_records / TIME_FOR_COMPARE); if (read_time > found_read_time) { read_time=found_read_time; @@ -2074,11 +2076,12 @@ check_quick_select(PARAM *param,uint idx,SEL_ARG *tree) if (!tree) DBUG_RETURN(HA_POS_ERROR); // Can't use it + param->max_key_part=0; + param->range_count=0; if (tree->type == SEL_ARG::IMPOSSIBLE) DBUG_RETURN(0L); // Impossible select. return if (tree->type != SEL_ARG::KEY_RANGE || tree->part != 0) DBUG_RETURN(HA_POS_ERROR); // Don't use tree - param->max_key_part=0; records=check_quick_keys(param,idx,tree,param->min_key,0,param->max_key,0); if (records != HA_POS_ERROR) { @@ -2146,6 +2149,7 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree, } keynr=param->real_keynr[idx]; + param->range_count++; if (!tmp_min_flag && ! tmp_max_flag && (uint) key_tree->part+1 == param->table->key_info[keynr].key_parts && (param->table->key_info[keynr].flags & HA_NOSAME) && @@ -2322,6 +2326,7 @@ get_quick_keys(PARAM *param,QUICK_SELECT *quick,KEY_PART *key, flag); set_if_bigger(quick->max_used_key_length,range->min_length); set_if_bigger(quick->max_used_key_length,range->max_length); + set_if_bigger(quick->used_key_parts, (uint) key_tree->part+1); if (!range) // Not enough memory return 1; quick->ranges.push_back(range); diff --git a/sql/opt_range.h b/sql/opt_range.h index bc56fb99b4b..00736bfc22f 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -70,7 +70,7 @@ class QUICK_SELECT { public: bool next,dont_free; int error; - uint index,max_used_key_length; + uint index, max_used_key_length, used_key_parts; TABLE *head; handler *file; byte *record; diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 1e116518da0..34cce98d087 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -69,8 +69,10 @@ static int maxmin_in_range(bool max_fl, Field* field, COND *cond); RETURN VALUES 0 No errors - 1 if all items was resolved - -1 on impossible conditions + 1 if all items were resolved + -1 on impossible conditions + OR an error number from my_base.h HA_ERR_... if a deadlock or a lock + wait timeout happens, for example */ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) @@ -82,6 +84,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) table_map where_tables= 0; Item *item; COND *org_conds= conds; + int error; if (conds) where_tables= conds->used_tables(); @@ -131,7 +134,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) if (outer_tables || (table->table->file->table_flags() & HA_NOT_EXACT_COUNT)) { - const_result= 0; // Can't optimize left join + const_result= 0; // Can't optimize left join break; } tables->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); @@ -164,6 +167,11 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) Item_field *item_field= ((Item_field*) expr); TABLE *table= item_field->field->table; + if ((table->file->table_flags() & HA_NOT_READ_AFTER_KEY)) + { + const_result=0; + break; + } /* Look for a partial key that can be used for optimization. If we succeed, ref.key_length will contain the length of @@ -179,18 +187,21 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) const_result= 0; break; } - bool error= table->file->index_init((uint) ref.key); + error= table->file->index_init((uint) ref.key); if (!ref.key_length) - error= table->file->index_first(table->record[0]) != 0; + error= table->file->index_first(table->record[0]); else - error= table->file->index_read(table->record[0],key_buff, - ref.key_length, - range_fl & NEAR_MIN ? - HA_READ_AFTER_KEY : - HA_READ_KEY_OR_NEXT) || - reckey_in_range(0, &ref, item_field->field, - conds, range_fl, prefix_len); + { + error= table->file->index_read(table->record[0],key_buff, + ref.key_length, + range_fl & NEAR_MIN ? + HA_READ_AFTER_KEY : + HA_READ_KEY_OR_NEXT); + if (!error && reckey_in_range(0, &ref, item_field->field, + conds, range_fl, prefix_len)) + error= HA_ERR_KEY_NOT_FOUND; + } if (table->key_read) { table->key_read= 0; @@ -198,10 +209,16 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) } table->file->index_end(); if (error) - return -1; // No rows matching where + { + if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE) + return -1; // No rows matching WHERE + /* HA_ERR_LOCK_DEADLOCK or some other error */ + table->file->print_error(error, MYF(0)); + return(error); + } removed_tables|= table->map; } - else if (!expr->const_item()) // This is VERY seldom false + else if (!expr->const_item()) // This is VERY seldom false { const_result= 0; break; @@ -249,18 +266,21 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) const_result= 0; break; } - bool error= table->file->index_init((uint) ref.key); + error= table->file->index_init((uint) ref.key); if (!ref.key_length) - error=table->file->index_last(table->record[0]) != 0; + error= table->file->index_last(table->record[0]); else - error= table->file->index_read(table->record[0], key_buff, - ref.key_length, - range_fl & NEAR_MAX ? - HA_READ_BEFORE_KEY : - HA_READ_PREFIX_LAST_OR_PREV) || - reckey_in_range(1, &ref, item_field->field, - conds, range_fl, prefix_len); + { + error= table->file->index_read(table->record[0], key_buff, + ref.key_length, + range_fl & NEAR_MAX ? + HA_READ_BEFORE_KEY : + HA_READ_PREFIX_LAST_OR_PREV); + if (!error && reckey_in_range(1, &ref, item_field->field, + conds, range_fl, prefix_len)) + error= HA_ERR_KEY_NOT_FOUND; + } if (table->key_read) { table->key_read=0; @@ -268,10 +288,16 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) } table->file->index_end(); if (error) - return -1; // Impossible query + { + if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE) + return -1; // No rows matching WHERE + /* HA_ERR_LOCK_DEADLOCK or some other error */ + table->file->print_error(error, MYF(0)); + return(error); + } removed_tables|= table->map; } - else if (!expr->const_item()) // This is VERY seldom false + else if (!expr->const_item()) // This is VERY seldom false { const_result= 0; break; @@ -597,6 +623,10 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, (if we have a condition field = const, prefix_len contains the length of the whole search key) + NOTE + This function may set table->key_read to 1, which must be reset after + index is used! (This can only happen when function returns 1) + RETURN 0 Index can not be used to optimize MIN(field)/MAX(field) 1 Can use key to optimize MIN()/MAX() diff --git a/sql/protocol.cc b/sql/protocol.cc index d00ecb5dbc4..7abbf3ce85b 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -52,7 +52,7 @@ void send_error(THD *thd, uint sql_errno, const char *err) { #ifndef EMBEDDED_LIBRARY uint length; - char buff[MYSQL_ERRMSG_SIZE+2]; + char buff[MYSQL_ERRMSG_SIZE+2], *pos; #endif NET *net= &thd->net; DBUG_ENTER("send_error"); @@ -98,7 +98,14 @@ void send_error(THD *thd, uint sql_errno, const char *err) if (net->return_errno) { // new client code; Add errno before message int2store(buff,sql_errno); - length= (uint) (strmake(buff+2,err,MYSQL_ERRMSG_SIZE-1) - buff); + pos= buff+2; + if (thd->client_capabilities & CLIENT_PROTOCOL_41) + { + /* The first # is to make the protocol backward compatible */ + strmov(buff+2, "#000000"); + pos= buff + 2 + SQLSTATE_LENGTH +1; + } + length= (uint) (strmake(pos, err, MYSQL_ERRMSG_SIZE-1) - buff); err=buff; } else @@ -113,26 +120,6 @@ void send_error(THD *thd, uint sql_errno, const char *err) DBUG_VOID_RETURN; } -/* - Send an error to the client when a connection is forced close - This is used by mysqld.cc, which doesn't have a THD -*/ - -#ifndef EMBEDDED_LIBRARY -void net_send_error(NET *net, uint sql_errno, const char *err) -{ - char buff[2]; - uint length; - DBUG_ENTER("send_net_error"); - - int2store(buff,sql_errno); - length=(uint) strlen(err); - set_if_smaller(length,MYSQL_ERRMSG_SIZE-1); - net_write_command(net,(uchar) 255, buff, 2, err, length); - DBUG_VOID_RETURN; -} -#endif - /* Send a warning to the end user @@ -173,7 +160,7 @@ net_printf(THD *thd, uint errcode, ...) #ifndef EMBEDDED_LIBRARY const char *text_pos; #else - char text_pos[500]; + char text_pos[1024]; #endif int head_length= NET_HEADER_SIZE; NET *net= &thd->net; @@ -199,9 +186,11 @@ net_printf(THD *thd, uint errcode, ...) format=va_arg(args,char*); errcode= ER_UNKNOWN_ERROR; } - offset= net->return_errno ? 2 : 0; + offset= (net->return_errno ? + ((thd->client_capabilities & CLIENT_PROTOCOL_41) ? + 2+SQLSTATE_LENGTH+1 : 2) : 0); #ifndef EMBEDDED_LIBRARY - text_pos=(char*) net->buff+head_length+offset+1; + text_pos=(char*) net->buff + head_length + offset + 1; #endif (void) vsprintf(my_const_cast(char*) (text_pos),format,args); length=(uint) strlen((char*) text_pos); @@ -228,7 +217,15 @@ net_printf(THD *thd, uint errcode, ...) net->buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); net->buff[head_length]=(uchar) 255; // Error package if (offset) - int2store(text_pos-2, errcode); + { + uchar *pos= net->buff+head_length+1; + int2store(pos, errcode); + if (thd->client_capabilities & CLIENT_PROTOCOL_41) + { + /* The first # is to make the protocol backward compatible */ + memcpy(pos+2, "#000000", SQLSTATE_LENGTH +1); + } + } VOID(net_real_write(net,(char*) net->buff,length+head_length+1+offset)); #else net->last_errno= errcode; @@ -502,6 +499,7 @@ bool Protocol::send_fields(List<Item> *list, uint flag) String tmp((char*) buff,sizeof(buff),&my_charset_bin); Protocol_simple prot(thd); String *packet= prot.storage_packet(); + CHARSET_INFO *thd_charset= thd->variables.character_set_results; DBUG_ENTER("send_fields"); if (flag & 1) @@ -526,36 +524,37 @@ bool Protocol::send_fields(List<Item> *list, uint flag) if (thd->client_capabilities & CLIENT_PROTOCOL_41) { - if (prot.store(field.db_name, (uint) strlen(field.db_name), - cs, thd->charset()) || + if (prot.store("std", 3, cs, thd_charset) || + prot.store(field.db_name, (uint) strlen(field.db_name), + cs, thd_charset) || prot.store(field.table_name, (uint) strlen(field.table_name), - cs, thd->charset()) || + cs, thd_charset) || prot.store(field.org_table_name, (uint) strlen(field.org_table_name), - cs, thd->charset()) || + cs, thd_charset) || prot.store(field.col_name, (uint) strlen(field.col_name), - cs, thd->charset()) || + cs, thd_charset) || prot.store(field.org_col_name, (uint) strlen(field.org_col_name), - cs, thd->charset()) || + cs, thd_charset) || packet->realloc(packet->length()+12)) goto err; /* Store fixed length fields */ pos= (char*) packet->ptr()+packet->length(); - *pos++= 11; // Length of packed fields + *pos++= 12; // Length of packed fields int2store(pos, field.charsetnr); - int3store(pos+2, field.length); - pos[5]= field.type; - int2store(pos+6,field.flags); - pos[8]= (char) field.decimals; - pos[9]= 0; // For the future + int4store(pos+2, field.length); + pos[6]= field.type; + int2store(pos+7,field.flags); + pos[9]= (char) field.decimals; pos[10]= 0; // For the future - pos+= 11; + pos[11]= 0; // For the future + pos+= 12; } else { if (prot.store(field.table_name, (uint) strlen(field.table_name), - cs, thd->charset()) || + cs, thd_charset) || prot.store(field.col_name, (uint) strlen(field.col_name), - cs, thd->charset()) || + cs, thd_charset) || packet->realloc(packet->length()+10)) goto err; pos= (char*) packet->ptr()+packet->length(); @@ -709,7 +708,7 @@ bool Protocol_simple::store(const char *from, uint length, field_types[field_pos] <= MYSQL_TYPE_GEOMETRY)); field_pos++; #endif - if (!my_charset_same(fromcs, tocs) && + if (tocs && !my_charset_same(fromcs, tocs) && (fromcs != &my_charset_bin) && (tocs != &my_charset_bin)) { @@ -724,7 +723,7 @@ bool Protocol_simple::store(const char *from, uint length, bool Protocol_simple::store(const char *from, uint length, CHARSET_INFO *fromcs) { - CHARSET_INFO *tocs= this->thd->variables.collation_results; + CHARSET_INFO *tocs= this->thd->variables.character_set_results; #ifndef DEBUG_OFF DBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_DECIMAL || @@ -732,7 +731,7 @@ bool Protocol_simple::store(const char *from, uint length, field_types[field_pos] <= MYSQL_TYPE_GEOMETRY)); field_pos++; #endif - if (!my_charset_same(fromcs, tocs) && + if (tocs && !my_charset_same(fromcs, tocs) && (fromcs != &my_charset_bin) && (tocs != &my_charset_bin)) { @@ -831,12 +830,14 @@ bool Protocol_simple::store(Field *field) #endif char buff[MAX_FIELD_WIDTH]; String str(buff,sizeof(buff), &my_charset_bin); + CHARSET_INFO *tocs= this->thd->variables.character_set_results; + field->val_str(&str,&str); - if (!my_charset_same(field->charset(), this->thd->charset()) && + if (tocs && !my_charset_same(field->charset(), tocs) && (field->charset() != &my_charset_bin) && - (this->thd->charset() != &my_charset_bin)) + (tocs != &my_charset_bin)) { - convert.copy(str.ptr(), str.length(), str.charset(), this->thd->charset()); + convert.copy(str.ptr(), str.length(), str.charset(), tocs); return net_store_data(convert.ptr(), convert.length()); } else @@ -891,9 +892,10 @@ bool Protocol_simple::store_time(TIME *tm) #endif char buff[40]; uint length; + uint day= (tm->year || tm->month) ? 0 : tm->day; length= my_sprintf(buff,(buff, "%s%02ld:%02d:%02d", tm->neg ? "-" : "", - (long) tm->day*3600L+(long) tm->hour, + (long) day*24L+(long) tm->hour, (int) tm->minute, (int) tm->second)); return net_store_data((char*) buff, length); diff --git a/sql/protocol.h b/sql/protocol.h index dd644afd335..ffd61b3e848 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -60,6 +60,8 @@ public: { return store_longlong((longlong) from, 0); } inline bool store(ulonglong from) { return store_longlong((longlong) from, 1); } + inline bool store(String *str) + { return store(str->c_ptr(),str->length(),str->charset()); } virtual bool prepare_for_send(List<Item> *item_list) { @@ -162,7 +164,6 @@ void net_printf(THD *thd,uint sql_errno, ...); void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L, const char *info=0); void send_eof(THD *thd, bool no_flush=0); -void net_send_error(NET *net, uint sql_errno, const char *err); char *net_store_length(char *packet,ulonglong length); char *net_store_length(char *packet,uint length); char *net_store_data(char *to,const char *from, uint length); diff --git a/sql/records.cc b/sql/records.cc index 9d8627bc1fc..783ca663dfe 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -16,7 +16,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Functions to read, write and lock records */ +/* Functions for easy reading of records, possible through a cache */ #include "mysql_priv.h" diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 58769827bed..bbfd7866aa2 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -23,7 +23,6 @@ #include "sql_repl.h" #include "slave.h" #include "sql_acl.h" -#include "mini_client.h" #include "log_event.h" #include <mysql.h> @@ -72,7 +71,7 @@ static int init_failsafe_rpl_thread(THD* thd) if (init_thr_lock() || thd->store_globals()) { - close_connection(&thd->net,ER_OUT_OF_RESOURCES); // is this needed? + close_connection(thd, ER_OUT_OF_RESOURCES, 1); // is this needed? end_thread(thd,0); DBUG_RETURN(-1); } @@ -484,14 +483,15 @@ int update_slave_list(MYSQL* mysql, MASTER_INFO* mi) int port_ind; DBUG_ENTER("update_slave_list"); - if (mc_mysql_query(mysql,"SHOW SLAVE HOSTS",16) || - !(res = mc_mysql_store_result(mysql))) + + if (mysql_real_query(mysql,"SHOW SLAVE HOSTS",16) || + !(res = mysql_store_result(mysql))) { - error= mc_mysql_error(mysql); + error= mysql_error(mysql); goto err; } - switch (mc_mysql_num_fields(res)) { + switch (mysql_num_fields(res)) { case 5: have_auth_info = 0; port_ind=2; @@ -508,7 +508,7 @@ HOSTS"; pthread_mutex_lock(&LOCK_slave_list); - while ((row= mc_mysql_fetch_row(res))) + while ((row= mysql_fetch_row(res))) { uint32 server_id; SLAVE_INFO* si, *old_si; @@ -541,7 +541,7 @@ HOSTS"; err: if (res) - mc_mysql_free_result(res); + mysql_free_result(res); if (error) { sql_print_error("While trying to obtain the list of slaves from the master \ @@ -566,7 +566,7 @@ pthread_handler_decl(handle_failsafe_rpl,arg) thd->thread_stack = (char*)&thd; MYSQL* recovery_captain = 0; pthread_detach_this_thread(); - if (init_failsafe_rpl_thread(thd) || !(recovery_captain=mc_mysql_init(0))) + if (init_failsafe_rpl_thread(thd) || !(recovery_captain=mysql_init(0))) { sql_print_error("Could not initialize failsafe replication thread"); goto err; @@ -599,7 +599,7 @@ pthread_handler_decl(handle_failsafe_rpl,arg) pthread_mutex_unlock(&LOCK_rpl_status); err: if (recovery_captain) - mc_mysql_close(recovery_captain); + mysql_close(recovery_captain); delete thd; my_thread_end(); pthread_exit(0); @@ -668,9 +668,10 @@ int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi) strmov(mysql->net.last_error, "Master is not configured"); DBUG_RETURN(1); } - if (!mc_mysql_connect(mysql, mi->host, mi->user, mi->password, 0, - mi->port, 0, 0, - slave_net_timeout)) + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&slave_net_timeout); + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (char *)default_charset_info); + if (!mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0, + mi->port, 0, 0)) DBUG_RETURN(1); DBUG_RETURN(0); } @@ -682,9 +683,9 @@ static inline void cleanup_mysql_results(MYSQL_RES* db_res, for (; cur >= start; --cur) { if (*cur) - mc_mysql_free_result(*cur); + mysql_free_result(*cur); } - mc_mysql_free_result(db_res); + mysql_free_result(db_res); } @@ -692,8 +693,8 @@ static int fetch_db_tables(THD *thd, MYSQL *mysql, const char *db, MYSQL_RES *table_res, MASTER_INFO *mi) { MYSQL_ROW row; - for (row = mc_mysql_fetch_row(table_res); row; - row = mc_mysql_fetch_row(table_res)) + for (row = mysql_fetch_row(table_res); row; + row = mysql_fetch_row(table_res)) { TABLE_LIST table; const char* table_name= row[0]; @@ -727,7 +728,7 @@ int load_master_data(THD* thd) int error = 0; const char* errmsg=0; int restart_thread_mask; - mc_mysql_init(&mysql); + mysql_init(&mysql); /* We do not want anyone messing with the slave at all for the entire @@ -749,7 +750,7 @@ int load_master_data(THD* thd) if (connect_to_master(thd, &mysql, active_mi)) { net_printf(thd, error= ER_CONNECT_TO_MASTER, - mc_mysql_error(&mysql)); + mysql_error(&mysql)); goto err; } @@ -758,15 +759,15 @@ int load_master_data(THD* thd) MYSQL_RES *db_res, **table_res, **table_res_end, **cur_table_res; uint num_dbs; - if (mc_mysql_query(&mysql, "SHOW DATABASES", 14) || - !(db_res = mc_mysql_store_result(&mysql))) + if (mysql_real_query(&mysql, "SHOW DATABASES", 14) || + !(db_res = mysql_store_result(&mysql))) { net_printf(thd, error = ER_QUERY_ON_MASTER, - mc_mysql_error(&mysql)); + mysql_error(&mysql)); goto err; } - if (!(num_dbs = (uint) mc_mysql_num_rows(db_res))) + if (!(num_dbs = (uint) mysql_num_rows(db_res))) goto err; /* In theory, the master could have no databases at all @@ -785,12 +786,12 @@ int load_master_data(THD* thd) we wait to issue FLUSH TABLES WITH READ LOCK for as long as we can to minimize the lock time. */ - if (mc_mysql_query(&mysql, "FLUSH TABLES WITH READ LOCK", 27) || - mc_mysql_query(&mysql, "SHOW MASTER STATUS",18) || - !(master_status_res = mc_mysql_store_result(&mysql))) + if (mysql_real_query(&mysql, "FLUSH TABLES WITH READ LOCK", 27) || + mysql_real_query(&mysql, "SHOW MASTER STATUS",18) || + !(master_status_res = mysql_store_result(&mysql))) { net_printf(thd, error = ER_QUERY_ON_MASTER, - mc_mysql_error(&mysql)); + mysql_error(&mysql)); goto err; } @@ -805,7 +806,7 @@ int load_master_data(THD* thd) cur_table_res++) { // since we know how many rows we have, this can never be NULL - MYSQL_ROW row = mc_mysql_fetch_row(db_res); + MYSQL_ROW row = mysql_fetch_row(db_res); char* db = row[0]; /* @@ -834,12 +835,12 @@ int load_master_data(THD* thd) goto err; } - if (mc_mysql_select_db(&mysql, db) || - mc_mysql_query(&mysql, "SHOW TABLES", 11) || - !(*cur_table_res = mc_mysql_store_result(&mysql))) + if (mysql_select_db(&mysql, db) || + mysql_real_query(&mysql, "SHOW TABLES", 11) || + !(*cur_table_res = mysql_store_result(&mysql))) { net_printf(thd, error = ER_QUERY_ON_MASTER, - mc_mysql_error(&mysql)); + mysql_error(&mysql)); cleanup_mysql_results(db_res, cur_table_res - 1, table_res); goto err; } @@ -857,7 +858,7 @@ int load_master_data(THD* thd) // adjust position in the master if (master_status_res) { - MYSQL_ROW row = mc_mysql_fetch_row(master_status_res); + MYSQL_ROW row = mysql_fetch_row(master_status_res); /* We need this check because the master may not be running with @@ -875,13 +876,13 @@ int load_master_data(THD* thd) active_mi->master_log_pos = BIN_LOG_HEADER_SIZE; flush_master_info(active_mi); } - mc_mysql_free_result(master_status_res); + mysql_free_result(master_status_res); } - if (mc_mysql_query(&mysql, "UNLOCK TABLES", 13)) + if (mysql_real_query(&mysql, "UNLOCK TABLES", 13)) { net_printf(thd, error = ER_QUERY_ON_MASTER, - mc_mysql_error(&mysql)); + mysql_error(&mysql)); goto err; } } @@ -920,7 +921,7 @@ err: UNLOCK_ACTIVE_MI; thd->proc_info = 0; - mc_mysql_close(&mysql); // safe to call since we always do mc_mysql_init() + mysql_close(&mysql); // safe to call since we always do mysql_init() if (!error) send_ok(thd); diff --git a/sql/set_var.cc b/sql/set_var.cc index e4adbb0a318..60b0d24430d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -87,6 +87,8 @@ static void fix_max_join_size(THD *thd, enum_var_type type); static void fix_query_cache_size(THD *thd, enum_var_type type); static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type); static void fix_key_buffer_size(THD *thd, enum_var_type type); +static void fix_myisam_max_extra_sort_file_size(THD *thd, enum_var_type type); +static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type); static byte *get_error_count(THD *thd); static byte *get_warning_count(THD *thd); @@ -101,13 +103,16 @@ sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size", &binlog_cache_size); sys_var_thd_ulong sys_bulk_insert_buff_size("bulk_insert_buffer_size", &SV::bulk_insert_buff_size); -sys_var_str sys_charset("character_set", +sys_var_character_set_server sys_character_set_server("character_set_server"); +sys_var_str sys_charset_system("character_set_system", sys_check_charset, sys_update_charset, sys_set_default_charset); -sys_var_collation_client sys_collation_client("collation_client"); +sys_var_character_set_database sys_character_set_database("character_set_database"); +sys_var_character_set_client sys_character_set_client("character_set_client"); +sys_var_character_set_connection sys_character_set_connection("character_set_connection"); +sys_var_character_set_results sys_character_set_results("character_set_results"); sys_var_collation_connection sys_collation_connection("collation_connection"); -sys_var_collation_results sys_collation_results("collation_results"); sys_var_bool_ptr sys_concurrent_insert("concurrent_insert", &myisam_concurrent_insert); sys_var_long_ptr sys_connect_timeout("connect_timeout", @@ -184,8 +189,9 @@ sys_var_thd_ulong sys_max_tmp_tables("max_tmp_tables", &SV::max_tmp_tables); sys_var_long_ptr sys_max_write_lock_count("max_write_lock_count", &max_write_lock_count); -sys_var_thd_ulonglong sys_myisam_max_extra_sort_file_size("myisam_max_extra_sort_file_size", &SV::myisam_max_extra_sort_file_size); -sys_var_thd_ulonglong sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size); +sys_var_thd_ulonglong sys_myisam_max_extra_sort_file_size("myisam_max_extra_sort_file_size", &SV::myisam_max_extra_sort_file_size, fix_myisam_max_extra_sort_file_size, 1); +sys_var_thd_ulonglong sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1); +sys_var_thd_ulong sys_myisam_repair_threads("myisam_repair_threads", &SV::myisam_repair_threads); sys_var_thd_ulong sys_myisam_sort_buffer_size("myisam_sort_buffer_size", &SV::myisam_sort_buff_size); sys_var_thd_ulong sys_net_buffer_length("net_buffer_length", &SV::net_buffer_length); @@ -229,6 +235,7 @@ sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol", sys_var_long_ptr sys_slave_net_timeout("slave_net_timeout", &slave_net_timeout); #endif +sys_var_bool_ptr sys_readonly("read_only", &opt_readonly); sys_var_long_ptr sys_slow_launch_time("slow_launch_time", &slow_launch_time); sys_var_thd_ulong sys_sort_buffer("sort_buffer_size", @@ -249,6 +256,11 @@ sys_var_thd_ulong sys_tmp_table_size("tmp_table_size", &SV::tmp_table_size); sys_var_thd_ulong sys_net_wait_timeout("wait_timeout", &SV::net_wait_timeout); + +#ifdef HAVE_INNOBASE_DB +sys_var_long_ptr sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_pct", + &srv_max_buf_pool_modified_pct); +#endif /* Variables that are bits in THD */ @@ -267,7 +279,7 @@ static sys_var_thd_bit sys_sql_big_tables("sql_big_tables", #endif static sys_var_thd_bit sys_big_selects("sql_big_selects", set_option_bit, - OPTION_BIG_TABLES); + OPTION_BIG_SELECTS); static sys_var_thd_bit sys_log_off("sql_log_off", set_option_bit, OPTION_LOG_OFF); @@ -349,9 +361,12 @@ sys_var *sys_variables[]= &sys_binlog_cache_size, &sys_buffer_results, &sys_bulk_insert_buff_size, - &sys_collation_client, + &sys_character_set_server, + &sys_character_set_database, + &sys_character_set_client, + &sys_character_set_connection, + &sys_character_set_results, &sys_collation_connection, - &sys_collation_results, &sys_concurrent_insert, &sys_connect_timeout, &sys_default_week_format, @@ -395,6 +410,7 @@ sys_var *sys_variables[]= &sys_max_write_lock_count, &sys_myisam_max_extra_sort_file_size, &sys_myisam_max_sort_file_size, + &sys_myisam_repair_threads, &sys_myisam_sort_buffer_size, &sys_net_buffer_length, &sys_net_read_timeout, @@ -426,6 +442,7 @@ sys_var *sys_variables[]= &sys_slave_net_timeout, &sys_slave_skip_counter, #endif + &sys_readonly, &sys_slow_launch_time, &sys_sort_buffer, &sys_sql_big_tables, @@ -439,6 +456,9 @@ sys_var *sys_variables[]= &sys_timestamp, &sys_tmp_table_size, &sys_tx_isolation, +#ifdef HAVE_INNOBASE_DB + &sys_innodb_max_dirty_pages_pct, +#endif &sys_unique_checks, &sys_warning_count }; @@ -463,11 +483,13 @@ struct show_var_st init_vars[]= { #endif {sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size, SHOW_SYS}, {sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS}, - {sys_charset.name, (char*) &sys_charset, SHOW_SYS}, - {"character_sets", (char*) &charsets_list, SHOW_CHAR_PTR}, - {sys_collation_client.name, (char*) &sys_collation_client, SHOW_SYS}, + {sys_character_set_server.name, (char*) &sys_character_set_server,SHOW_SYS}, + {sys_charset_system.name, (char*) &sys_charset_system, SHOW_SYS}, + {sys_character_set_database.name, (char*) &sys_character_set_database,SHOW_SYS}, + {sys_character_set_client.name,(char*) &sys_character_set_client,SHOW_SYS}, + {sys_character_set_connection.name,(char*) &sys_character_set_connection,SHOW_SYS}, + {sys_character_set_results.name,(char*) &sys_character_set_results, SHOW_SYS}, {sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS}, - {sys_collation_results.name, (char*) &sys_collation_results, SHOW_SYS}, {sys_concurrent_insert.name,(char*) &sys_concurrent_insert, SHOW_SYS}, {sys_connect_timeout.name, (char*) &sys_connect_timeout, SHOW_SYS}, {"datadir", mysql_real_data_home, SHOW_CHAR}, @@ -514,6 +536,7 @@ struct show_var_st init_vars[]= { {"innodb_log_files_in_group", (char*) &innobase_log_files_in_group, SHOW_LONG}, {"innodb_log_group_home_dir", (char*) &innobase_log_group_home_dir, SHOW_CHAR_PTR}, {"innodb_mirrored_log_groups", (char*) &innobase_mirrored_log_groups, SHOW_LONG}, + {sys_innodb_max_dirty_pages_pct.name, (char*) &sys_innodb_max_dirty_pages_pct, SHOW_SYS}, #endif {sys_interactive_timeout.name,(char*) &sys_interactive_timeout, SHOW_SYS}, {sys_join_buffer_size.name, (char*) &sys_join_buffer_size, SHOW_SYS}, @@ -550,13 +573,14 @@ struct show_var_st init_vars[]= { {sys_max_prep_stmt_count.name,(char*) &sys_max_prep_stmt_count, SHOW_SYS}, {sys_max_sort_length.name, (char*) &sys_max_sort_length, SHOW_SYS}, {sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS}, - {sys_max_tmp_tables.name, (char*) &sys_max_tmp_tables, SHOW_SYS}, + {sys_max_tmp_tables.name, (char*) &sys_max_tmp_tables, SHOW_SYS}, {sys_max_write_lock_count.name, (char*) &sys_max_write_lock_count,SHOW_SYS}, {sys_myisam_max_extra_sort_file_size.name, (char*) &sys_myisam_max_extra_sort_file_size, SHOW_SYS}, - {sys_myisam_max_sort_file_size.name, - (char*) &sys_myisam_max_sort_file_size, + {sys_myisam_max_sort_file_size.name, (char*) &sys_myisam_max_sort_file_size, + SHOW_SYS}, + {sys_myisam_repair_threads.name, (char*) &sys_myisam_repair_threads, SHOW_SYS}, {"myisam_recover_options", (char*) &myisam_recover_options_str, SHOW_CHAR_PTR}, {sys_myisam_sort_buffer_size.name, (char*) &sys_myisam_sort_buffer_size, SHOW_SYS}, @@ -595,6 +619,7 @@ struct show_var_st init_vars[]= { #ifdef HAVE_REPLICATION {sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout, SHOW_SYS}, #endif + {sys_readonly.name, (char*) &sys_readonly, SHOW_SYS}, {"skip_external_locking", (char*) &my_disable_locking, SHOW_MY_BOOL}, {"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL}, {"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL}, @@ -661,6 +686,21 @@ static void fix_low_priority_updates(THD *thd, enum_var_type type) } +static void +fix_myisam_max_extra_sort_file_size(THD *thd, enum_var_type type) +{ + myisam_max_extra_temp_length= + (my_off_t) global_system_variables.myisam_max_extra_sort_file_size; +} + + +static void +fix_myisam_max_sort_file_size(THD *thd, enum_var_type type) +{ + myisam_max_temp_length= + (my_off_t) global_system_variables.myisam_max_sort_file_size; +} + /* Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR */ @@ -911,15 +951,22 @@ byte *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type) bool sys_var_thd_ulonglong::update(THD *thd, set_var *var) { + ulonglong tmp= var->value->val_int(); + + if ((ulonglong) tmp > max_system_variables.*offset) + tmp= max_system_variables.*offset; + + if (option_limits) + tmp= (ulong) getopt_ull_limit_value(tmp, option_limits); if (var->type == OPT_GLOBAL) { /* Lock is needed to make things safe on 32 bit systems */ pthread_mutex_lock(&LOCK_global_system_variables); - global_system_variables.*offset= var->value->val_int(); + global_system_variables.*offset= (ulonglong) tmp; pthread_mutex_unlock(&LOCK_global_system_variables); } else - thd->variables.*offset= var->value->val_int(); + thd->variables.*offset= (ulonglong) tmp; return 0; } @@ -1010,6 +1057,7 @@ err: bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names) { + bool not_used; char buff[80], *error= 0; uint error_len= 0; String str(buff, sizeof(buff), system_charset_info), *res; @@ -1019,7 +1067,7 @@ bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names) if (!(res= var->value->val_str(&str))) goto err; var->save_result.ulong_value= (ulong) - find_set(enum_names, res->c_ptr(), res->length(), &error, &error_len); + find_set(enum_names, res->c_ptr(), res->length(), &error, &error_len, ¬_used); if (error_len) { strmake(buff, error, min(sizeof(buff), error_len)); @@ -1202,7 +1250,7 @@ CHARSET_INFO *get_old_charset_by_name(const char *name) for (c= old_conv; c->old_name; c++) { if (!my_strcasecmp(&my_charset_latin1,name,c->old_name)) - return get_charset_by_name(c->new_name,MYF(0)); + return get_charset_by_csname(c->new_name,MY_CS_PRIMARY,MYF(0)); } return NULL; } @@ -1216,7 +1264,31 @@ bool sys_var_collation::check(THD *thd, set_var *var) if (!(res=var->value->val_str(&str))) res= &empty_string; - if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))) && + if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0)))) + { + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); + return 1; + } + var->save_result.charset= tmp; // Save for update + return 0; +} + +bool sys_var_character_set::check(THD *thd, set_var *var) +{ + CHARSET_INFO *tmp; + char buff[80]; + String str(buff,sizeof(buff), system_charset_info), *res; + + if (!(res=var->value->val_str(&str))) + { + if (!nullable) + { + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "NULL"); + return 1; + } + tmp= NULL; + } + else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && !(tmp=get_old_charset_by_name(res->c_ptr()))) { my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); @@ -1226,83 +1298,127 @@ bool sys_var_collation::check(THD *thd, set_var *var) return 0; } -bool sys_var_collation_client::update(THD *thd, set_var *var) +bool sys_var_character_set::update(THD *thd, set_var *var) { - if (var->type == OPT_GLOBAL) - global_system_variables.collation_client= var->save_result.charset; - else - thd->variables.collation_client= var->save_result.charset; + ci_ptr(thd,var->type)[0]= var->save_result.charset; return 0; } -byte *sys_var_collation_client::value_ptr(THD *thd, enum_var_type type) +byte *sys_var_character_set::value_ptr(THD *thd, enum_var_type type) { - CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? - global_system_variables.collation_client : - thd->variables.collation_client); - return cs ? (byte*) cs->name : (byte*) ""; + CHARSET_INFO *cs= ci_ptr(thd,type)[0]; + return cs ? (byte*) cs->csname : (byte*) "NULL"; } -void sys_var_collation_client::set_default(THD *thd, enum_var_type type) + +CHARSET_INFO ** sys_var_character_set_connection::ci_ptr(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + return &global_system_variables.collation_connection; + else + return &thd->variables.collation_connection; +} + +void sys_var_character_set_connection::set_default(THD *thd, enum_var_type type) { if (type == OPT_GLOBAL) - global_system_variables.collation_client= default_charset_info; + global_system_variables.collation_connection= default_charset_info; else - thd->variables.collation_client= global_system_variables.collation_client; + thd->variables.collation_connection= global_system_variables.collation_connection; } -bool sys_var_collation_connection::update(THD *thd, set_var *var) +CHARSET_INFO ** sys_var_character_set_client::ci_ptr(THD *thd, enum_var_type type) { - if (var->type == OPT_GLOBAL) - global_system_variables.collation_connection= var->save_result.charset; + if (type == OPT_GLOBAL) + return &global_system_variables.character_set_client; else - thd->variables.collation_connection= var->save_result.charset; - return 0; + return &thd->variables.character_set_client; } -byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type) +void sys_var_character_set_client::set_default(THD *thd, enum_var_type type) { - CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? - global_system_variables.collation_connection : - thd->variables.collation_connection); - return cs ? (byte*) cs->name : (byte*) ""; + if (type == OPT_GLOBAL) + global_system_variables.character_set_client= default_charset_info; + else + thd->variables.character_set_client= global_system_variables.character_set_client; } -void sys_var_collation_connection::set_default(THD *thd, enum_var_type type) +CHARSET_INFO ** sys_var_character_set_results::ci_ptr(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + return &global_system_variables.character_set_results; + else + return &thd->variables.character_set_results; +} + +void sys_var_character_set_results::set_default(THD *thd, enum_var_type type) { if (type == OPT_GLOBAL) - global_system_variables.collation_connection= default_charset_info; + global_system_variables.character_set_results= default_charset_info; else - thd->variables.collation_connection= global_system_variables.collation_connection; + thd->variables.character_set_results= global_system_variables.character_set_results; +} + +CHARSET_INFO ** sys_var_character_set_server::ci_ptr(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + return &global_system_variables.character_set_server; + else + return &thd->variables.character_set_server; } -bool sys_var_collation_results::update(THD *thd, set_var *var) +void sys_var_character_set_server::set_default(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + global_system_variables.character_set_server= default_charset_info; + else + thd->variables.character_set_server= global_system_variables.character_set_server; +} + +CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + return &global_system_variables.character_set_database; + else + return &thd->variables.character_set_database; +} + +void sys_var_character_set_database::set_default(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + global_system_variables.character_set_database= default_charset_info; + else + thd->variables.character_set_database= thd->db_charset; +} + +bool sys_var_collation_connection::update(THD *thd, set_var *var) { if (var->type == OPT_GLOBAL) - global_system_variables.collation_results= var->save_result.charset; + global_system_variables.collation_connection= var->save_result.charset; else - thd->variables.collation_results= var->save_result.charset; + thd->variables.collation_connection= var->save_result.charset; return 0; } -byte *sys_var_collation_results::value_ptr(THD *thd, enum_var_type type) +byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type) { CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? - global_system_variables.collation_results : - thd->variables.collation_results); - return cs ? (byte*) cs->name : (byte*) ""; + global_system_variables.collation_connection : + thd->variables.collation_connection); + return cs ? (byte*) cs->name : (byte*) "NULL"; } -void sys_var_collation_results::set_default(THD *thd, enum_var_type type) +void sys_var_collation_connection::set_default(THD *thd, enum_var_type type) { if (type == OPT_GLOBAL) - global_system_variables.collation_results= default_charset_info; + global_system_variables.collation_connection= default_charset_info; else - thd->variables.collation_results= global_system_variables.collation_results; + thd->variables.collation_connection= global_system_variables.collation_connection; } + /***************************************************************************** Functions to handle SET NAMES and SET CHARACTER SET *****************************************************************************/ @@ -1314,9 +1430,9 @@ int set_var_collation_client::check(THD *thd) int set_var_collation_client::update(THD *thd) { - thd->variables.collation_client= collation_client; + thd->variables.character_set_client= character_set_client; + thd->variables.character_set_results= character_set_results; thd->variables.collation_connection= collation_connection; - thd->variables.collation_results= collation_results; thd->protocol_simple.init(thd); thd->protocol_prep.init(thd); return 0; @@ -1635,7 +1751,7 @@ sys_var *find_sys_var(const char *str, uint length) int sql_set_variables(THD *thd, List<set_var_base> *var_list) { int error= 0; - List_iterator<set_var_base> it(*var_list); + List_iterator_fast<set_var_base> it(*var_list); set_var_base *var; while ((var=it++)) @@ -1751,5 +1867,5 @@ int set_var_password::update(THD *thd) #ifdef __GNUC__ template class List<set_var_base>; -template class List_iterator<set_var_base>; +template class List_iterator_fast<set_var_base>; #endif diff --git a/sql/set_var.h b/sql/set_var.h index fbd20228d24..d016c3a7085 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -235,17 +235,27 @@ class sys_var_thd_ulonglong :public sys_var_thd { public: ulonglong SV::*offset; + bool only_global; sys_var_thd_ulonglong(const char *name_arg, ulonglong SV::*offset_arg) :sys_var_thd(name_arg), offset(offset_arg) {} sys_var_thd_ulonglong(const char *name_arg, ulonglong SV::*offset_arg, - sys_after_update_func func) - :sys_var_thd(name_arg,func), offset(offset_arg) + sys_after_update_func func, bool only_global_arg) + :sys_var_thd(name_arg, func), offset(offset_arg), + only_global(only_global_arg) {} bool update(THD *thd, set_var *var); void set_default(THD *thd, enum_var_type type); SHOW_TYPE type() { return SHOW_LONGLONG; } byte *value_ptr(THD *thd, enum_var_type type); + bool check_default(enum_var_type type) + { + return type == OPT_GLOBAL && !option_limits; + } + bool check_type(enum_var_type type) + { + return (only_global && type != OPT_GLOBAL); + } }; @@ -420,34 +430,80 @@ SHOW_TYPE type() { return SHOW_CHAR; } virtual void set_default(THD *thd, enum_var_type type)= 0; }; -class sys_var_collation_client :public sys_var_collation +class sys_var_character_set :public sys_var_thd { public: - sys_var_collation_client(const char *name_arg) :sys_var_collation(name_arg) {} + bool nullable; + sys_var_character_set(const char *name_arg) :sys_var_thd(name_arg) + { nullable= 0; } + bool check(THD *thd, set_var *var); +SHOW_TYPE type() { return SHOW_CHAR; } + bool check_update_type(Item_result type) + { + return type != STRING_RESULT; /* Only accept strings */ + } + bool check_default(enum_var_type type) { return 0; } bool update(THD *thd, set_var *var); - void set_default(THD *thd, enum_var_type type); byte *value_ptr(THD *thd, enum_var_type type); + virtual void set_default(THD *thd, enum_var_type type)= 0; + virtual CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type)= 0; }; -class sys_var_collation_connection :public sys_var_collation +class sys_var_character_set_client :public sys_var_character_set { public: - sys_var_collation_connection(const char *name_arg) :sys_var_collation(name_arg) {} - bool update(THD *thd, set_var *var); + sys_var_character_set_client(const char *name_arg) : + sys_var_character_set(name_arg) {} void set_default(THD *thd, enum_var_type type); - byte *value_ptr(THD *thd, enum_var_type type); + CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type); }; -class sys_var_collation_results :public sys_var_collation +class sys_var_character_set_results :public sys_var_character_set { public: - sys_var_collation_results(const char *name_arg) :sys_var_collation(name_arg) {} + sys_var_character_set_results(const char *name_arg) : + sys_var_character_set(name_arg) + { nullable= 1; } + void set_default(THD *thd, enum_var_type type); + CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type); +}; + +class sys_var_character_set_server :public sys_var_character_set +{ +public: + sys_var_character_set_server(const char *name_arg) : + sys_var_character_set(name_arg) {} + void set_default(THD *thd, enum_var_type type); + CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type); +}; + +class sys_var_character_set_database :public sys_var_character_set +{ +public: + sys_var_character_set_database(const char *name_arg) : + sys_var_character_set(name_arg) {} + void set_default(THD *thd, enum_var_type type); + CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type); +}; + +class sys_var_character_set_connection :public sys_var_character_set +{ +public: + sys_var_character_set_connection(const char *name_arg) : + sys_var_character_set(name_arg) {} + void set_default(THD *thd, enum_var_type type); + CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type); +}; + +class sys_var_collation_connection :public sys_var_collation +{ +public: + sys_var_collation_connection(const char *name_arg) :sys_var_collation(name_arg) {} bool update(THD *thd, set_var *var); void set_default(THD *thd, enum_var_type type); byte *value_ptr(THD *thd, enum_var_type type); }; - /* Variable that you can only read from */ class sys_var_readonly: public sys_var @@ -555,16 +611,16 @@ public: class set_var_collation_client: public set_var_base { - CHARSET_INFO *collation_client; + CHARSET_INFO *character_set_client; + CHARSET_INFO *character_set_results; CHARSET_INFO *collation_connection; - CHARSET_INFO *collation_results; public: set_var_collation_client(CHARSET_INFO *client_coll_arg, CHARSET_INFO *connection_coll_arg, CHARSET_INFO *result_coll_arg) - :collation_client(client_coll_arg), - collation_connection(connection_coll_arg), - collation_results(result_coll_arg) + :character_set_client(client_coll_arg), + character_set_results(result_coll_arg), + collation_connection(connection_coll_arg) {} int check(THD *thd); int update(THD *thd); @@ -581,5 +637,5 @@ sys_var *find_sys_var(const char *str, uint length=0); int sql_set_variables(THD *thd, List<set_var_base> *var_list); void fix_delay_key_write(THD *thd, enum_var_type type); -extern sys_var_str sys_charset; +extern sys_var_str sys_charset_system; CHARSET_INFO *get_old_charset_by_name(const char *old_name); diff --git a/sql/share/charsets/Index.xml b/sql/share/charsets/Index.xml index 9b95326fe9e..6e091066654 100644 --- a/sql/share/charsets/Index.xml +++ b/sql/share/charsets/Index.xml @@ -1,6 +1,6 @@ <?xml version='1.0' encoding="utf-8"?> -<charsets max-id="83"> +<charsets max-id="91"> <description> This file lists all of the available character sets. @@ -19,7 +19,11 @@ To make maintaining easier please: <alias>csbig5</alias> <collation name="big5_chinese_ci" id="1" order="Chinese"> <flag>primary</flag> - <flag>compiled"</flag> + <flag>compiled</flag> + </collation> + <collation name="big5_bin" id="84" order="Binary"> + <flag>binary</flag> + <flag>compiled</flag> </collation> </charset> @@ -96,7 +100,10 @@ To make maintaining easier please: <collation name="latin1_swedish_ci" id="8" order="Finnish, Swedish" flag="primary"/> <collation name="latin1_danish_ci" id="15" order="Danish"/> <collation name="latin1_german2_ci" id="31" order="German Phonebook" flag="compiled"/> - <collation name="latin1_bin" id="47" order="Binary" flag="binary"/> + <collation name="latin1_bin" id="47" order="Binary"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> <collation name="latin1_general_ci" id="48"> <order>Dutch</order> <order>English</order> @@ -169,7 +176,14 @@ To make maintaining easier please: <family>Japanese</family> <description>EUC-JP Japanese</description> <alias>euc-jp</alias> - <collation name="ujis_japanese_ci" id="12" order="Japanese" flag="primary"/> + <collation name="ujis_japanese_ci" id="12" order="Japanese"> + <flag>primary</flag> + <flag>compiled</flag> + </collation> + <collation name="ujis_bin" id="91" order="Japanese"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> </charset> <charset name="sjis"> @@ -178,7 +192,14 @@ To make maintaining easier please: <alias>s-jis</alias> <alias>shift-jis</alias> <alias>x-sjis</alias> - <collation name="sjis_japanese_ci" id="13" order="Japanese" flag="primary"/> + <collation name="sjis_japanese_ci" id="13" order="Japanese"> + <flag>primary</flag> + <flag>compiled</flag> + </collation> + <collation name="sjis_bin" id="88" order="Binary"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> </charset> <charset name="cp1251"> @@ -236,6 +257,10 @@ To make maintaining easier please: <flag>primary</flag> <flag>compiled</flag> </collation> + <collation name="tis620_bin" id="89" order="Binary"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> </charset> <charset name="euckr"> @@ -245,7 +270,11 @@ To make maintaining easier please: <alias>euc-kr</alias> <collation name="euckr_korean_ci" id="19" order="Korean"> <flag>primary</flag> - <flag>compiled"</flag> + <flag>compiled</flag> + </collation> + <collation name="euckr_bin" id="85"> + <flag>binary</flag> + <flag>compiled</flag> </collation> </charset> @@ -255,7 +284,7 @@ To make maintaining easier please: <alias>BalticRim</alias> <alias>iso-8859-13</alias> <alias>l7</alias> - <collation name="latin7_estonian_ci" id="20"> + <collation name="latin7_estonian_cs" id="20"> <order>Estonian</order> </collation> <collation name="latin7_general_ci" id="41"> @@ -285,7 +314,11 @@ To make maintaining easier please: <alias>iso-ir-58</alias> <collation name="gb2312_chinese_ci" id="24" order="Chinese"> <flag>primary</flag> - <flag>compiled"</flag> + <flag>compiled</flag> + </collation> + <collation name="gb2312_bin" id="86"> + <flag>binary</flag> + <flag>compiled</flag> </collation> </charset> @@ -315,7 +348,9 @@ To make maintaining easier please: <order>Slovenian</order> <order>Sorbian</order> </collation> - <collation name="cp1250_czech_ci" id="34" order="Czech"/> + <collation name="cp1250_czech_ci" id="34" order="Czech"> + <flag>compiled</flag> + </collation> <collation name="cp1250_bin" id="66" order="Binary" flag="binary"/> </charset> @@ -327,6 +362,10 @@ To make maintaining easier please: <flag>primary</flag> <flag>compiled</flag> </collation> + <collation name="gbk_bin" id="87" order="Binary"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> </charset> <charset name="cp1257"> @@ -369,14 +408,27 @@ To make maintaining easier please: <family>Unicode</family> <description>UTF-8 Unicode</description> <alias>utf-8</alias> - <collation name="utf8_general_ci" id="33" flag="primary"/> - <collation name="utf8_bin" id="83" flag="binary"/> + <collation name="utf8_general_ci" id="33"> + <flag>primary</flag> + <flag>compiled</flag> + </collation> + <collation name="utf8_bin" id="83"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> </charset> <charset name="ucs2"> <family>Unicode</family> <description>UCS-2 Unicode</description> - <collation name="ucs2_general_ci" id="35" flag="primary"/> + <collation name="ucs2_general_ci" id="35"> + <flag>primary</flag> + <flag>compiled</flag> + </collation> + <collation name="ucs2_bin" id="90"> + <flag>binary</flag> + <flag>compiled</flag> + </collation> </charset> <charset name="cp866"> diff --git a/sql/share/charsets/latin7.xml b/sql/share/charsets/latin7.xml index d50601b5a90..1c25f5894b6 100644 --- a/sql/share/charsets/latin7.xml +++ b/sql/share/charsets/latin7.xml @@ -93,7 +93,7 @@ </unicode> -<collation name="latin7_estonian_ci"> +<collation name="latin7_estonian_cs"> <map> 00 02 03 04 05 06 07 08 09 2E 2F 30 31 32 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B @@ -115,7 +115,7 @@ </collation> -<collation name="latin7_general_ci"> +<collation name="latin7_general_cs"> <!-- Created for case-sensitive record search --> <!-- by Andis Grasis & Rihards Grasis e-mail:andis@cata.lv --> <map> @@ -139,7 +139,7 @@ </collation> -<collation name="latin7_general_cs"> +<collation name="latin7_general_ci"> <!-- Created for case-insensitive record search --> <!-- Created by Andis & Rihards --> <map> diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index e04d4494a93..e277c19e26f 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -114,7 +114,7 @@ v/* "Blob polo-B¾ka '%-.64s' nemù¾e mít defaultní hodnotu", "Nep-Bøípustné jméno databáze '%-.64s'", "Nep-Bøípustné jméno tabulky '%-.64s'", -"Zadan-Bý SELECT by procházel pøíli¹ mnoho záznamù a trval velmi dlouho. Zkontrolujte tvar WHERE a je-li SELECT v poøádku, pou¾ijte SET OPTION SQL_BIG_SELECTS=1", +"Zadan-Bý SELECT by procházel pøíli¹ mnoho záznamù a trval velmi dlouho. Zkontrolujte tvar WHERE a je-li SELECT v poøádku, pou¾ijte SET SQL_BIG_SELECTS=1", "Nezn-Bámá chyba", "Nezn-Bámá procedura %s", "Chybn-Bý poèet parametrù procedury %s", diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index ff89dbb6bcf..01856ffed01 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -108,7 +108,7 @@ "BLOB feltet '%-.64s' kan ikke have en standard værdi", "Ugyldigt database navn '%-.64s'", "Ugyldigt tabel navn '%-.64s'", -"SELECT ville undersøge for mange poster og ville sandsynligvis tage meget lang tid. Undersøg WHERE delen og brug SET OPTION SQL_BIG_SELECTS=1 hvis udtrykket er korrekt", +"SELECT ville undersøge for mange poster og ville sandsynligvis tage meget lang tid. Undersøg WHERE delen og brug SET SQL_BIG_SELECTS=1 hvis udtrykket er korrekt", "Ukendt fejl", "Ukendt procedure %s", "Forkert antal parametre til proceduren %s", diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index 98ca6a834e4..4b9b0b9f710 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -116,7 +116,7 @@ "Blob veld '%-.64s' can geen standaardwaarde bevatten", "Databasenaam '%-.64s' is niet getoegestaan", "Niet toegestane tabelnaam '%-.64s'", -"Het SELECT-statement zou te veel records analyseren en dus veel tijd in beslagnemen. Kijk het WHERE-gedeelte van de query na en kies SET OPTION SQL_BIG_SELECTS=1 als het stament in orde is.", +"Het SELECT-statement zou te veel records analyseren en dus veel tijd in beslagnemen. Kijk het WHERE-gedeelte van de query na en kies SET SQL_BIG_SELECTS=1 als het stament in orde is.", "Onbekende Fout", "Onbekende procedure %s", "Foutief aantal parameters doorgegeven aan procedure %s", diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index cb709c45326..89045b13985 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -105,7 +105,7 @@ "BLOB column '%-.64s' can't have a default value", "Incorrect database name '%-.100s'", "Incorrect table name '%-.100s'", -"The SELECT would examine too many records and probably take a very long time. Check your WHERE and use SET OPTION SQL_BIG_SELECTS=1 if the SELECT is ok", +"The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok", "Unknown error", "Unknown procedure '%-.64s'", "Incorrect parameter count to procedure '%-.64s'", @@ -249,16 +249,21 @@ "Reference '%-.64s' not supported (%s)", "Every derived table must have it's own alias", "Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", -"Client does not support authentication protocol requested by server. Consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", -"COLLATION '%s' is not valid for CHARACTER SET '%s'", -"The slave was already running", -"The slave was already stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_BUF_ERROR: Not enough memory available for zlib", -"Z_MEM_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Table '%-.64s' from one of SELECT's can not be used in %-.32s" +"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" +"All parts of a SPATIAL KEY must be NOT NULL" +"COLLATION '%s' is not valid for CHARACTER SET '%s'" +"The slave was already running" +"The slave was already stopped" +"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)" +"Z_BUF_ERROR: Not enough memory available for zlib" +"Z_MEM_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)" +"Z_DATA_ERROR: Input data was corrupted for zlib" +"%d line(s) was(were) cut by group_concat()" +"Record count is fewer than the column count at row %ld"; +"Record count is more than the column count at row %ld"; +"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld"; +"Data truncated, out of range for column '%s' at row %ld"; +"Data truncated for column '%s' at row %ld" "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index f9d5a2b6324..d5064b53790 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -110,7 +110,7 @@ "BLOB-tüüpi tulp '%-.64s' ei saa omada vaikeväärtust", "Vigane andmebaasi nimi '%-.100s'", "Vigane tabeli nimi '%-.100s'", -"SELECT lause peab läbi vaatama suure hulga kirjeid ja võtaks tõenäoliselt liiga kaua aega. Tasub kontrollida WHERE klauslit ja vajadusel kasutada käsku SET OPTION SQL_BIG_SELECTS=1", +"SELECT lause peab läbi vaatama suure hulga kirjeid ja võtaks tõenäoliselt liiga kaua aega. Tasub kontrollida WHERE klauslit ja vajadusel kasutada käsku SET SQL_BIG_SELECTS=1", "Tundmatu viga", "Tundmatu protseduur '%-.64s'", "Vale parameetrite hulk protseduurile '%-.64s'", diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 1c4efab7e53..eb936243332 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -105,7 +105,7 @@ "BLOB '%-.64s' ne peut avoir de valeur par défaut", "Nom de base de donnée illégal: '%-.64s'", "Nom de table illégal: '%-.64s'", -"SELECT va devoir examiner beaucoup d'enregistrements ce qui va prendre du temps. Vérifiez la clause WHERE et utilisez SET OPTION SQL_BIG_SELECTS=1 si SELECT se passe bien", +"SELECT va devoir examiner beaucoup d'enregistrements ce qui va prendre du temps. Vérifiez la clause WHERE et utilisez SET SQL_BIG_SELECTS=1 si SELECT se passe bien", "Erreur inconnue", "Procédure %s inconnue", "Mauvais nombre de paramètres pour la procedure %s", diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index 00d6e784dcb..2ac25216b8e 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -114,7 +114,7 @@ "BLOB-Feld '%-.64s' kann keinen Vorgabewert (Default-Value) besitzen.", "Unerlaubter Datenbankname '%-.64s'.", "Unerlaubter Tabellenname '%-.64s'.", -"Die Ausführung des SELECT würde zu viele Datensätze untersuchen und wahrscheinlich sehr lange daueren. Bitte WHERE überprüfen oder gegebenenfalls SET OPTION SQL_BIG_SELECTS=1 verwenden.", +"Die Ausführung des SELECT würde zu viele Datensätze untersuchen und wahrscheinlich sehr lange daueren. Bitte WHERE überprüfen oder gegebenenfalls SET SQL_BIG_SELECTS=1 verwenden.", "Unbekannter Fehler.", "Unbekannte Procedure %-.64s.", "Falsche Parameterzahl für Procedure %-.64s.", diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index fdeb787859c..8e82559db5c 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -105,7 +105,7 @@ "Ôá Blob ðåäßá '%-.64s' äåí ìðïñïýí íá Ý÷ïõí ðñïêáèïñéóìÝíåò ôéìÝò (default value)", "ËÜèïò üíïìá âÜóçò äåäïìÝíùí '%-.100s'", "ËÜèïò üíïìá ðßíáêá '%-.100s'", -"Ôï SELECT èá åîåôÜóåé ìåãÜëï áñéèìü åããñáöþí êáé ðéèáíþò èá êáèõóôåñÞóåé. Ðáñáêáëþ åîåôÜóôå ôéò ðáñáìÝôñïõò ôïõ WHERE êáé ÷ñçóéìïðïéåßóôå SET OPTION SQL_BIG_SELECTS=1 áí ôï SELECT åßíáé óùóôü", +"Ôï SELECT èá åîåôÜóåé ìåãÜëï áñéèìü åããñáöþí êáé ðéèáíþò èá êáèõóôåñÞóåé. Ðáñáêáëþ åîåôÜóôå ôéò ðáñáìÝôñïõò ôïõ WHERE êáé ÷ñçóéìïðïéåßóôå SET SQL_BIG_SELECTS=1 áí ôï SELECT åßíáé óùóôü", "ÐñïÝêõøå Üãíùóôï ëÜèïò", "Áãíùóôç äéáäéêáóßá '%-.64s'", "ËÜèïò áñéèìüò ðáñáìÝôñùí óôç äéáäéêáóßá '%-.64s'", diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index 708bad26391..de0e7da614e 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -107,7 +107,7 @@ "A(z) '%-.64s' blob objektumnak nem lehet alapertelmezett erteke", "Hibas adatbazisnev: '%-.100s'", "Hibas tablanev: '%-.100s'", -"A SELECT tul sok rekordot fog megvizsgalni es nagyon sokaig fog tartani. Ellenorizze a WHERE-t es hasznalja a SET OPTION SQL_BIG_SELECTS=1 beallitast, ha a SELECT ok", +"A SELECT tul sok rekordot fog megvizsgalni es nagyon sokaig fog tartani. Ellenorizze a WHERE-t es hasznalja a SET SQL_BIG_SELECTS=1 beallitast, ha a SELECT ok", "Ismeretlen hiba", "Ismeretlen eljaras: '%-.64s'", "Rossz parameter a(z) '%-.64s'eljaras szamitasanal", diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index 23d157ce628..d9308faf8a6 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -105,7 +105,7 @@ "Il campo BLOB '%-.64s' non puo` avere un valore di default", "Nome database errato '%-.100s'", "Nome tabella errato '%-.100s'", -"La SELECT dovrebbe esaminare troppi record e usare troppo tempo. Controllare la WHERE e usa SET OPTION SQL_BIG_SELECTS=1 se e` tutto a posto.", +"La SELECT dovrebbe esaminare troppi record e usare troppo tempo. Controllare la WHERE e usa SET SQL_BIG_SELECTS=1 se e` tutto a posto.", "Errore sconosciuto", "Procedura '%-.64s' sconosciuta", "Numero di parametri errato per la procedura '%-.64s'", diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index 82a8c23ab67..45e78941906 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -107,7 +107,7 @@ "BLOB column '%-.64s' can't have a default value", "»ØÄꤷ¤¿ database ̾ '%-.100s' ¤¬´Ö°ã¤Ã¤Æ¤¤¤Þ¤¹", "»ØÄꤷ¤¿ table ̾ '%-.100s' ¤Ï¤Þ¤Á¤¬¤Ã¤Æ¤¤¤Þ¤¹", -"The SELECT would examine too many records and probably take a very long time. Check your WHERE and use SET OPTION SQL_BIG_SELECTS=1 if the SELECT is ok", +"The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok", "Unknown error", "Unknown procedure '%-.64s'", "Incorrect parameter count to procedure '%-.64s'", diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index a96805c1dc5..43d291ae3a5 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -105,7 +105,7 @@ "BLOB Ä®·³ '%-.64s' ´Â µðÆúÆ® °ªÀ» °¡Áú ¼ö ¾ø½À´Ï´Ù.", "'%-.100s' µ¥ÀÌŸº£À̽ºÀÇ À̸§ÀÌ ºÎÁ¤È®ÇÕ´Ï´Ù.", "'%-.100s' Å×À̺í À̸§ÀÌ ºÎÁ¤È®ÇÕ´Ï´Ù.", -"SELECT ¸í·É¿¡¼ ³Ê¹« ¸¹Àº ·¹Äڵ带 ã±â ¶§¹®¿¡ ¸¹Àº ½Ã°£ÀÌ ¼Ò¿äµË´Ï´Ù. µû¶ó¼ WHERE ¹®À» Á¡°ËÇϰųª, ¸¸¾à SELECT°¡ okµÇ¸é SET OPTION SQL_BIG_SELECTS=1 ¿É¼ÇÀ» »ç¿ëÇϼ¼¿ä.", +"SELECT ¸í·É¿¡¼ ³Ê¹« ¸¹Àº ·¹Äڵ带 ã±â ¶§¹®¿¡ ¸¹Àº ½Ã°£ÀÌ ¼Ò¿äµË´Ï´Ù. µû¶ó¼ WHERE ¹®À» Á¡°ËÇϰųª, ¸¸¾à SELECT°¡ okµÇ¸é SET SQL_BIG_SELECTS=1 ¿É¼ÇÀ» »ç¿ëÇϼ¼¿ä.", "¾Ë¼ö ¾ø´Â ¿¡·¯ÀÔ´Ï´Ù.", "¾Ë¼ö ¾ø´Â ¼öÇ๮ : '%-.64s'", "'%-.64s' ¼öÇ๮¿¡ ´ëÇÑ ºÎÁ¤È®ÇÑ ÆĶó¸ÞÅÍ", diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index 31e2afa0cc9..c0c045438ec 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -107,7 +107,7 @@ "Blob feltet '%-.64s' kan ikkje ha ein standard verdi", "Ugyldig database namn '%-.64s'", "Ugyldig tabell namn '%-.64s'", -"SELECT ville undersøkje for mange postar og ville sannsynligvis ta veldig lang tid. Undersøk WHERE klausulen og bruk SET OPTION SQL_BIG_SELECTS=1 om SELECTen er korrekt", +"SELECT ville undersøkje for mange postar og ville sannsynligvis ta veldig lang tid. Undersøk WHERE klausulen og bruk SET SQL_BIG_SELECTS=1 om SELECTen er korrekt", "Ukjend feil", "Ukjend prosedyre %s", "Feil parameter tal til prosedyra %s", diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index 2e1468bc815..03430ae546b 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -107,7 +107,7 @@ "Blob feltet '%-.64s' kan ikke ha en standard verdi", "Ugyldig database navn '%-.64s'", "Ugyldig tabell navn '%-.64s'", -"SELECT ville undersøke for mange poster og ville sannsynligvis ta veldig lang tid. Undersøk WHERE klausulen og bruk SET OPTION SQL_BIG_SELECTS=1 om SELECTen er korrekt", +"SELECT ville undersøke for mange poster og ville sannsynligvis ta veldig lang tid. Undersøk WHERE klausulen og bruk SET SQL_BIG_SELECTS=1 om SELECTen er korrekt", "Ukjent feil", "Ukjent prosedyre %s", "Feil parameter antall til prosedyren %s", diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index 284334cbfbd..ef051d957cb 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -105,7 +105,7 @@ "Coluna BLOB '%-.64s' não pode ter um valor padrão (default)", "Nome de banco de dados '%-.100s' incorreto", "Nome de tabela '%-.100s' incorreto", -"O SELECT examinaria registros demais e provavelmente levaria muito tempo. Cheque sua cláusula WHERE e use SET OPTION SQL_BIG_SELECTS=1, se o SELECT estiver correto", +"O SELECT examinaria registros demais e provavelmente levaria muito tempo. Cheque sua cláusula WHERE e use SET SQL_BIG_SELECTS=1, se o SELECT estiver correto", "Erro desconhecido", "'Procedure' '%-.64s' desconhecida", "Número de parâmetros incorreto para a 'procedure' '%-.64s'", @@ -219,46 +219,46 @@ "Não pode acrescentar uma restrição de chave estrangeira", "Não pode acrescentar uma linha filha: uma restrição de chave estrangeira falhou", "Não pode apagar uma linha pai: uma restrição de chave estrangeira falhou", -"Error connecting to master: %-.128s", -"Error running query on master: %-.128s", -"Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", -"The used SELECT statements have a different number of columns", -"Can't execute the query because you have a conflicting read lock", -"Mixing of transactional and non-transactional tables is disabled", -"Option '%s' used twice in statement", -"User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", -"Variable '%-.64s' is a LOCAL variable and can't be used with SET GLOBAL", -"Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", -"Variable '%-.64s' doesn't have a default value", -"Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", -"Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", -"This version of MySQL doesn't yet support '%s'", -"Got fatal error %d: '%-.128s' from master when reading data from binary log", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", -"Cardinality error (more/less than %d columns)", -"Subselect returns more than 1 record", -"Unknown prepared statement handler (%ld) given to %s", -"Help database is corrupt or does not exist", -"Cyclic reference on subqueries", -"Converting column '%s' from %s to %s", -"Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", -"Client does not support authentication protocol requested by server. Consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", -"COLLATION '%s' is not valid for CHARACTER SET '%s'", -"The slave was already running", -"The slave was already stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_BUF_ERROR: Not enough memory available for zlib", -"Z_MEM_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", -"Using storage engine %s for table '%s'", -"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", +"Erro connectando para o master: %-.128s", +"Erro rodando consulta no master: %-.128s", +"Erro quando executando comando %s: %-.128s", +"Uso errado de %s e %s", +"Os comandos SELECT usados têm diferentes números de colunas", +"Não pode executar a consulta porque você tem um conflitante travamento de leitura", +"Combinação de tabelas transacionais e não transacionais está desativada", +"Opção '%s' usada duas vezes no comando", +"Usuário '%-.64s' há excedido o '%s' de recursos (atual valor: %ld)", +"Acesso negado. Você necessita o privilégio %-.128s para essa operação", +"Variável '%-.64s' é uma LOCAL variável e não pode ser usada com SET GLOBAL", +"Variável '%-.64s' é uma GLOBAL variável e deve ser configurada com SET GLOBAL", +"Variável '%-.64s' não tem um valor default (padrão)", +"Variável '%-.64s' não pode ser configurada para o valor de '%-.64s'", +"Tipo de argumento errado para a variável '%-.64s'", +"Variável '%-.64s' somente pode ser configurada, não lida", +"Uso/localização errada de '%s'", +"Esta versão de MySQL não suporta ainda '%s'", +"Obteve fatal error %d: '%-.128s' a partir do master quando lendo dados do binary log", +"Definição errada da chave estrangeira para '%-.64s': %s", +"Referência da chave e referência da tabela não coincidem", +"Error de cardinalidade (mais/menos que %d colunas)", +"Subconsulta retorna mais que 1 registro", +"Desconhecido manipulador de declaração preparado (%ld) determinado para %s", +"Banco de dado de ajuda corrupto ou não existente", +"Referência cíclica em subconsultas", +"Convertendo coluna '%s' de %s para %s", +"Referência '%-.64s' não suportada (%s)", +"Cada tabela derivada deve ter seu próprio alias", +"Select %u foi reduzido durante otimização", +"Tabela '%-.64s' de um dos SELECT's não pode ser usada em %-.32s", +"Cliente não suporta o protocolo de autenticação exigido pelo servidor. Considere a atualização deo cliente MySQL", +"Todas as partes de uma SPATIAL KEY devem ser NOT NULL", +"COLLATION '%s' não é válida para CHARACTER SET '%s'", +"O slave já está rodando", +"O slave já está parado", +"Tamanho muito grande dos dados des comprimidos. O máximo tamanho é %d. (provavelmente, o comprimento dos dados descomprimidos está corrupto)", +"Z_BUF_ERROR: Não suficiente memória disponível para zlib", +"Z_MEM_ERROR: Não suficiente espaço no buffer emissor para zlib (provavelmente, o comprimento dos dados descomprimidos está corrupto)", +"Z_DATA_ERROR: Dados de entrada está corrupto para zlib", +"%d linha(s) foi(foram) cortada(s) por group_concat()", +"Usando engine de armazenamento %s para tabela '%s'", +"Combinação ilegal de collations (%s,%s) e (%s,%s) para operação '%s'", diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index 1966b37bc72..89c00b4bf15 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -109,7 +109,7 @@ "Coloana BLOB '%-.64s' nu poate avea o valoare default", "Numele bazei de date este incorect '%-.100s'", "Numele tabelei este incorect '%-.100s'", -"SELECT-ul ar examina prea multe cimpuri si probabil ar lua prea mult timp. Verifica clauza WHERE si foloseste SET OPTION SQL_BIG_SELECTS=1 daca SELECT-ul e ok", +"SELECT-ul ar examina prea multe cimpuri si probabil ar lua prea mult timp. Verifica clauza WHERE si foloseste SET SQL_BIG_SELECTS=1 daca SELECT-ul e ok", "Eroare unknown", "Procedura unknown '%-.64s'", "Procedura '%-.64s' are un numar incorect de parametri", diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index 3935aef82e3..fac4dedb3ee 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -107,7 +107,7 @@ "îÅ×ÏÚÍÏÖÎÏ ÕËÁÚÙ×ÁÔØ ÚÎÁÞÅÎÉÅ ÐÏ ÕÍÏÌÞÁÎÉÀ ÄÌÑ ÓÔÏÌÂÃÁ BLOB '%-.64s'", "îÅËÏÒÒÅËÔÎÏÅ ÉÍÑ ÂÁÚÙ ÄÁÎÎÙÈ '%-.100s'", "îÅËÏÒÒÅËÔÎÏÅ ÉÍÑ ÔÁÂÌÉÃÙ '%-.100s'", -"äÌÑ ÔÁËÏÊ ×ÙÂÏÒËÉ SELECT ÄÏÌÖÅÎ ÂÕÄÅÔ ÐÒÏÓÍÏÔÒÅÔØ ÓÌÉÛËÏÍ ÍÎÏÇÏ ÚÁÐÉÓÅÊ É, ×ÉÄÉÍÏ, ÜÔÏ ÚÁÊÍÅÔ ÏÞÅÎØ ÍÎÏÇÏ ×ÒÅÍÅÎÉ. ðÒÏ×ÅÒØÔÅ ×ÁÛÅ ÕËÁÚÁÎÉÅ WHERE, É, ÅÓÌÉ × ÎÅÍ ×ÓÅ × ÐÏÒÑÄËÅ, ÕËÁÖÉÔÅ SET OPTION SQL_BIG_SELECTS=1", +"äÌÑ ÔÁËÏÊ ×ÙÂÏÒËÉ SELECT ÄÏÌÖÅÎ ÂÕÄÅÔ ÐÒÏÓÍÏÔÒÅÔØ ÓÌÉÛËÏÍ ÍÎÏÇÏ ÚÁÐÉÓÅÊ É, ×ÉÄÉÍÏ, ÜÔÏ ÚÁÊÍÅÔ ÏÞÅÎØ ÍÎÏÇÏ ×ÒÅÍÅÎÉ. ðÒÏ×ÅÒØÔÅ ×ÁÛÅ ÕËÁÚÁÎÉÅ WHERE, É, ÅÓÌÉ × ÎÅÍ ×ÓÅ × ÐÏÒÑÄËÅ, ÕËÁÖÉÔÅ SET SQL_BIG_SELECTS=1", "îÅÉÚ×ÅÓÔÎÁÑ ÏÛÉÂËÁ", "îÅÉÚ×ÅÓÔÎÁÑ ÐÒÏÃÅÄÕÒÁ '%-.64s'", "îÅËÏÒÒÅËÔÎÏÅ ËÏÌÉÞÅÓÔ×Ï ÐÁÒÁÍÅÔÒÏ× ÄÌÑ ÐÒÏÃÅÄÕÒÙ '%-.64s'", diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index db25f12ed13..8f7747c6bf6 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -113,7 +113,7 @@ "Pole BLOB '%-.64s' nemô¾e ma» implicitnú hodnotu", "Neprípustné meno databázy '%-.100s'", "Neprípustné meno tabuµky '%-.100s'", -"Zadaná po¾iadavka SELECT by prechádzala príli¹ mnoho záznamov a trvala by príli¹ dlho. Skontrolujte tvar WHERE a ak je v poriadku, pou¾ite SET OPTION SQL_BIG_SELECTS=1", +"Zadaná po¾iadavka SELECT by prechádzala príli¹ mnoho záznamov a trvala by príli¹ dlho. Skontrolujte tvar WHERE a ak je v poriadku, pou¾ite SET SQL_BIG_SELECTS=1", "Neznámá chyba", "Neznámá procedúra '%-.64s'", "Chybný poèet parametrov procedúry '%-.64s'", diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index 44fb0a19640..4a7989ce7be 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -106,7 +106,7 @@ "Campo Blob '%-.64s' no puede tener valores patron", "Nombre de base de datos ilegal '%-.64s'", "Nombre de tabla ilegal '%-.64s'", -"El SELECT puede examinar muchos registros y probablemente con mucho tiempo. Verifique tu WHERE y usa SET OPTION SQL_BIG_SELECTS=1 si el SELECT esta correcto", +"El SELECT puede examinar muchos registros y probablemente con mucho tiempo. Verifique tu WHERE y usa SET SQL_BIG_SELECTS=1 si el SELECT esta correcto", "Error desconocido", "Procedimiento desconocido %s", "Equivocado parametro count para procedimiento %s", diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index e40a44957f1..6734369d3ac 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -105,7 +105,7 @@ "BLOB fält '%-.64s' kan inte ha ett DEFAULT-värde", "Felaktigt databasnamn '%-.64s'", "Felaktigt tabellnamn '%-.64s'", -"Den angivna frågan skulle troligen ta mycket lång tid! Kontrollera din WHERE och använd SET OPTION SQL_BIG_SELECTS=1 ifall du vill hantera stora joins", +"Den angivna frågan skulle läsa mer än MAX_JOIN_SIZE rader. Kontrollera din WHERE och använd SET SQL_BIG_SELECTS=1 eller SET MAX_JOIN_SIZE=# ifall du vill hantera stora joins", "Oidentifierat fel", "Okänd procedur: %s", "Felaktigt antal parametrar till procedur %s", diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt index 968327a1024..67c52dc8fee 100644 --- a/sql/share/ukrainian/errmsg.txt +++ b/sql/share/ukrainian/errmsg.txt @@ -110,7 +110,7 @@ "óÔÏ×ÂÅÃØ BLOB '%-.64s' ÎÅ ÍÏÖÅ ÍÁÔÉ ÚÎÁÞÅÎÎÑ ÐÏ ÚÁÍÏ×ÞÕ×ÁÎÎÀ", "îÅצÒÎÅ ¦Í'Ñ ÂÁÚÉ ÄÁÎÎÉÈ '%-.100s'", "îÅצÒÎÅ ¦Í'Ñ ÔÁÂÌÉæ '%-.100s'", -"úÁÐÉÔÕ SELECT ÐÏÔÒ¦ÂÎÏ ÏÂÒÏÂÉÔÉ ÂÁÇÁÔÏ ÚÁÐÉÓ¦×, ÝÏ, ÐÅ×ÎÅ, ÚÁÊÍÅ ÄÕÖÅ ÂÁÇÁÔÏ ÞÁÓÕ. ðÅÒÅצÒÔÅ ×ÁÛÅ WHERE ÔÁ ×ÉËÏÒÉÓÔÏ×ÕÊÔÅ SET OPTION SQL_BIG_SELECTS=1, ÑËÝÏ ÃÅÊ ÚÁÐÉÔ SELECT ¤ צÒÎÉÍ", +"úÁÐÉÔÕ SELECT ÐÏÔÒ¦ÂÎÏ ÏÂÒÏÂÉÔÉ ÂÁÇÁÔÏ ÚÁÐÉÓ¦×, ÝÏ, ÐÅ×ÎÅ, ÚÁÊÍÅ ÄÕÖÅ ÂÁÇÁÔÏ ÞÁÓÕ. ðÅÒÅצÒÔÅ ×ÁÛÅ WHERE ÔÁ ×ÉËÏÒÉÓÔÏ×ÕÊÔÅ SET SQL_BIG_SELECTS=1, ÑËÝÏ ÃÅÊ ÚÁÐÉÔ SELECT ¤ צÒÎÉÍ", "îÅצÄÏÍÁ ÐÏÍÉÌËÁ", "îÅצÄÏÍÁ ÐÒÏÃÅÄÕÒÁ '%-.64s'", "èÉÂÎÁ ˦ÌØ˦ÓÔØ ÐÁÒÁÍÅÔÒ¦× ÐÒÏÃÅÄÕÒÉ '%-.64s'", diff --git a/sql/slave.cc b/sql/slave.cc index eae795ae760..22c47bbdd05 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -20,12 +20,12 @@ #include <mysql.h> #include <myisam.h> -#include "mini_client.h" #include "slave.h" #include "sql_repl.h" #include "repl_failsafe.h" #include <thr_alarm.h> #include <my_dir.h> +#include <sql_common.h> bool use_slave_mask = 0; MY_BITMAP slave_error_mask; @@ -1164,15 +1164,15 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, if (!called_connected) { - if (!(mysql = mc_mysql_init(NULL))) + if (!(mysql = mysql_init(NULL))) { send_error(thd); // EOM DBUG_RETURN(1); } if (connect_to_master(thd, mysql, mi)) { - net_printf(thd, ER_CONNECT_TO_MASTER, mc_mysql_error(mysql)); - mc_mysql_close(mysql); + net_printf(thd, ER_CONNECT_TO_MASTER, mysql_error(mysql)); + mysql_close(mysql); DBUG_RETURN(1); } if (thd->killed) @@ -1193,7 +1193,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, err: thd->net.no_send_ok = 0; // Clear up garbage after create_table_from_dump if (!called_connected) - mc_mysql_close(mysql); + mysql_close(mysql); if (errmsg && thd->net.vio) send_error(thd, error, errmsg); DBUG_RETURN(test(error)); // Return 1 on error @@ -1560,12 +1560,12 @@ int register_slave_on_master(MYSQL* mysql) /* The master will fill in master_id */ int4store(pos, 0); pos+= 4; - if (mc_simple_command(mysql, COM_REGISTER_SLAVE, (char*) buf, + if (simple_command(mysql, COM_REGISTER_SLAVE, (char*) buf, (uint) (pos- buf), 0)) { sql_print_error("Error on COM_REGISTER_SLAVE: %d '%s'", - mc_mysql_errno(mysql), - mc_mysql_error(mysql)); + mysql_errno(mysql), + mysql_error(mysql)); return 1; } return 0; @@ -1959,18 +1959,18 @@ static int request_dump(MYSQL* mysql, MASTER_INFO* mi, int4store(buf + 6, server_id); len = (uint) strlen(logname); memcpy(buf + 10, logname,len); - if (mc_simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1)) + if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1)) { /* Something went wrong, so we will just reconnect and retry later in the future, we should do a better error analysis, but for now we just fill up the error log :-) */ - if (mc_mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) + if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) *suppress_warnings= 1; // Suppress reconnect warning else sql_print_error("Error on COM_BINLOG_DUMP: %d %s, will retry in %d secs", - mc_mysql_errno(mysql), mc_mysql_error(mysql), + mysql_errno(mysql), mysql_error(mysql), master_connect_retry); DBUG_RETURN(1); } @@ -1997,7 +1997,7 @@ static int request_table_dump(MYSQL* mysql, const char* db, const char* table) *p++ = table_len; memcpy(p, table, table_len); - if (mc_simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1)) + if (simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1)) { sql_print_error("request_table_dump: Error sending the table dump \ command"); @@ -2041,10 +2041,10 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) return packet_error; #endif - len = mc_net_safe_read(mysql); + len = net_safe_read(mysql); if (len == packet_error || (long) len < 1) { - if (mc_mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) + if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) { /* We are trying a normal reconnect after a read timeout; @@ -2056,7 +2056,7 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings) else sql_print_error("Error reading packet from server: %s (\ server_errno=%d)", - mc_mysql_error(mysql), mc_mysql_errno(mysql)); + mysql_error(mysql), mysql_errno(mysql)); return packet_error; } @@ -2064,7 +2064,7 @@ server_errno=%d)", { sql_print_error("Slave: received 0 length packet from server, apparent\ master shutdown: %s", - mc_mysql_error(mysql)); + mysql_error(mysql)); return packet_error; } @@ -2214,7 +2214,7 @@ slave_begin: mi->master_log_name, llstr(mi->master_log_pos,llbuff))); - if (!(mi->mysql = mysql = mc_mysql_init(NULL))) + if (!(mi->mysql = mysql = mysql_init(NULL))) { sql_print_error("Slave I/O thread: error in mc_mysql_init()"); goto err; @@ -2269,7 +2269,7 @@ dump"); } thd->proc_info = "Waiiting to reconnect after a failed dump request"; - mc_end_server(mysql); + end_server(mysql); /* First time retry immediately, assuming that we can recover right away - if first time fails, sleep between re-tries @@ -2319,7 +2319,7 @@ after reconnect"); if (event_len == packet_error) { - uint mysql_error_number= mc_mysql_errno(mysql); + uint mysql_error_number= mysql_errno(mysql); if (mysql_error_number == ER_NET_PACKET_TOO_LARGE) { sql_print_error("\ @@ -2332,11 +2332,11 @@ max_allowed_packet", if (mysql_error_number == ER_MASTER_FATAL_ERROR_READING_BINLOG) { sql_print_error(ER(mysql_error_number), mysql_error_number, - mc_mysql_error(mysql)); + mysql_error(mysql)); goto err; } thd->proc_info = "Waiting to reconnect after a failed read"; - mc_end_server(mysql); + end_server(mysql); if (retry_count++) { if (retry_count > master_retry_count) @@ -2406,7 +2406,7 @@ err: VOID(pthread_mutex_unlock(&LOCK_thread_count)); if (mysql) { - mc_mysql_close(mysql); + mysql_close(mysql); mi->mysql=0; } thd->proc_info = "Waiting for slave mutex on exit"; @@ -2429,9 +2429,7 @@ err: goto slave_begin; #endif my_thread_end(); -#ifndef __NETWARE__ pthread_exit(0); -#endif /* __NETWARE__ */ DBUG_RETURN(0); // Can't return anything here } @@ -2573,9 +2571,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ goto slave_begin; #endif my_thread_end(); -#ifndef __NETWARE__ pthread_exit(0); -#endif /* __NETWARE__ */ DBUG_RETURN(0); // Can't return anything here } @@ -2951,22 +2947,24 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi, client_flag=CLIENT_COMPRESS; /* We will use compression */ while (!(slave_was_killed = io_slave_killed(thd,mi)) && - (reconnect ? mc_mysql_reconnect(mysql) != 0: - !mc_mysql_connect(mysql, mi->host, mi->user, mi->password, 0, - mi->port, 0, client_flag, - thd->variables.net_read_timeout))) + (reconnect ? mysql_reconnect(mysql) != 0: + !(mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, + (char *)&thd->variables.net_read_timeout), + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (char *)default_charset_info), + mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0, + mi->port, 0, client_flag)))) { /* Don't repeat last error */ - if (mc_mysql_errno(mysql) != last_errno) + if ((int)mysql_errno(mysql) != last_errno) { - last_errno=mc_mysql_errno(mysql); + last_errno=mysql_errno(mysql); suppress_warnings= 0; sql_print_error("Slave I/O thread: error %s to master \ '%s@%s:%d': \ Error: '%s' errno: %d retry-time: %d retries: %d", (reconnect ? "reconnecting" : "connecting"), mi->user,mi->host,mi->port, - mc_mysql_error(mysql), last_errno, + mysql_error(mysql), last_errno, mi->connect_retry, master_retry_count); } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index b6191b2061e..ec6db64ea73 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -70,7 +70,7 @@ static ACL_USER *find_acl_user(const char *host, const char *user); static bool update_user_table(THD *thd, const char *host, const char *user, const char *new_password); static void update_hostname(acl_host_and_ip *host, const char *hostname); -static bool compare_hostname(const acl_host_and_ip *host, const char *hostname, +static bool compare_hostname(const acl_host_and_ip *host,const char *hostname, const char *ip); /* @@ -496,8 +496,9 @@ void prepare_scramble(THD *thd, ACL_USER *acl_user,char* prepared_scramble) ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, const char *password,const char *message,char **priv_user, - bool old_ver, USER_RESOURCES *mqh, char *prepared_scramble, - uint *cur_priv_version, ACL_USER **cached_user) + char *priv_host, bool old_ver, USER_RESOURCES *mqh, + char *prepared_scramble, uint *cur_priv_version, + ACL_USER **cached_user) { ulong user_access=NO_ACCESS; *priv_user= (char*) user; @@ -593,7 +594,7 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, { Vio *vio=thd->net.vio; /* - In this point we know that user is allowed to connect + At this point we know that user is allowed to connect from given host by given username/password pair. Now we check if SSL is required, if user is using SSL and if X509 certificate attributes are OK @@ -611,8 +612,11 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, /* Connections with non-valid certificates are dropped already in sslaccept() anyway, so we do not check validity here. + + We need to check for absence of SSL because without SSL + we should reject connection. */ - if (SSL_get_peer_certificate(vio->ssl_)) + if (vio_type(vio) == VIO_TYPE_SSL && SSL_get_peer_certificate(vio->ssl_)) user_access=acl_user->access; break; case SSL_TYPE_SPECIFIED: /* Client should have specified attrib */ @@ -622,6 +626,8 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, If cipher name is specified, we compare it to actual cipher in use. */ + if (vio_type(vio) != VIO_TYPE_SSL) + break; if (acl_user->ssl_cipher) { DBUG_PRINT("info",("comparing ciphers: '%s' and '%s'", @@ -630,6 +636,10 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, user_access=acl_user->access; else { + if (global_system_variables.log_warnings) + sql_print_error("X509 ciphers mismatch: should be '%s' but is '%s'", + acl_user->ssl_cipher, + SSL_get_cipher(vio->ssl_)); user_access=NO_ACCESS; break; } @@ -647,6 +657,9 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, acl_user->x509_issuer, ptr)); if (strcmp(acl_user->x509_issuer, ptr)) { + if (global_system_variables.log_warnings) + sql_print_error("X509 issuer mismatch: should be '%s' but is '%s'", + acl_user->x509_issuer, ptr); user_access=NO_ACCESS; free(ptr); break; @@ -662,7 +675,12 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, DBUG_PRINT("info",("comparing subjects: '%s' and '%s'", acl_user->x509_subject, ptr)); if (strcmp(acl_user->x509_subject,ptr)) + { + if (global_system_variables.log_warnings) + sql_print_error("X509 subject mismatch: '%s' vs '%s'", + acl_user->x509_subject, ptr); user_access=NO_ACCESS; + } else user_access=acl_user->access; free(ptr); @@ -677,6 +695,11 @@ ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, if (!acl_user->user) *priv_user=(char*) ""; // Change to anonymous user /* purecov: inspected */ + if (acl_user->host.hostname) + strmake(priv_host, acl_user->host.hostname, MAX_HOSTNAME); + else + *priv_host= 0; + unlock_and_exit: VOID(pthread_mutex_unlock(&acl_cache->lock)); DBUG_RETURN(user_access); @@ -780,7 +803,7 @@ static void acl_insert_user(const char *user, const char *host, VOID(push_dynamic(&acl_users,(gptr) &acl_user)); if (!acl_user.host.hostname || acl_user.host.hostname[0] == wild_many && !acl_user.host.hostname[1]) - allow_all_hosts=1; // Anyone can connect /* purecov: tested */ + allow_all_hosts=1; // Anyone can connect /* purecov: tested */ qsort((gptr) dynamic_element(&acl_users,0,ACL_USER*),acl_users.elements, sizeof(ACL_USER),(qsort_cmp) acl_compare); @@ -1126,8 +1149,7 @@ bool change_password(THD *thd, const char *host, const char *user, Simple hack to avoid cracking */ length=(uint) strlen(new_password); - - if (length!=45) + if (length != 45) new_password[length & 16]=0; VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -2060,10 +2082,10 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, } -int mysql_table_grant (THD *thd, TABLE_LIST *table_list, - List <LEX_USER> &user_list, - List <LEX_COLUMN> &columns, ulong rights, - bool revoke_grant) +int mysql_table_grant(THD *thd, TABLE_LIST *table_list, + List <LEX_USER> &user_list, + List <LEX_COLUMN> &columns, ulong rights, + bool revoke_grant) { ulong column_priv = 0; List_iterator <LEX_USER> str_list (user_list); @@ -2437,7 +2459,7 @@ my_bool grant_init(THD *org_thd) mem_check->ok() && hash_insert(&column_priv_hash,(byte*) mem_check)) { /* This could only happen if we are out memory */ - grant_option = FALSE; /* purecov: deadcode */ + grant_option= FALSE; /* purecov: deadcode */ goto end_unlock; } } @@ -2477,16 +2499,16 @@ void grant_reload(THD *thd) rw_wrlock(&LOCK_grant); grant_version++; old_column_priv_hash= column_priv_hash; - old_grant_option = grant_option; - old_mem = memex; + old_grant_option= grant_option; + old_mem= memex; if (grant_init(thd)) { // Error. Revert to old hash DBUG_PRINT("error",("Reverting to old privileges")); grant_free(); /* purecov: deadcode */ column_priv_hash= old_column_priv_hash; /* purecov: deadcode */ - grant_option = old_grant_option; /* purecov: deadcode */ - memex = old_mem; /* purecov: deadcode */ + grant_option= old_grant_option; /* purecov: deadcode */ + memex= old_mem; /* purecov: deadcode */ } else { @@ -2583,8 +2605,8 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, } -bool check_grant_column (THD *thd,TABLE *table, const char *name, - uint length, uint show_tables) +bool check_grant_column(THD *thd,TABLE *table, const char *name, + uint length, uint show_tables) { GRANT_TABLE *grant_table; GRANT_COLUMN *grant_column; @@ -2650,7 +2672,12 @@ bool check_grant_all_columns(THD *thd, ulong want_access, TABLE *table) want_access &= ~table->grant.privilege; if (!want_access) - return 0; // Already checked + return 0; // Already checked + if (!grant_option) + { + field= table->field[0]; // To give a meaningful error message + goto err2; + } rw_rdlock(&LOCK_grant); @@ -2679,9 +2706,9 @@ bool check_grant_all_columns(THD *thd, ulong want_access, TABLE *table) return 0; /* We must use my_printf_error() here! */ - err: +err: rw_unlock(&LOCK_grant); - +err2: const char *command=""; if (want_access & SELECT_ACL) command ="select"; @@ -3108,11 +3135,11 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) } } } - global.append(" ON ",4); + global.append(" ON `",5); global.append(grant_table->db); - global.append(".",1); + global.append("`.`",3); global.append(grant_table->tname); - global.append(" TO '",5); + global.append("` TO '",6); global.append(lex_user->user.str,lex_user->user.length); global.append("'@'",3); global.append(lex_user->host.str,lex_user->host.length); diff --git a/sql/sql_acl.h b/sql/sql_acl.h index ceb866d809f..d85a281cbb5 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -136,7 +136,8 @@ void acl_free(bool end=0); ulong acl_get(const char *host, const char *ip, const char *bin_ip, const char *user, const char *db); ulong acl_getroot(THD *thd, const char *host, const char *ip, const char *user, - const char *password,const char *scramble,char **priv_user, + const char *password,const char *scramble, + char **priv_user, char *priv_host, bool old_ver, USER_RESOURCES *max,char* prepared_scramble, uint *cur_priv_version, ACL_USER **cached_user); bool acl_check_host(const char *host, const char *ip); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index fc95f5deb40..81c620fdaf4 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -423,8 +423,9 @@ bool close_thread_table(THD *thd, TABLE **table_ptr) { DBUG_ENTER("close_thread_table"); - bool found_old_table=0; - TABLE *table=*table_ptr; + bool found_old_table= 0; + TABLE *table= *table_ptr; + DBUG_ASSERT(table->key_read == 0); *table_ptr=table->next; if (table->version != refresh_version || @@ -1693,7 +1694,7 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, else thd->dupp_field=field; } - if (check_grants && check_grant_column(thd,table,name,length)) + if (check_grants && check_grant_column(thd,table,name,length)) return WRONG_GRANT; return field; } @@ -1743,8 +1744,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, { found_table=1; Field *find=find_field_in_table(thd,tables->table,name,length, - grant_option && - tables->table->grant.want_privilege, + test(tables->table->grant. + want_privilege), 1); if (find) { @@ -1801,8 +1802,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, } Field *field=find_field_in_table(thd,tables->table,name,length, - grant_option && - tables->table->grant.want_privilege, + test(tables->table->grant.want_privilege), allow_rowid); if (field) { @@ -2098,9 +2098,10 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, (!db_name || !strcmp(tables->db,db_name)))) { /* Ensure that we have access right to all columns */ - if (grant_option && !thd->master_access && - check_grant_all_columns(thd,SELECT_ACL,table) ) + if (!(table->grant.privilege & SELECT_ACL) && + check_grant_all_columns(thd,SELECT_ACL,table)) DBUG_RETURN(-1); + Field **ptr=table->field,*field; thd->used_tables|=table->map; while ((field = *ptr++)) @@ -2227,7 +2228,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) ******************************************************************************/ int -fill_record(List<Item> &fields,List<Item> &values) +fill_record(List<Item> &fields,List<Item> &values, bool ignore_errors) { List_iterator_fast<Item> f(fields),v(values); Item *value; @@ -2237,7 +2238,7 @@ fill_record(List<Item> &fields,List<Item> &values) while ((field=(Item_field*) f++)) { value=v++; - if (value->save_in_field(field->field, 0) > 0) + if (value->save_in_field(field->field, 0) > 0 && !ignore_errors) DBUG_RETURN(1); } DBUG_RETURN(0); @@ -2245,7 +2246,7 @@ fill_record(List<Item> &fields,List<Item> &values) int -fill_record(Field **ptr,List<Item> &values) +fill_record(Field **ptr,List<Item> &values, bool ignore_errors) { List_iterator_fast<Item> v(values); Item *value; @@ -2255,7 +2256,7 @@ fill_record(Field **ptr,List<Item> &values) while ((field = *ptr++)) { value=v++; - if (value->save_in_field(field, 0) == 1) + if (value->save_in_field(field, 0) == 1 && !ignore_errors) DBUG_RETURN(1); } DBUG_RETURN(0); @@ -2310,7 +2311,7 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys) DBUG_ENTER("mysql_create_index"); bzero((char*) &create_info,sizeof(create_info)); create_info.db_type=DB_TYPE_DEFAULT; - create_info.table_charset= thd->db_charset; + create_info.table_charset= thd->variables.character_set_database; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, fields, keys, drop, alter, 0, (ORDER*)0, FALSE, @@ -2327,7 +2328,7 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop) DBUG_ENTER("mysql_drop_index"); bzero((char*) &create_info,sizeof(create_info)); create_info.db_type=DB_TYPE_DEFAULT; - create_info.table_charset= thd->db_charset; + create_info.table_charset= thd->variables.character_set_database; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, fields, keys, drop, alter, 0, (ORDER*)0, FALSE, diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index d8265a1b359..adc3d177fdf 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -761,11 +761,11 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) uint8 tables_type= 0; if ((local_tables = is_cacheable(thd, thd->query_length, - thd->query, &thd->lex, tables_used, - &tables_type))) + thd->query, &thd->lex, tables_used, + &tables_type))) { NET *net= &thd->net; - byte flags = (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0); + byte flags= (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0); STRUCT_LOCK(&structure_guard_mutex); if (query_cache_size == 0) @@ -790,8 +790,10 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) */ flags|= (byte) thd->charset()->number; DBUG_ASSERT(thd->charset()->number < 128); - tot_length=thd->query_length+thd->db_length+2; - thd->query[tot_length-1] = (char) flags; + tot_length= thd->query_length+thd->db_length+2+sizeof(ha_rows); + thd->query[tot_length-1]= (char) flags; + memcpy((void *)(thd->query + (tot_length-sizeof(ha_rows)-1)), + (const void *)&thd->variables.select_limit, sizeof(ha_rows)); /* Check if another thread is processing the same query? */ Query_cache_block *competitor = (Query_cache_block *) @@ -921,7 +923,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) } Query_cache_block *query_block; - tot_length=query_length+thd->db_length+2; + tot_length= query_length+thd->db_length+2+sizeof(ha_rows); if (thd->db_length) { memcpy(sql+query_length+1, thd->db, thd->db_length); @@ -937,10 +939,12 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) Most significant bit - CLIENT_LONG_FLAG, Other - charset number (0 no charset convertion) */ - flags = (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0); - flags |= (byte) thd->charset()->number; + flags= (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0); + flags|= (byte) thd->charset()->number; DBUG_ASSERT(thd->charset()->number < 128); - sql[tot_length-1] = (char) flags; + sql[tot_length-1]= (char) flags; + memcpy((void *)(sql + (tot_length-sizeof(ha_rows)-1)), + (const void *)&thd->variables.select_limit, sizeof(ha_rows)); query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql, tot_length); /* Quick abort on unlocked data */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index f579b02ee50..fb088b602b1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -109,7 +109,7 @@ THD::THD():user_time(0), is_fatal_error(0), file_id = 0; cond_count=0; warn_id= 0; - db_charset=default_charset_info; + db_charset= global_system_variables.character_set_database; mysys_var=0; #ifndef DBUG_OFF dbug_sentry=THD_SENTRY_MAGIC; @@ -120,6 +120,7 @@ THD::THD():user_time(0), is_fatal_error(0), net.last_error[0]=0; // If error on boot ull=0; system_thread=cleanup_done=0; + peer_port= 0; // For SHOW PROCESSLIST transaction.changed_tables = 0; #ifdef __WIN__ real_id = 0; diff --git a/sql/sql_class.h b/sql/sql_class.h index 925afde2202..157a58cb8fa 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -358,6 +358,7 @@ struct system_variables ulong max_prep_stmt_count; ulong max_sort_length; ulong max_tmp_tables; + ulong myisam_repair_threads; ulong myisam_sort_buff_size; ulong net_buffer_length; ulong net_interactive_timeout; @@ -385,9 +386,11 @@ struct system_variables my_bool low_priority_updates; my_bool new_mode; - CHARSET_INFO *collation_client; + CHARSET_INFO *character_set_server; + CHARSET_INFO *character_set_database; + CHARSET_INFO *character_set_client; + CHARSET_INFO *character_set_results; CHARSET_INFO *collation_connection; - CHARSET_INFO *collation_results; }; void free_tmp_table(THD *thd, TABLE *entry); @@ -434,13 +437,14 @@ public: ip - client IP */ char *host,*user,*priv_user,*db,*ip; + char priv_host[MAX_HOSTNAME]; /* remote (peer) port */ uint16 peer_port; /* Points to info-string that will show in SHOW PROCESSLIST */ const char *proc_info; /* points to host if host is available, otherwise points to ip */ const char *host_or_ip; - + ulong client_capabilities; /* What the client supports */ /* Determines if which non-standard SQL behaviour should be enabled */ ulong max_client_packet_length; @@ -512,6 +516,7 @@ public: ulong query_id, warn_id, version, options, thread_id, col_access; ulong current_stmt_id; ulong rand_saved_seed1, rand_saved_seed2; + ulong row_count; // Row counter, mainly for errors and warnings long dbug_thread_id; pthread_t real_id; uint current_tablenr,tmp_table,cond_count; @@ -530,6 +535,7 @@ public: uint8 query_cache_type; // type of query cache processing bool slave_thread; bool set_query_id,locked,count_cuted_fields,some_tables_deleted; + bool last_cuted_field; bool no_errors, allow_sum_func, password, is_fatal_error; bool query_start_used,last_insert_id_used,insert_id_used,rand_used; bool system_thread,in_lock_tables,global_read_lock; @@ -668,7 +674,7 @@ public: net.report_error= 1; DBUG_PRINT("error",("Fatal error set")); } - inline CHARSET_INFO *charset() { return variables.collation_client; } + inline CHARSET_INFO *charset() { return variables.character_set_client; } }; /* diff --git a/sql/sql_db.cc b/sql/sql_db.cc index fe8a945bff8..f8cf1eee0c5 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -51,7 +51,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, 1 Could not create file or write to it. Error sent through my_error() */ -static bool write_db_opt(const char *path, HA_CREATE_INFO *create) +static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create) { register File file; char buf[256]; // Should be enough for one option @@ -61,8 +61,9 @@ static bool write_db_opt(const char *path, HA_CREATE_INFO *create) { ulong length; CHARSET_INFO *cs= (create && create->table_charset) ? - create->table_charset : default_charset_info; - length= my_sprintf(buf,(buf, "default-character-set=%s\n", cs->name)); + create->table_charset : + thd->variables.character_set_database; + length= my_sprintf(buf,(buf, "default-character-set=%s\ndefault-collation=%s\n", cs->csname,cs->name)); /* Error is written by my_write */ if (!my_write(file,(byte*) buf, length, MYF(MY_NABP+MY_WME))) @@ -89,7 +90,7 @@ static bool write_db_opt(const char *path, HA_CREATE_INFO *create) */ -static bool load_db_opt(const char *path, HA_CREATE_INFO *create) +static bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create) { File file; char buf[256]; @@ -98,7 +99,7 @@ static bool load_db_opt(const char *path, HA_CREATE_INFO *create) uint nbytes; bzero((char*) create,sizeof(*create)); - create->table_charset= default_charset_info; + create->table_charset= global_system_variables.character_set_database; if ((file=my_open(path, O_RDONLY | O_SHARE, MYF(0))) >= 0) { IO_CACHE cache; @@ -115,12 +116,18 @@ static bool load_db_opt(const char *path, HA_CREATE_INFO *create) { if (!strncmp(buf,"default-character-set", (pos-buf))) { - if (strcmp(pos+1,"DEFAULT")) + if (!(create->table_charset=get_charset_by_csname(pos+1, + MY_CS_PRIMARY, + MYF(0)))) { - if (!(create->table_charset=get_charset_by_name(pos+1, MYF(0)))) - { - sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1); - } + sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1); + } + } + else if (!strncmp(buf,"default-collation", (pos-buf))) + { + if (!(create->table_charset=get_charset_by_name(pos+1, MYF(0)))) + { + sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1); } } } @@ -197,7 +204,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, unpack_dirname(path, path); strcat(path,MY_DB_OPT_FILE); - if (write_db_opt(path, create_info)) + if (write_db_opt(thd, path, create_info)) { /* Could not create options file. @@ -270,7 +277,7 @@ int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) /* Check directory */ (void)sprintf(path,"%s/%s/%s", mysql_data_home, db, MY_DB_OPT_FILE); fn_format(path, path, "", "", MYF(MY_UNPACK_FILENAME)); - if ((error=write_db_opt(path, create_info))) + if ((error=write_db_opt(thd, path, create_info))) goto exit; /* @@ -280,7 +287,9 @@ int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) if (thd->db && !strcmp(thd->db,db)) { thd->db_charset= (create_info && create_info->table_charset) ? - create_info->table_charset : default_charset_info; + create_info->table_charset : + global_system_variables.character_set_database; + thd->variables.character_set_database= thd->db_charset; } mysql_update_log.write(thd,thd->query, thd->query_length); @@ -401,6 +410,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, ulong found_other_files=0; char filePath[FN_REFLEN]; TABLE_LIST *tot_list=0, **tot_list_next; + List<String> raid_dirs; + DBUG_ENTER("mysql_rm_known_files"); DBUG_PRINT("enter",("path: %s", org_path)); @@ -420,6 +431,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, { char newpath[FN_REFLEN]; MY_DIR *new_dirp; + String *dir; + strxmov(newpath,org_path,"/",file->name,NullS); unpack_filename(newpath,newpath); if ((new_dirp = my_dir(newpath,MYF(MY_DONT_SORT)))) @@ -430,7 +443,11 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, my_dirend(dirp); DBUG_RETURN(-1); } + raid_dirs.push_back(dir=new String(newpath, &my_charset_latin1)); + dir->copy(); + continue; } + found_other_files++; continue; } if (find_type(fn_ext(file->name),&deletable_extentions,1+2) <= 0) @@ -440,7 +457,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, continue; } strxmov(filePath,org_path,"/",file->name,NullS); - if (db && !my_strcasecmp(&my_charset_latin1, + if (db && !my_strcasecmp(&my_charset_latin1, fn_ext(file->name), reg_ext)) { /* Drop the table nicely */ @@ -470,12 +487,19 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, deleted++; } } - my_dirend(dirp); - if (thd->killed || (tot_list && mysql_rm_table_part2_with_lock(thd, tot_list, 1, 0, 1))) + { + my_dirend(dirp); DBUG_RETURN(-1); - + } + List_iterator<String> it(raid_dirs); + String *dir; + while ((dir= it++)) + if (rmdir(dir->c_ptr()) < 0) + found_other_files++; + my_dirend(dirp); + /* If the directory is a symbolic link, remove the link first, then remove the directory the symbolic link pointed at @@ -573,11 +597,11 @@ bool mysql_change_db(THD *thd, const char *name) { net_printf(thd,ER_DBACCESS_DENIED_ERROR, thd->priv_user, - thd->host_or_ip, + thd->priv_host, dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, - thd->host_or_ip, + thd->priv_host, dbname); my_free(dbname,MYF(0)); DBUG_RETURN(1); @@ -600,8 +624,11 @@ bool mysql_change_db(THD *thd, const char *name) thd->db_access=db_access; strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE); - load_db_opt(path, &create); - thd->db_charset= create.table_charset ? create.table_charset : default_charset_info; + load_db_opt(thd, path, &create); + thd->db_charset= create.table_charset ? + create.table_charset : + global_system_variables.character_set_database; + thd->variables.character_set_database= thd->db_charset; DBUG_RETURN(0); } @@ -659,7 +686,7 @@ int mysqld_show_create_db(THD *thd, char *dbname, if (found_libchar) path[length-1]= FN_LIBCHAR; strmov(path+length, MY_DB_OPT_FILE); - load_db_opt(path, &create); + load_db_opt(thd, path, &create); List<Item> field_list; field_list.push_back(new Item_empty_string("Database",NAME_LEN)); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 6bb336a87a6..ebb09b99df7 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -67,7 +67,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, } /* Test if the user wants to delete all rows */ - if (!using_limit && const_cond && + if (!using_limit && const_cond && (!conds || conds->val_int()) && !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE))) { deleted= table->file->records; @@ -178,6 +178,15 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, (void) table->file->extra(HA_EXTRA_NORMAL); cleanup: + /* + Invalidate the table in the query cache if something changed. This must + be before binlog writing and ha_autocommit_... + */ + if (deleted) + { + query_cache_invalidate3(thd, table_list, 1); + } + transactional_table= table->file->has_transactions(); log_delayed= (transactional_table || table->tmp_table); if (deleted && (error <= 0 || !transactional_table)) @@ -199,14 +208,6 @@ cleanup: error=1; } - /* - Store table for future invalidation or invalidate it in - the query cache if something changed - */ - if (deleted) - { - query_cache_invalidate3(thd, table_list, 1); - } if (thd->lock) { mysql_unlock_tables(thd, thd->lock); @@ -480,6 +481,12 @@ bool multi_delete::send_eof() /* reset used flags */ thd->proc_info="end"; + /* + We must invalidate the query cache before binlog writing and + ha_autocommit_... + */ + if (deleted) + query_cache_invalidate3(thd, delete_tables, 1); /* Write the SQL statement to the binlog if we deleted @@ -504,9 +511,6 @@ bool multi_delete::send_eof() if (transactional_tables) if (ha_autocommit_or_rollback(thd,local_error > 0)) local_error=1; - - if (deleted) - query_cache_invalidate3(thd, delete_tables, 1); if (local_error) ::send_error(thd); diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 7f555f37d40..2bf1a68e504 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -116,7 +116,8 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *first_table= (TABLE_LIST*) select_cursor->table_list.first; /* Setting up. A must if a join or IGNORE, USE or similar are utilised */ if (setup_tables(first_table) || - setup_wild(thd, first_table, select_cursor->item_list, 0, select_cursor->with_wild)) + setup_wild(thd, first_table, select_cursor->item_list, 0, + select_cursor->with_wild)) { res= -1; goto exit; @@ -128,16 +129,18 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, (item_list.elements + select_cursor->with_sum_func + select_cursor->order_list.elements + select_cursor->group_list.elements)) || - setup_fields(thd, select_cursor->ref_pointer_array, first_table, item_list, - 0, 0, 1)) + setup_fields(thd, select_cursor->ref_pointer_array, first_table, + item_list, 0, 0, 1)) { res= -1; goto exit; } bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); tmp_table_param.field_count= item_list.elements; - /* temp table is created so that it hounours if UNION without ALL is to be - processed */ + /* + Temp table is created so that it hounours if UNION without ALL is to be + processed + */ if (!(table= create_tmp_table(thd, &tmp_table_param, item_list, (ORDER*) 0, is_union && !unit->union_option, 1, @@ -190,6 +193,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, org_table_list->table=table; table->derived_select_number= select_cursor->select_number; table->tmp_table= TMP_TABLE; + org_table_list->grant.privilege= SELECT_ACL; if (lex->describe) { // to fix a problem in EXPLAIN @@ -206,7 +210,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, /* Try to catch errors if this is accessed */ org_table_list->derived=(SELECT_LEX_UNIT *) 1; #endif -// This line is required to force read of table stats in the optimizer + // Force read of table stats in the optimizer table->file->info(HA_STATUS_VARIABLE); } } diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 3b9c329d5e5..db0dbe0dedc 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -79,6 +79,7 @@ void mysql_reset_errors(THD *thd) free_root(&thd->warn_root,MYF(0)); bzero((char*) thd->warn_count, sizeof(thd->warn_count)); thd->warn_list.empty(); + thd->row_count= 1; // by default point to row 1 } DBUG_VOID_RETURN; } diff --git a/sql/sql_help.cc b/sql/sql_help.cc index 36c7ef87b17..2925141d331 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -26,74 +26,155 @@ struct st_find_field static struct st_find_field init_used_fields[]= { - { "help_topic", "name", 0}, - { "help_topic","description", 0}, - { "help_topic","example", 0}, - { "help_topic", "help_topic_id", 0}, - { "help_category","name", 0}, - { "help_category","help_category_id", 0}, - { "help_relation","help_topic_id", 0}, - { "help_relation","help_category_id", 0} + { "help_topic", "help_topic_id", 0}, + { "help_topic", "name", 0}, + { "help_topic", "help_category_id", 0}, + { "help_topic", "description", 0}, + { "help_topic", "example", 0}, + + { "help_category", "help_category_id", 0}, + { "help_category", "parent_category_id", 0}, + { "help_category", "name", 0}, + + { "help_keyword", "help_keyword_id", 0}, + { "help_keyword", "name", 0}, + + { "help_relation", "help_topic_id", 0}, + { "help_relation", "help_keyword_id", 0} }; enum enum_used_fields { - help_topic_name=0, help_topic_description, help_topic_example, - help_topic_help_topic_id, - help_category_name, help_category_help_category_id, - help_relation_help_topic_id, help_relation_help_category_id + help_topic_help_topic_id= 0, + help_topic_name, + help_topic_help_category_id, + help_topic_description, + help_topic_example, + + help_category_help_category_id, + help_category_parent_category_id, + help_category_name, + + help_keyword_help_keyword_id, + help_keyword_name, + + help_relation_help_topic_id, + help_relation_help_keyword_id }; /* - Fill local used field structure with pointer to fields */ + Fill st_find_field structure with pointers to fields + + SYNOPSIS + init_fields() + thd Thread handler + tables list of all tables for fields + find_fields array of structures + count size of previous array + + RETURN VALUES + 0 all ok + 1 one of the fileds didn't finded +*/ static bool init_fields(THD *thd, TABLE_LIST *tables, - struct st_find_field *find_field, - uint count) + struct st_find_field *find_fields, uint count) { - for (; count-- ; find_field++) + DBUG_ENTER("init_fields"); + for (; count-- ; find_fields++) { TABLE_LIST *not_used; /* We have to use 'new' here as field will be re_linked on free */ - Item_field *field= new Item_field("mysql", find_field->table_name, - find_field->field_name); - if (!(find_field->field= find_field_in_tables(thd, field, tables, - ¬_used, - TRUE))) - return 1; + Item_field *field= new Item_field("mysql", find_fields->table_name, + find_fields->field_name); + if (!(find_fields->field= find_field_in_tables(thd, field, tables, + ¬_used, TRUE))) + DBUG_RETURN(1); } - return 0; + DBUG_RETURN(0); } +/* + + Returns variants of found topic for help (if it is just single topic, + returns description and example, or else returns only names..) + + SYNOPSIS + memorize_variant_topic() + + thd Thread handler + topics Table of topics + count number of alredy found topics + find_fields Filled array of information for work with fields + + RETURN VALUES + names array of names of found topics (out) -#define help_charset &my_charset_latin1 + name name of found topic (out) + description description of found topic (out) + example example for found topic (out) + + NOTE + Field 'names' is set only if more than one topic is found. + Fields 'name', 'description', 'example' are set only if + found exactly one topic. +*/ + +void memorize_variant_topic(THD *thd, TABLE *topics, int count, + struct st_find_field *find_fields, + List<String> *names, + String *name, String *description, String *example) +{ + DBUG_ENTER("memorize_variant_topic"); + MEM_ROOT *mem_root= &thd->mem_root; + if (count==0) + { + get_field(mem_root,find_fields[help_topic_name].field, name); + get_field(mem_root,find_fields[help_topic_description].field, description); + get_field(mem_root,find_fields[help_topic_example].field, example); + } + else + { + if (count==1) + names->push_back(name); + String *new_name= new String; + get_field(mem_root,find_fields[help_topic_name].field,new_name); + names->push_back(new_name); + } + DBUG_VOID_RETURN; +} /* Look for topics by mask SYNOPSIS search_topics() - thd Thread handler - topics Table of topic - select Function to test for if matching help topic. - Normally 'help_topic.name like 'bit%' - pfname Pointer to Field structure for field "name" - names List of founded topic's names (out) - name Name of founded topic (out), - Only set if founded exactly one topic) - description Description of founded topic (out) - Only set if founded exactly one topic. - example Example for founded topic (out) - Only if founded exactly one topic. + thd Thread handler + topics Table of topics + find_fields Filled array of info for fields + select Function to test for matching help topic. + Normally 'help_topic.name like 'bit%' + RETURN VALUES - # number of topics founded + # number of topics found + + names array of names of found topics (out) + name name of found topic (out) + description description of found topic (out) + example example for found topic (out) + + NOTE + Field 'names' is set only if more than one topic was found. + Fields 'name', 'description', 'example' are set only if + exactly one topic was found. + */ -int search_topics(THD *thd, TABLE *topics, struct st_find_field *find_field, - SQL_SELECT *select, List<char> *names, - char **name, char **description, char **example) +int search_topics(THD *thd, TABLE *topics, struct st_find_field *find_fields, + SQL_SELECT *select, List<String> *names, + String *name, String *description, String *example) { - DBUG_ENTER("search_functions"); + DBUG_ENTER("search_topics"); int count= 0; READ_RECORD read_record_info; @@ -102,139 +183,93 @@ int search_topics(THD *thd, TABLE *topics, struct st_find_field *find_field, { if (!select->cond->val_int()) // Dosn't match like continue; - - char *lname= get_field(&thd->mem_root, find_field[help_topic_name].field); + memorize_variant_topic(thd,topics,count,find_fields, + names,name,description,example); count++; - if (count > 2) - { - names->push_back(lname); - } - else if (count == 1) - { - *description= get_field(&thd->mem_root, - find_field[help_topic_description].field); - *example= get_field(&thd->mem_root, - find_field[help_topic_example].field); - *name= lname; - } - else - { - names->push_back(*name); - names->push_back(lname); - *name= 0; - *description= 0; - *example= 0; - } } end_read_record(&read_record_info); + DBUG_RETURN(count); } /* - Look for categories by mask + Look for keyword by mask SYNOPSIS - search_categories() - thd THD for init_read_record - categories Table of categories - select Function to test for if matching help topic. - Normally 'help_topic.name like 'bit%' - names List of founded topic's names (out) - res_id Primary index of founded category (only if - founded exactly one category) + search_keyword() + thd Thread handler + keywords Table of keywords + find_fields Filled array of info for fields + select Function to test for matching keyword. + Normally 'help_keyword.name like 'bit%' + + key_id help_keyword_if of found topics (out) RETURN VALUES - # Number of categories founded + 0 didn't find any topics matching the mask + 1 found exactly one topic matching the mask + 2 found more then one topic matching the mask */ -int search_categories(THD *thd, TABLE *categories, - struct st_find_field *find_fields, - SQL_SELECT *select, List<char> *names, int16 *res_id) +int search_keyword(THD *thd, TABLE *keywords, struct st_find_field *find_fields, + SQL_SELECT *select, int *key_id) { - Field *pfname= find_fields[help_category_name].field; - DBUG_ENTER("search_categories"); + DBUG_ENTER("search_keyword"); int count= 0; - READ_RECORD read_record_info; - init_read_record(&read_record_info, thd, categories, select,1,0); - while (!read_record_info.read_record(&read_record_info)) + READ_RECORD read_record_info; + init_read_record(&read_record_info, thd, keywords, select,1,0); + while (!read_record_info.read_record(&read_record_info) && count<2) { - if (select && !select->cond->val_int()) + if (!select->cond->val_int()) // Dosn't match like continue; - char *lname= get_field(&thd->mem_root,pfname); - if (++count == 1 && res_id) - { - Field *pcat_id= find_fields[help_category_help_category_id].field; - *res_id= (int16) pcat_id->val_int(); - } - names->push_back(lname); + + *key_id= find_fields[help_keyword_help_keyword_id].field->val_int(); + + count++; } end_read_record(&read_record_info); - + DBUG_RETURN(count); } - /* - Send to client rows in format: - column1 : <name> - column2 : <is_it_category> + Look for all topics with keyword SYNOPSIS - send_variant_2_list() - protocol Protocol for sending - names List of names - cat Value of the column <is_it_category> + get_topics_for_keyword() + thd Thread handler + topics Table of topics + relations Table of m:m relation "topic/keyword" + find_fields Filled array of info for fields + key_id Primary index to use to find for keyword RETURN VALUES - -1 Writing fail - 0 Data was successefully send -*/ - -int send_variant_2_list(Protocol *protocol, List<char> *names, - const char *cat) -{ - DBUG_ENTER("send_names"); - - List_iterator<char> it(*names); - const char *cur_name; - while ((cur_name= it++)) - { - protocol->prepare_for_resend(); - protocol->store(cur_name, system_charset_info); - protocol->store(cat, system_charset_info); - if (protocol->write()) - DBUG_RETURN(-1); - } - DBUG_RETURN(0); -} + # number of topics found + names array of name of found topics (out) -/* - Look for all topics of category + name name of found topic (out) + description description of found topic (out) + example example for found topic (out) - SYNOPSIS - get_all_topics_for_category() - thd Thread handler - topics Table of topics - relations Table of m:m relation "topic/category" - cat_id Primary index looked for category - res List of founded topic's names (out) - - RETURN VALUES - -1 corrupt database - 0 succesefull + NOTE + Field 'names' is set only if more than one topic was found. + Fields 'name', 'description', 'example' are set only if + exactly one topic was found. */ -int get_all_topics_for_category(THD *thd, TABLE *topics, TABLE *relations, - struct st_find_field *find_fields, - int16 cat_id, List<char> *res) +int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, + struct st_find_field *find_fields, int16 key_id, + List<String> *names, + String *name, String *description, String *example) { - char buff[8]; // Max int length - DBUG_ENTER("get_all_topics_for_category"); - + char buff[8]; // Max int length + int count= 0; int iindex_topic, iindex_relations; - Field *rtopic_id, *rcat_id; + Field *rtopic_id, *rkey_id; + + DBUG_ENTER("get_topics_for_keyword"); if ((iindex_topic= find_type((char*) "PRIMARY", &topics->keynames, 1+2)-1)<0 || @@ -245,37 +280,156 @@ int get_all_topics_for_category(THD *thd, TABLE *topics, TABLE *relations, DBUG_RETURN(-1); } rtopic_id= find_fields[help_relation_help_topic_id].field; - rcat_id= find_fields[help_relation_help_category_id].field; + rkey_id= find_fields[help_relation_help_keyword_id].field; topics->file->index_init(iindex_topic); relations->file->index_init(iindex_relations); - rcat_id->store((longlong) cat_id); - rcat_id->get_key_image(buff, rcat_id->pack_length(), help_charset, + rkey_id->store((longlong) key_id); + rkey_id->get_key_image(buff, rkey_id->pack_length(), rkey_id->charset(), Field::itRAW); int key_res= relations->file->index_read(relations->record[0], - (byte *)buff, rcat_id->pack_length(), + (byte *)buff, rkey_id->pack_length(), HA_READ_KEY_EXACT); - for ( ; !key_res && cat_id == (int16) rcat_id->val_int() ; + for ( ; + !key_res && key_id == (int16) rkey_id->val_int() ; key_res= relations->file->index_next(relations->record[0])) { char topic_id_buff[8]; longlong topic_id= rtopic_id->val_int(); Field *field= find_fields[help_topic_help_topic_id].field; field->store((longlong) topic_id); - field->get_key_image(topic_id_buff, field->pack_length(), help_charset, + field->get_key_image(topic_id_buff, field->pack_length(), field->charset(), Field::itRAW); - + if (!topics->file->index_read(topics->record[0], (byte *)topic_id_buff, - field->pack_length(), - HA_READ_KEY_EXACT)) - res->push_back(get_field(&thd->mem_root, - find_fields[help_topic_name].field)); + field->pack_length(), HA_READ_KEY_EXACT)) + { + memorize_variant_topic(thd,topics,count,find_fields, + names,name,description,example); + count++; + } } - DBUG_RETURN(0); + DBUG_RETURN(count); +} + +/* + Look for topics with keyword by mask + + SYNOPSIS + search_topics_by_keyword() + thd Thread handler + keywords Table of keywords + topics Table of topics + relations Table of m:m relation "topic/keyword" + find_fields Filled array of info for fields + select Function to test for if matching help keyword. + Normally 'help_keyword.name like 'bit%' + + RETURN VALUES + # number of topics found + + names array of name of found topics (out) + + name name of found topic (out) + description description of found topic (out) + example example for found topic (out) + + NOTE + Field 'names' is set only if more than one topic was found. + Fields 'name', 'description', 'example' are set only if + exactly one topic was found. +*/ + +int search_topics_by_keyword(THD *thd, + TABLE *keywords, TABLE *topics, TABLE *relations, + struct st_find_field *find_fields, + SQL_SELECT *select, List<String> *names, + String *name, String *description, String *example) +{ + int key_id; + return search_keyword(thd,keywords,find_fields,select,&key_id)!=1 + ? 0 : get_topics_for_keyword(thd,topics,relations,find_fields,key_id, + names,name,description,example); +} + +/* + Look for categories by mask + + SYNOPSIS + search_categories() + thd THD for init_read_record + categories Table of categories + find_fields Filled array of info for fields + select Function to test for if matching help topic. + Normally 'help_vategory.name like 'bit%' + names List of found categories names (out) + res_id Primary index of found category (only if + found exactly one category) + + RETURN VALUES + # Number of categories found +*/ + +int search_categories(THD *thd, TABLE *categories, + struct st_find_field *find_fields, + SQL_SELECT *select, List<String> *names, int16 *res_id) +{ + Field *pfname= find_fields[help_category_name].field; + Field *pcat_id= find_fields[help_category_help_category_id].field; + int count= 0; + READ_RECORD read_record_info; + + DBUG_ENTER("search_categories"); + + init_read_record(&read_record_info, thd, categories, select,1,0); + while (!read_record_info.read_record(&read_record_info)) + { + if (select && !select->cond->val_int()) + continue; + String *lname= new String; + get_field(&thd->mem_root,pfname,lname); + if (++count == 1 && res_id) + *res_id= (int16) pcat_id->val_int(); + names->push_back(lname); + } + end_read_record(&read_record_info); + + DBUG_RETURN(count); } +/* + Look for all topics or subcategories of category + + SYNOPSIS + get_all_items_for_category() + thd Thread handler + items Table of items + pfname Field "name" in items + select "where" part of query.. + res list of finded names +*/ + +void get_all_items_for_category(THD *thd, TABLE *items, Field *pfname, + SQL_SELECT *select, List<String> *res) +{ + DBUG_ENTER("get_all_items_for_category"); + + READ_RECORD read_record_info; + init_read_record(&read_record_info, thd, items, select,1,0); + while (!read_record_info.read_record(&read_record_info)) + { + if (!select->cond->val_int()) + continue; + String *name= new String(); + get_field(&thd->mem_root,pfname,name); + res->push_back(name); + } + end_read_record(&read_record_info); + + DBUG_VOID_RETURN; +} /* Send to client answer for help request @@ -284,17 +438,16 @@ int get_all_topics_for_category(THD *thd, TABLE *topics, TABLE *relations, send_answer_1() protocol - protocol for sending s1 - value of column "Name" - s2 - value of column "Category" - s3 - value of column "Description" - s4 - value of column "Example" + s2 - value of column "Description" + s3 - value of column "Example" IMPLEMENTATION Format used: - +----------+---------+------------+------------+ - |Name: |Category |Description |Example | - +----------+---------+------------+------------+ - |String(64)|String(1)|String(1000)|String(1000)| - +----------+---------+------------+------------+ + +----------+------------+------------+ + |name |description |example | + +----------+------------+------------+ + |String(64)|String(1000)|String(1000)| + +----------+------------+------------+ with exactly one row! RETURN VALUES @@ -303,24 +456,21 @@ int get_all_topics_for_category(THD *thd, TABLE *topics, TABLE *relations, 0 Successeful send */ -int send_answer_1(Protocol *protocol, const char *s1, const char *s2, - const char *s3, const char *s4) +int send_answer_1(Protocol *protocol, String *s1, String *s2, String *s3) { DBUG_ENTER("send_answer_1"); List<Item> field_list; - field_list.push_back(new Item_empty_string("Name",64)); - field_list.push_back(new Item_empty_string("Category",1)); - field_list.push_back(new Item_empty_string("Description",1000)); - field_list.push_back(new Item_empty_string("Example",1000)); + field_list.push_back(new Item_empty_string("name",64)); + field_list.push_back(new Item_empty_string("description",1000)); + field_list.push_back(new Item_empty_string("example",1000)); if (protocol->send_fields(&field_list,1)) DBUG_RETURN(1); protocol->prepare_for_resend(); - protocol->store(s1, system_charset_info); - protocol->store(s2, system_charset_info); - protocol->store(s3, system_charset_info); - protocol->store(s4, system_charset_info); + protocol->store(s1); + protocol->store(s2); + protocol->store(s3); if (protocol->write()) DBUG_RETURN(-1); DBUG_RETURN(0); @@ -332,28 +482,151 @@ int send_answer_1(Protocol *protocol, const char *s1, const char *s2, SYNOPSIS send_header_2() - protocol - protocol for sending + protocol - protocol for sending + is_it_category - need column 'source_category_name' IMPLEMENTATION - +----------+---------+ - |Name: |Category | - +----------+---------+ - |String(64)|String(1)| - +----------+---------+ + +- -+ + |+-------------------- | +----------+--------------+ + ||source_category_name | |name |is_it_category| + |+-------------------- | +----------+--------------+ + ||String(64) | |String(64)|String(1) | + |+-------------------- | +----------+--------------+ + +- -+ RETURN VALUES result of protocol->send_fields */ -int send_header_2(Protocol *protocol) +int send_header_2(Protocol *protocol, bool for_category) { - DBUG_ENTER("send_header2"); + DBUG_ENTER("send_header_2"); List<Item> field_list; - field_list.push_back(new Item_empty_string("Name",64)); - field_list.push_back(new Item_empty_string("Category",1)); + if (for_category) + field_list.push_back(new Item_empty_string("source_category_name",64)); + field_list.push_back(new Item_empty_string("name",64)); + field_list.push_back(new Item_empty_string("is_it_category",1)); DBUG_RETURN(protocol->send_fields(&field_list,1)); } +/* + strcmp for using in qsort + + SYNOPSIS + strptrcmp() + ptr1 (const void*)&str1 + ptr2 (const void*)&str2 + + RETURN VALUES + same as strcmp +*/ + +int string_ptr_cmp(const void* ptr1, const void* ptr2) +{ + String *str1= *(String**)ptr1; + String *str2= *(String**)ptr2; + return strcmp(str1->c_ptr(),str2->c_ptr()); +} + +/* + Send to client rows in format: + column1 : <name> + column2 : <is_it_category> + + SYNOPSIS + send_variant_2_list() + protocol Protocol for sending + names List of names + cat Value of the column <is_it_category> + source_name name of category for all items.. + + RETURN VALUES + -1 Writing fail + 0 Data was successefully send +*/ + +int send_variant_2_list(MEM_ROOT *mem_root, Protocol *protocol, + List<String> *names, + const char *cat, String *source_name) +{ + DBUG_ENTER("send_variant_2_list"); + + String **pointers= (String**)alloc_root(mem_root, + sizeof(String*)*names->elements); + String **pos= pointers; + + List_iterator<String> it(*names); + String *cur_name; + while ((*pos++= it++)); + + qsort(pointers,names->elements,sizeof(String*),string_ptr_cmp); + + String **end= pointers + names->elements; + for (String **pos= pointers; pos!=end; pos++) + { + protocol->prepare_for_resend(); + if (source_name) + protocol->store(source_name); + protocol->store(*pos); + protocol->store(cat,1,&my_charset_latin1); + if (protocol->write()) + DBUG_RETURN(-1); + } + + DBUG_RETURN(0); +} + +/* + Prepare simple SQL_SELECT table.* WHERE <Item> + + SYNOPSIS + prepare_simple_select() + thd Thread handler + cond WHERE part of select + tables list of tables, used in WHERE + table goal table + + error code of error (out) + + RETURN VALUES + # created SQL_SELECT +*/ + +SQL_SELECT *prepare_simple_select(THD *thd, Item *cond, TABLE_LIST *tables, + TABLE *table, int *error) +{ + cond->fix_fields(thd, tables, &cond); // can never fail + SQL_SELECT *res= make_select(table,0,0,cond,error); + return (*error || (res && res->check_quick(0, HA_POS_ERROR))) ? 0 : res; +} + +/* + Prepare simple SQL_SELECT table.* WHERE table.name LIKE mask + + SYNOPSIS + prepare_select_for_name() + thd Thread handler + mask mask for compare with name + mlen length of mask + tables list of tables, used in WHERE + table goal table + pfname field "name" in table + + error code of error (out) + + RETURN VALUES + # created SQL_SELECT +*/ + +SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen, + TABLE_LIST *tables, TABLE *table, + Field *pfname, int *error) +{ + Item *cond= new Item_func_like(new Item_field(pfname), + new Item_string(mask,mlen,pfname->charset()), + (char*) "\\"); + return prepare_simple_select(thd,cond,tables,table,error); +} /* Server-side function 'help' @@ -371,12 +644,13 @@ int send_header_2(Protocol *protocol) int mysqld_help(THD *thd, const char *mask) { Protocol *protocol= thd->protocol; - SQL_SELECT *select= 0, *select_cat= 0; - Item *cond_topic, *cond_cat; + SQL_SELECT *select_topics_by_name= 0, *select_keyword_by_name= 0, + *select_cat_by_name= 0, *select_topics_by_cat= 0, *select_cat_by_cat= 0, + *select_root_cats= 0; st_find_field used_fields[array_elements(init_used_fields)]; DBUG_ENTER("mysqld_help"); - TABLE_LIST tables[3]; + TABLE_LIST tables[4]; bzero((gptr)tables,sizeof(tables)); tables[0].alias= tables[0].real_name= (char*) "help_topic"; tables[0].lock_type= TL_READ; @@ -389,11 +663,17 @@ int mysqld_help(THD *thd, const char *mask) tables[2].alias= tables[2].real_name= (char*) "help_relation"; tables[2].lock_type= TL_READ; tables[2].db= (char*) "mysql"; - tables[2].next= 0; + tables[2].next= &tables[3]; + tables[3].alias= tables[3].real_name= (char*) "help_keyword"; + tables[3].lock_type= TL_READ; + tables[3].db= (char*) "mysql"; + tables[3].next= 0; - List<char> function_list, categories_list; - char *name, *description, *example; + List<String> topics_list, categories_list, subcategories_list; + String name, description, example; int res, count_topics, count_categories, error; + uint mlen= strlen(mask); + MEM_ROOT *mem_root= &thd->mem_root; if (open_and_lock_tables(thd, tables)) { @@ -409,111 +689,101 @@ int mysqld_help(THD *thd, const char *mask) goto end; } - /* TODO: Find out why these are needed (should not be) */ - tables[0].table->file->init_table_handle_for_HANDLER(); - tables[1].table->file->init_table_handle_for_HANDLER(); - tables[2].table->file->init_table_handle_for_HANDLER(); + for (size_t i=0; i<sizeof(tables)/sizeof(TABLE_LIST); i++) + tables[i].table->file->init_table_handle_for_HANDLER(); - cond_topic= new Item_func_like(new Item_field(used_fields[help_topic_name]. - field), - new Item_string(mask, strlen(mask), - help_charset), - (char*) "\\"); - cond_topic->fix_fields(thd, tables, &cond_topic); // can never fail - select= make_select(tables[0].table,0,0,cond_topic,&error); - if (error || (select && select->check_quick(0, HA_POS_ERROR))) - { - res= -1; - goto end; - } - - cond_cat= new Item_func_like(new Item_field(used_fields[help_category_name]. - field), - new Item_string(mask, strlen(mask), - help_charset), - (char*) "\\"); - cond_cat->fix_fields(thd, tables, &cond_topic); // can never fail - select_cat= make_select(tables[1].table,0,0,cond_cat,&error); - if (error || (select_cat && select_cat->check_quick(0, HA_POS_ERROR))) + if (!(select_topics_by_name= + prepare_select_for_name(thd,mask,mlen,tables,tables[0].table, + used_fields[help_topic_name].field,&error)) || + !(select_cat_by_name= + prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, + used_fields[help_category_name].field,&error))|| + !(select_keyword_by_name= + prepare_select_for_name(thd,mask,mlen,tables,tables[3].table, + used_fields[help_keyword_name].field,&error))) { res= -1; goto end; } res= 1; - count_topics= search_topics(thd,tables[0].table, used_fields, select, - &function_list, &name, &description, &example); + count_topics= search_topics(thd,tables[0].table,used_fields, + select_topics_by_name,&topics_list, + &name, &description, &example); + + if (count_topics == 0) + count_topics= search_topics_by_keyword(thd,tables[3].table,tables[0].table, + tables[2].table,used_fields, + select_keyword_by_name,&topics_list, + &name,&description,&example); + if (count_topics == 0) { int16 category_id; - Item *cond= - new Item_func_like(new - Item_field(used_fields[help_category_name].field), - new Item_string(mask, strlen(mask), - help_charset), - (char*) "\\"); - (void) cond->fix_fields(thd, tables, &cond); // can never fail - + Field *cat_cat_id= used_fields[help_category_parent_category_id].field; count_categories= search_categories(thd, tables[1].table, used_fields, - select_cat, &categories_list, - &category_id); - if (count_categories == 1) + select_cat_by_name, + &categories_list,&category_id); + if (!count_categories) { - if (get_all_topics_for_category(thd,tables[0].table, - tables[2].table, used_fields, - category_id, &function_list)) - { - res= -1; + if (send_header_2(protocol,false)) goto end; - } - List_iterator<char> it(function_list); - char *cur_topic; - char buff[1024]; - String example(buff, sizeof(buff), help_charset); - example.length(0); - - while ((cur_topic= it++)) - { - example.append(cur_topic); - example.append("\n",1); - } - if ((send_answer_1(protocol, categories_list.head(), - "Y","",example.ptr()))) + } + else if (count_categories > 1) + { + if (send_header_2(protocol,false) || + send_variant_2_list(mem_root,protocol,&categories_list,"Y",0)) goto end; } - else + else { - if (send_header_2(protocol)) + Field *topic_cat_id= used_fields[help_topic_help_category_id].field; + Item *cond_topic_by_cat= new Item_func_equal(new Item_field(topic_cat_id), + new Item_int(category_id)); + Item *cond_cat_by_cat= new Item_func_equal(new Item_field(cat_cat_id), + new Item_int(category_id)); + if (!(select_topics_by_cat= prepare_simple_select(thd,cond_topic_by_cat, + tables,tables[0].table, + &error)) || + !(select_cat_by_cat= prepare_simple_select(thd,cond_cat_by_cat,tables, + tables[1].table,&error))) + { + res= -1; goto end; - if (count_categories == 0) - search_categories(thd,tables[1].table, used_fields, (SQL_SELECT *) 0, - &categories_list, 0); - if (send_variant_2_list(protocol,&categories_list,"Y")) + } + get_all_items_for_category(thd,tables[0].table, + used_fields[help_topic_name].field, + select_topics_by_cat,&topics_list); + get_all_items_for_category(thd,tables[1].table, + used_fields[help_category_name].field, + select_cat_by_cat,&subcategories_list); + String *cat= categories_list.head(); + if (send_header_2(protocol, true) || + send_variant_2_list(mem_root,protocol,&topics_list, "N",cat) || + send_variant_2_list(mem_root,protocol,&subcategories_list,"Y",cat)) goto end; } } else if (count_topics == 1) { - if (send_answer_1(protocol,name,"N",description, example)) + if (send_answer_1(protocol,&name,&description,&example)) goto end; } else { /* First send header and functions */ - if (send_header_2(protocol) || - send_variant_2_list(protocol, &function_list, "N")) + if (send_header_2(protocol, false) || + send_variant_2_list(mem_root,protocol, &topics_list, "N", 0)) goto end; - search_categories(thd, tables[1].table, used_fields, select_cat, - &categories_list, 0); + search_categories(thd, tables[1].table, used_fields, + select_cat_by_name,&categories_list, 0); /* Then send categories */ - if (send_variant_2_list(protocol, &categories_list, "Y")) + if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0)) goto end; } res= 0; send_eof(thd); end: - delete select; - delete select_cat; DBUG_RETURN(res); } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 7418140517c..1908f898a27 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -258,7 +258,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, if (fields.elements || !value_count) { restore_record(table,default_values); // Get empty record - if (fill_record(fields,*values)|| thd->net.report_error || + if (fill_record(fields, *values, 0)|| thd->net.report_error || check_null_fields(thd,table)) { if (values_list.elements != 1 && !thd->net.report_error) @@ -276,7 +276,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, restore_record(table,default_values); // Get empty record else table->record[0][0]=table->default_values[0]; // Fix delete marker - if (fill_record(table->field,*values) || thd->net.report_error) + if (fill_record(table->field,*values, 0) || thd->net.report_error) { if (values_list.elements != 1 && ! thd->net.report_error) { @@ -306,6 +306,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, { // Get auto increment value id= thd->last_insert_id; } + thd->row_count++; } if (lock_type == TL_WRITE_DELAYED) { @@ -343,7 +344,16 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, else if (table->next_number_field) id=table->next_number_field->val_int(); // Return auto_increment value + /* + Invalidate the table in the query cache if something changed. + For the transactional algorithm to work the invalidation must be + before binlog writing and ha_autocommit_... + */ + if (info.copied || info.deleted) + query_cache_invalidate3(thd, table_list, 1); + transactional_table= table->file->has_transactions(); + log_delayed= (transactional_table || table->tmp_table); if ((info.copied || info.deleted) && (error <= 0 || !transactional_table)) { @@ -361,14 +371,6 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, if (transactional_table) error=ha_autocommit_or_rollback(thd,error); - /* - Store table for future invalidation or invalidate it in - the query cache if something changed - */ - if (info.copied || info.deleted) - { - query_cache_invalidate3(thd, table_list, 1); - } if (thd->lock) { mysql_unlock_tables(thd, thd->lock); @@ -483,7 +485,8 @@ int write_record(TABLE *table,COPY_INFO *info) key_copy((byte*) key,table,key_nr,0); if ((error=(table->file->index_read_idx(table->record[1],key_nr, (byte*) key, - table->key_info[key_nr].key_length, + table->key_info[key_nr]. + key_length, HA_READ_KEY_EXACT)))) goto err; } @@ -495,7 +498,7 @@ int write_record(TABLE *table,COPY_INFO *info) */ store_record(table,insert_values); restore_record(table,record[1]); - if (fill_record(*info->update_fields,*info->update_values)) + if (fill_record(*info->update_fields, *info->update_values, 0)) goto err; if ((error=table->file->update_row(table->record[1],table->record[0]))) goto err; @@ -506,10 +509,11 @@ int write_record(TABLE *table,COPY_INFO *info) { if (last_uniq_key(table,key_nr)) { - if ((error=table->file->update_row(table->record[1],table->record[0]))) + if ((error=table->file->update_row(table->record[1], + table->record[0]))) goto err; info->deleted++; - break; /* Update logfile and count */ + break; /* Update logfile and count */ } else if ((error=table->file->delete_row(table->record[1]))) goto err; @@ -708,6 +712,9 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) /* no match; create a new thread to handle the table */ if (!(tmp=find_handler(thd,table_list))) { + /* Don't create more than max_insert_delayed_threads */ + if (delayed_insert_threads >= max_insert_delayed_threads) + DBUG_RETURN(0); thd->proc_info="Creating delayed handler"; pthread_mutex_lock(&LOCK_delayed_create); if (!(tmp=find_handler(thd,table_list))) // Was just created @@ -1086,12 +1093,12 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg) while (!thd->killed) { int error; -#if (defined(HAVE_BROKEN_COND_TIMEDWAIT) || defined(HAVE_LINUXTHREADS)) +#if defined(HAVE_BROKEN_COND_TIMEDWAIT) error=pthread_cond_wait(&di->cond,&di->mutex); #else error=pthread_cond_timedwait(&di->cond,&di->mutex,&abstime); #ifdef EXTRA_DEBUG - if (error && error != EINTR) + if (error && error != EINTR && error != ETIMEDOUT) { fprintf(stderr, "Got error %d from pthread_cond_timedwait\n",error); DBUG_PRINT("error",("Got error %d from pthread_cond_timedwait", @@ -1393,9 +1400,9 @@ bool select_insert::send_data(List<Item> &values) return 0; } if (fields->elements) - fill_record(*fields,values); + fill_record(*fields, values, 1); else - fill_record(table->field,values); + fill_record(table->field, values, 1); if (thd->net.report_error || write_record(table,&info)) return 1; if (table->next_number_field) // Clear for next record @@ -1414,11 +1421,9 @@ void select_insert::send_error(uint errcode,const char *err) ::send_error(thd,errcode,err); table->file->extra(HA_EXTRA_NO_CACHE); table->file->activate_all_index(thd); - ha_rollback_stmt(thd); if (info.copied || info.deleted) - { query_cache_invalidate3(thd, table, 1); - } + ha_rollback_stmt(thd); } @@ -1429,6 +1434,14 @@ bool select_insert::send_eof() error=table->file->activate_all_index(thd); table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); + /* + We must invalidate the table in the query cache before binlog writing + and ha_autocommit_... + */ + + if (info.copied || info.deleted) + query_cache_invalidate3(thd, table, 1); + /* Write to binlog before commiting transaction */ if (mysql_bin_log.is_open()) { @@ -1438,10 +1451,6 @@ bool select_insert::send_eof() } if ((error2=ha_autocommit_or_rollback(thd,error)) && ! error) error=error2; - if (info.copied || info.deleted) - { - query_cache_invalidate3(thd, table, 1); - } if (error) { table->file->print_error(error,MYF(0)); @@ -1460,7 +1469,7 @@ bool select_insert::send_eof() thd->cuted_fields); if (last_insert_id) thd->insert_id(last_insert_id); // For update log - ::send_ok(thd,info.copied,last_insert_id,buff); + ::send_ok(thd,info.copied+info.deleted,last_insert_id,buff); mysql_update_log.write(thd,thd->query,thd->query_length); return 0; } @@ -1510,7 +1519,7 @@ bool select_create::send_data(List<Item> &values) unit->offset_limit_cnt--; return 0; } - fill_record(field,values); + fill_record(field, values, 1); if (thd->net.report_error ||write_record(table,&info)) return 1; if (table->next_number_field) // Clear for next record diff --git a/sql/sql_list.h b/sql/sql_list.h index f4cca627515..ff21663576a 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +/* Copyright (C) 2000-2003 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 @@ -368,6 +368,7 @@ template <class T> class I_List :private base_ilist { public: I_List() :base_ilist() {} + inline void empty() { base_ilist::empty(); } inline bool is_empty() { return base_ilist::is_empty(); } inline void append(T* a) { base_ilist::append(a); } inline void push_back(T* a) { base_ilist::push_back(a); } diff --git a/sql/sql_load.cc b/sql/sql_load.cc index a68eada0025..12acfb9b5df 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -185,7 +185,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, else { unpack_filename(name,ex->file_name); -#if !defined(__WIN__) && !defined(OS2) +#if !defined(__WIN__) && !defined(OS2) && ! defined(__NETWARE__) MY_STAT stat_info; if (!my_stat(name,&stat_info,MYF(MY_WME))) DBUG_RETURN(-1); @@ -215,7 +215,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, info.handle_duplicates=handle_duplicates; info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX; - READ_INFO read_info(file,tot_length,thd->db_charset, + READ_INFO read_info(file,tot_length,thd->variables.character_set_database, *field_term,*ex->line_start, *ex->line_term, *enclosed, info.escape_char, read_file_from_client, is_fifo); if (read_info.error) @@ -283,6 +283,12 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, table->copy_blobs=0; thd->count_cuted_fields=0; /* Don`t calc cuted fields */ + /* + We must invalidate the table in query cache before binlog writing and + ha_autocommit_... + */ + query_cache_invalidate3(thd, table_list, 0); + if (error) { if (transactional_table) @@ -344,8 +350,6 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, } if (transactional_table) error=ha_autocommit_or_rollback(thd,error); - query_cache_invalidate3(thd, table_list, 0); - err: if (thd->lock) { @@ -370,7 +374,8 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields, ulonglong id; DBUG_ENTER("read_fixed_length"); - id=0; + id= 0; + /* No fields can be null in this format. mark all fields as not null */ while ((sql_field= (Item_field*) it++)) sql_field->field->set_notnull(); @@ -389,11 +394,14 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields, #endif while ((sql_field= (Item_field*) it++)) { - Field *field=sql_field->field; + Field *field= sql_field->field; if (pos == read_info.row_end) { - thd->cuted_fields++; /* Not enough fields */ - field->reset(); + thd->cuted_fields++; /* Not enough fields */ + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_TOO_FEW_RECORDS, + ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count); + field->reset(); } else { @@ -403,14 +411,19 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields, field->field_length) length=field->field_length; save_chr=pos[length]; pos[length]='\0'; // Safeguard aganst malloc - field->store((char*) pos,length,read_info.read_charset); + field->store((char*) pos,length,read_info.read_charset); pos[length]=save_chr; if ((pos+=length) > read_info.row_end) pos= read_info.row_end; /* Fills rest with space */ } } if (pos != read_info.row_end) + { thd->cuted_fields++; /* To long row */ + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_TOO_MANY_RECORDS, + ER(ER_WARN_TOO_MANY_RECORDS), thd->row_count); + } if (write_record(table,&info)) DBUG_RETURN(1); /* @@ -426,7 +439,13 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields, if (read_info.next_line()) // Skip to next line break; if (read_info.line_cuted) + { thd->cuted_fields++; /* To long row */ + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_TOO_MANY_RECORDS, + ER(ER_WARN_TOO_MANY_RECORDS), thd->row_count); + } + thd->row_count++; } if (id && !read_info.error) thd->insert_id(id); // For binary/update log @@ -447,8 +466,8 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, DBUG_ENTER("read_sep_field"); enclosed_length=enclosed.length(); - id=0; - + id= 0; + for (;;it.rewind()) { if (thd->killed) @@ -477,8 +496,9 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, { if (field->type() == FIELD_TYPE_TIMESTAMP) ((Field_timestamp*) field)->set_time(); - else if (field != table->next_number_field) - thd->cuted_fields++; + else if (field != table->next_number_field) + field->set_warning((uint)MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_NULL_TO_NOTNULL); } continue; } @@ -497,6 +517,9 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, sql_field->field->set_null(); sql_field->field->reset(); thd->cuted_fields++; + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_TOO_FEW_RECORDS, + ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count); } } if (write_record(table,&info)) @@ -514,7 +537,13 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, if (read_info.next_line()) // Skip to next line break; if (read_info.line_cuted) + { thd->cuted_fields++; /* To long row */ + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS), + thd->row_count); + } + thd->row_count++; } if (id && !read_info.error) thd->insert_id(id); // For binary/update log diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1d2449839d8..f098ce0d0b6 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -59,6 +59,9 @@ static void refresh_status(void); static bool append_file_to_dir(THD *thd, char **filename_ptr, char *table_name); +static bool single_table_command_access(THD *thd, ulong privilege, + TABLE_LIST *tables, int *res); + const char *any_db="*any*"; // Special symbol for check_access const char *command_name[]={ @@ -213,7 +216,15 @@ static int check_user(THD *thd,enum_server_command command, const char *user, thd->db=0; thd->db_length=0; USER_RESOURCES ur; + char tmp_passwd[SCRAMBLE41_LENGTH]; DBUG_ENTER("check_user"); + + /* + Move password to temporary buffer as it may be stored in communication + buffer + */ + strmake(tmp_passwd, passwd, sizeof(tmp_passwd)); + passwd= tmp_passwd; // Use local copy /* We shall avoid dupplicate user allocations here */ if (!thd->user && !(thd->user = my_strdup(user, MYF(0)))) @@ -222,7 +233,8 @@ static int check_user(THD *thd,enum_server_command command, const char *user, DBUG_RETURN(1); } thd->master_access=acl_getroot(thd, thd->host, thd->ip, thd->user, - passwd, thd->scramble, &thd->priv_user, + passwd, thd->scramble, + &thd->priv_user, thd->priv_host, (protocol_version == 9 || !(thd->client_capabilities & CLIENT_LONG_PASSWORD)), @@ -230,9 +242,9 @@ static int check_user(THD *thd,enum_server_command command, const char *user, cur_priv_version,hint_user); DBUG_PRINT("info", - ("Capabilities: %d packet_length: %ld Host: '%s' User: '%s' Using password: %s Access: %u db: '%s'", + ("Capabilities: %d packet_length: %ld Host: '%s' Login user: '%s' Priv_user: '%s' Using password: %s Access: %u db: '%s'", thd->client_capabilities, thd->max_client_packet_length, - thd->host_or_ip, thd->priv_user, + thd->host_or_ip, thd->user, thd->priv_user, had_password ? "yes": "no", thd->master_access, thd->db ? thd->db : "*none*")); @@ -307,6 +319,7 @@ static int check_user(THD *thd,enum_server_command command, const char *user, DBUG_RETURN(error); } send_ok(thd); // Ready to handle questions + thd->password= test(passwd[0]); // Remember for error messages DBUG_RETURN(0); // ok } @@ -582,7 +595,6 @@ check_connections(THD *thd) DBUG_PRINT("info",("Host: %s",thd->host)); thd->host_or_ip= thd->host; thd->ip= 0; - thd->peer_port= 0; bzero((char*) &thd->remote,sizeof(struct sockaddr)); } /* Ensure that wrong hostnames doesn't cause buffer overflows */ @@ -592,8 +604,8 @@ check_connections(THD *thd) { /* buff[] needs to big enough to hold the server_version variable */ char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH+64]; - int client_flags = (CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB | - CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION); + ulong client_flags = (CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB | + CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION); if (opt_using_transactions) client_flags|=CLIENT_TRANSACTIONS; @@ -611,7 +623,7 @@ check_connections(THD *thd) memcpy(end,thd->scramble,SCRAMBLE_LENGTH+1); end+=SCRAMBLE_LENGTH +1; int2store(end,client_flags); - end[2]=(char) MY_CHARSET_CURRENT; + end[2]=(char) default_charset_info->number; int2store(end+3,thd->server_status); bzero(end+5,13); end+=18; @@ -635,11 +647,38 @@ check_connections(THD *thd) return(ER_OUT_OF_RESOURCES); thd->client_capabilities=uint2korr(net->read_pos); +#ifdef TO_BE_REMOVED_IN_4_1_RELEASE + /* + This is just a safety check against any client that would use the old + CLIENT_CHANGE_USER flag + */ + if ((thd->client_capabilities & CLIENT_PROTOCOL_41) && + !(thd->client_capabilities & (CLIENT_RESERVED | + CLIENT_SECURE_CONNECTION | + CLIENT_MULTI_RESULTS))) + thd->client_capabilities&= ~CLIENT_PROTOCOL_41; +#endif if (thd->client_capabilities & CLIENT_PROTOCOL_41) { thd->client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16; thd->max_client_packet_length= uint4korr(net->read_pos+4); - end= (char*) net->read_pos+8; + if (!(thd->variables.character_set_client= + get_charset((uint) net->read_pos[8], MYF(0)))) + { + thd->variables.character_set_client= + global_system_variables.character_set_client; + thd->variables.collation_connection= + global_system_variables.collation_connection; + thd->variables.character_set_results= + global_system_variables.character_set_results; + } + else + { + thd->variables.character_set_results= + thd->variables.collation_connection= + thd->variables.character_set_client; + } + end= (char*) net->read_pos+32; } else { @@ -751,7 +790,6 @@ check_connections(THD *thd) } else if (res) return -1; // Error sent from check_user() - thd->password=using_password; return 0; } @@ -770,7 +808,7 @@ pthread_handler_decl(handle_one_connection,arg) // The following calls needs to be done before we call DBUG_ macros if (!(test_flags & TEST_NO_THREADS) & my_thread_init()) { - close_connection(&thd->net,ER_OUT_OF_RESOURCES); + close_connection(thd, ER_OUT_OF_RESOURCES, 1); statistic_increment(aborted_connects,&LOCK_status); end_thread(thd,0); return 0; @@ -797,7 +835,7 @@ pthread_handler_decl(handle_one_connection,arg) #endif if (thd->store_globals()) { - close_connection(&thd->net,ER_OUT_OF_RESOURCES); + close_connection(thd, ER_OUT_OF_RESOURCES, 1); statistic_increment(aborted_connects,&LOCK_status); end_thread(thd,0); return 0; @@ -855,7 +893,7 @@ pthread_handler_decl(handle_one_connection,arg) } end_thread: - close_connection(net); + close_connection(thd, 0, 1); end_thread(thd,1); /* If end_thread returns, we are either running with --one-thread @@ -881,7 +919,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg) /* The following must be called before DBUG_ENTER */ if (my_thread_init() || thd->store_globals()) { - close_connection(&thd->net,ER_OUT_OF_RESOURCES); + close_connection(thd, ER_OUT_OF_RESOURCES, 1); thd->fatal_error(); goto end; } @@ -1284,7 +1322,8 @@ restore_user: break; #else { - char *fields; + char *fields, *pend; + String convname; TABLE_LIST table_list; statistic_increment(com_stat[SQLCOM_SHOW_FIELDS],&LOCK_status); bzero((char*) &table_list,sizeof(table_list)); @@ -1294,8 +1333,11 @@ restore_user: break; } thd->free_list=0; - table_list.alias= table_list.real_name= thd->strdup(packet); - packet=strend(packet)+1; + pend= strend(packet); + convname.copy(packet, pend-packet, + thd->variables.character_set_client, system_charset_info); + table_list.alias= table_list.real_name= convname.c_ptr(); + packet= pend+1; // command not cachable => no gap for data base name if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1))) break; @@ -1411,7 +1453,7 @@ restore_user: #ifndef OS2 send_eof(thd); // This is for 'quit request' #endif - close_connection(net); + close_connection(thd, 0, 1); close_thread_tables(thd); // Free before kill free_root(&thd->mem_root,MYF(0)); free_root(&thd->transaction.mem_root,MYF(0)); @@ -1551,7 +1593,8 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length) /* We must allocate some extra memory for query cache */ if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet), packet_length, - thd->db_length+2))) + thd->db_length+2+ + sizeof(ha_rows)))) return 1; thd->query[packet_length]=0; thd->query_length= packet_length; @@ -1648,6 +1691,18 @@ mysql_execute_command(THD *thd) #endif ) DBUG_VOID_RETURN; + + /* + When option readonly is set deny operations which change tables. + Except for the replication thread and the 'super' users. + */ + if (opt_readonly && + !(thd->slave_thread || (thd->master_access & SUPER_ACL)) && + (uc_update_queries[lex->sql_command] > 0)) + { + send_error(thd, ER_CANT_UPDATE_WITH_READLOCK); + DBUG_VOID_RETURN; + } statistic_increment(com_stat[lex->sql_command],&LOCK_status); switch (lex->sql_command) { @@ -1832,7 +1887,8 @@ mysql_execute_command(THD *thd) } case SQLCOM_SHOW_SLAVE_STAT: { - if (check_global_access(thd, SUPER_ACL)) + /* Accept one of two privileges */ + if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL)) goto error; LOCK_ACTIVE_MI; res = show_master_info(thd,active_mi); @@ -1841,7 +1897,8 @@ mysql_execute_command(THD *thd) } case SQLCOM_SHOW_MASTER_STAT: { - if (check_global_access(thd, SUPER_ACL)) + /* Accept one of two privileges */ + if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL)) goto error; res = show_binlog_info(thd); break; @@ -2247,15 +2304,10 @@ mysql_execute_command(THD *thd) TABLE_LIST *table; if (check_db_used(thd,tables)) goto error; - for (table=tables ; table ; table=table->next) - { - if (table->derived) - table->grant.privilege= SELECT_ACL; - else if (check_access(thd,UPDATE_ACL,table->db,&table->grant.privilege)) + + if (single_table_command_access(thd, UPDATE_ACL, tables, &res)) goto error; - } - if (grant_option && check_grant(thd,UPDATE_ACL,tables)) - goto error; + if (select_lex->item_list.elements != lex->value_list.elements) { send_error(thd,ER_WRONG_VALUE_COUNT); @@ -2309,10 +2361,10 @@ mysql_execute_command(THD *thd) my_bool update=(lex->value_list.elements ? UPDATE_ACL : 0); ulong privilege= (lex->duplicates == DUP_REPLACE ? INSERT_ACL | DELETE_ACL : INSERT_ACL | update); - if (check_access(thd,privilege,tables->db,&tables->grant.privilege)) - goto error; /* purecov: inspected */ - if (grant_option && check_grant(thd,privilege,tables)) - goto error; + + if (single_table_command_access(thd, privilege, tables, &res)) + goto error; + if (select_lex->item_list.elements != lex->value_list.elements) { send_error(thd,ER_WRONG_VALUE_COUNT); @@ -2394,10 +2446,9 @@ mysql_execute_command(THD *thd) break; case SQLCOM_DELETE: { - if (check_access(thd,DELETE_ACL,tables->db,&tables->grant.privilege)) - goto error; /* purecov: inspected */ - if (grant_option && check_grant(thd,DELETE_ACL,tables)) + if (single_table_command_access(thd, DELETE_ACL, tables, &res)) goto error; + // Set privilege for the WHERE clause tables->grant.want_privilege=(SELECT_ACL & ~tables->grant.privilege); res = mysql_delete(thd,tables, select_lex->where, @@ -3056,14 +3107,63 @@ error: } +/* + Check grants for commands which work only with one table and all other + tables belong to subselects. + + SYNOPSYS + single_table_command_access() + thd - Thread handler + privilege - asked privelage + tables - table list of command + res - pointer on result code variable + + RETURN + 0 - OK + 1 - access denied +*/ + +static bool single_table_command_access(THD *thd, ulong privilege, + TABLE_LIST *tables, int *res) + +{ + if (check_access(thd, privilege, tables->db, &tables->grant.privilege)) + return 1; + + // Show only 1 table for check_grant + TABLE_LIST *subselects_tables= tables->next; + tables->next= 0; + if (grant_option && check_grant(thd, privilege, tables)) + return 1; + + // check rights on tables of subselect (if exists) + if (subselects_tables) + { + tables->next= subselects_tables; + if ((*res= check_table_access(thd, SELECT_ACL, subselects_tables))) + return 1; + } + return 0; +} + + /**************************************************************************** Get the user (global) and database privileges for all used tables - Returns true (error) if we can't get the privileges and we don't use - table/column grants. - The idea of EXTRA_ACL is that one will be granted access to the table if - one has the asked privilege on any column combination of the table; For - example to be able to check a table one needs to have SELECT privilege on - any column of the table. + + NOTES + The idea of EXTRA_ACL is that one will be granted access to the table if + one has the asked privilege on any column combination of the table; For + example to be able to check a table one needs to have SELECT privilege on + any column of the table. + + RETURN + 0 ok + 1 If we can't get the privileges and we don't use table/column grants. + + save_priv In this we store global and db level grants for the table + Note that we don't store db level grants if the global grants + is enough to satisfy the request and the global grants contains + a SELECT grant. ****************************************************************************/ bool @@ -3088,7 +3188,17 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, if ((thd->master_access & want_access) == want_access) { - *save_priv=thd->master_access; + /* + If we don't have a global SELECT privilege, we have to get the database + specific access rights to be able to handle queries of type + UPDATE t1 SET a=1 WHERE b > 0 + */ + db_access= thd->db_access; + if (!(thd->master_access & SELECT_ACL) && + (db && (!thd->db || strcmp(db,thd->db)))) + db_access=acl_get(thd->host, thd->ip, (char*) &thd->remote.sin_addr, + thd->priv_user, db); /* purecov: inspected */ + *save_priv=thd->master_access | db_access; DBUG_RETURN(FALSE); } if (((want_access & ~thd->master_access) & ~(DB_ACLS | EXTRA_ACL)) || @@ -3097,7 +3207,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, if (!no_errors) net_printf(thd,ER_ACCESS_DENIED_ERROR, thd->priv_user, - thd->host_or_ip, + thd->priv_host, thd->password ? ER(ER_YES) : ER(ER_NO));/* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -3122,18 +3232,35 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, if (!no_errors) net_printf(thd,ER_DBACCESS_DENIED_ERROR, thd->priv_user, - thd->host_or_ip, + thd->priv_host, db ? db : thd->db ? thd->db : "unknown"); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } -/* check for global access and give descriptive error message if it fails */ +/* + check for global access and give descriptive error message if it fails + + SYNOPSIS + check_global_access() + thd Thread handler + want_access Use should have any of these global rights + + WARNING + One gets access rigth if one has ANY of the rights in want_access + This is useful as one in most cases only need one global right, + but in some case we want to check if the user has SUPER or + REPL_CLIENT_ACL rights. + + RETURN + 0 ok + 1 Access denied. In this case an error is sent to the client +*/ bool check_global_access(THD *thd, ulong want_access) { char command[128]; - if ((thd->master_access & want_access) == want_access) + if ((thd->master_access & want_access)) return 0; get_privilege_desc(command, sizeof(command), want_access); net_printf(thd,ER_SPECIFIC_ACCESS_DENIED_ERROR, @@ -3237,6 +3364,7 @@ static bool check_merge_table_access(THD *thd, char *db, #define used_stack(A,B) (long) (B - A) #endif +#ifndef EMBEDDED_LIBRARY bool check_stack_overrun(THD *thd,char *buf __attribute__((unused))) { long stack_used; @@ -3250,6 +3378,7 @@ bool check_stack_overrun(THD *thd,char *buf __attribute__((unused))) } return 0; } +#endif /* EMBEDDED_LIBRARY */ #define MY_YACC_INIT 1000 // Start with big alloc #define MY_YACC_MAX 32000 // Because of 'short' @@ -3548,9 +3677,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, new_field->comment.str= (char*) comment->str_value.ptr(); new_field->comment.length=comment->str_value.length(); } - if (length) - if (!(new_field->length= (uint) atoi(length))) - length=0; /* purecov: inspected */ + if (length && !(new_field->length= (uint) atoi(length))) + length=0; /* purecov: inspected */ uint sign_len=type_modifier & UNSIGNED_FLAG ? 0 : 1; if (new_field->length && new_field->decimals && @@ -3583,10 +3711,13 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, break; case FIELD_TYPE_DECIMAL: if (!length) - new_field->length = 10; // Default length for DECIMAL - new_field->length+=sign_len; - if (new_field->decimals) - new_field->length++; + new_field->length= 10; // Default length for DECIMAL + if (new_field->length < MAX_FIELD_WIDTH) // Skip wrong argument + { + new_field->length+=sign_len; + if (new_field->decimals) + new_field->length++; + } break; case FIELD_TYPE_STRING: case FIELD_TYPE_VAR_STRING: @@ -3716,12 +3847,13 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, { char *not_used; uint not_used2; + bool not_used3; thd->cuted_fields=0; String str,*res; res=default_value->val_str(&str); (void) find_set(interval, res->ptr(), res->length(), ¬_used, - ¬_used2); + ¬_used2, ¬_used3); if (thd->cuted_fields) { net_printf(thd,ER_INVALID_DEFAULT,field_name); @@ -4011,6 +4143,24 @@ void add_join_on(TABLE_LIST *b,Item *expr) } +/* + Mark that we have a NATURAL JOIN between two tables + + SYNOPSIS + add_join_natural() + a Table to do normal join with + b Do normal join with this table + + IMPLEMENTATION + This function just marks that table b should be joined with a. + The function setup_cond() will create in b->on_expr a list + of equal condition between all fields of the same name. + + SELECT * FROM t1 NATURAL LEFT JOIN t2 + <=> + SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... ) +*/ + void add_join_natural(TABLE_LIST *a,TABLE_LIST *b) { b->natural_join=a; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index a39541b0fc5..fe47e553cf3 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -22,7 +22,6 @@ #include "sql_repl.h" #include "sql_acl.h" #include "log_event.h" -#include "mini_client.h" #include <my_dir.h> extern const char* any_db; @@ -1079,6 +1078,9 @@ err: } send_eof(thd); + pthread_mutex_lock(&LOCK_thread_count); + thd->current_linfo = 0; + pthread_mutex_unlock(&LOCK_thread_count); DBUG_RETURN(0); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 85ebb9f207f..4167da5802a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -466,8 +466,17 @@ JOIN::optimize() if (tables_list && tmp_table_param.sum_func_count && ! group_list) { int res; + /* + opt_sum_query() returns -1 if no rows match to the WHERE conditions, + or 1 if all items were resolved, or 0, or an error number HA_ERR_... + */ if ((res=opt_sum_query(tables_list, all_fields, conds))) { + if (res > 1) + { + delete procedure; + DBUG_RETURN(-1); + } if (res < 0) { zero_result_cause= "No matching min/max row"; @@ -610,7 +619,17 @@ JOIN::optimize() select_distinct= 0; no_order= !order; if (all_order_fields_used) + { + if (order && skip_sort_order) + { + /* + Force MySQL to read the table in sorted order to get result in + ORDER BY order. + */ + tmp_table_param.quick_group=0; + } order=0; + } group=1; // For end_write_group } else @@ -2379,7 +2398,10 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, if (table->quick_keys & ((key_map) 1 << key)) records= (double) table->quick_rows[key]; else - records= (double) s->records/rec; // quick_range couldn't use key! + { + /* quick_range couldn't use key! */ + records= (double) s->records/rec; + } } else { @@ -3037,6 +3059,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) join->unit->select_limit_cnt)) < 0) DBUG_RETURN(1); // Impossible range sel->cond=orig_cond; + /* Fix for EXPLAIN */ + if (sel->quick) + join->best_positions[i].records_read= sel->quick->records; } else { @@ -4239,7 +4264,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, table->blob_ptr_size=mi_portable_sizeof_char_ptr; table->map=1; table->tmp_table= TMP_TABLE; - table->derived_select_number= 0; table->db_low_byte_first=1; // True for HEAP and MyISAM table->temp_pool_slot = temp_pool_slot; table->copy_blobs= 1; @@ -5027,6 +5051,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records) ha_rows found_records=join->found_records; READ_RECORD *info= &join_tab->read_record; + join->thd->row_count= 0; do { if (join->thd->killed) // Aborted by user @@ -5035,6 +5060,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records) return -2; /* purecov: inspected */ } join->examined_rows++; + join->thd->row_count++; if (!on_expr || on_expr->val_int()) { found=1; @@ -6249,14 +6275,14 @@ is_subkey(KEY_PART_INFO *key_part, KEY_PART_INFO *ref_key_part, */ static uint -test_if_subkey(ORDER *order, TABLE *table, uint ref, key_map usable_keys) +test_if_subkey(ORDER *order, TABLE *table, uint ref, uint ref_key_parts, + key_map usable_keys) { uint nr; uint min_length= (uint) ~0; uint best= MAX_KEY; uint not_used; KEY_PART_INFO *ref_key_part= table->key_info[ref].key_part; - uint ref_key_parts= table->key_info[ref].key_parts; KEY_PART_INFO *ref_key_part_end= ref_key_part + ref_key_parts; for (nr= 0; usable_keys; usable_keys>>= 1, nr++) @@ -6291,10 +6317,12 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, bool no_changes) { int ref_key; + uint ref_key_parts; TABLE *table=tab->table; SQL_SELECT *select=tab->select; key_map usable_keys; DBUG_ENTER("test_if_skip_sort_order"); + LINT_INIT(ref_key_parts); /* Check which keys can be used to resolve ORDER BY */ usable_keys= ~(key_map) 0; @@ -6310,9 +6338,15 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, ref_key= -1; if (tab->ref.key >= 0) // Constant range in WHERE - ref_key=tab->ref.key; + { + ref_key= tab->ref.key; + ref_key_parts= tab->ref.key_parts; + } else if (select && select->quick) // Range found by opt_range - ref_key=select->quick->index; + { + ref_key= select->quick->index; + ref_key_parts= select->quick->used_key_parts; + } if (ref_key >= 0) { @@ -6326,20 +6360,28 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, /* We come here when ref_key is not among usable_keys */ - uint a; - if ((a= test_if_subkey(order, table, ref_key, usable_keys)) < MAX_KEY) + uint new_ref_key; + /* + If using index only read, only consider other possible index only + keys + */ + if (table->used_keys & (((key_map) 1 << ref_key))) + usable_keys|= table->used_keys; + if ((new_ref_key= test_if_subkey(order, table, ref_key, ref_key_parts, + usable_keys)) < MAX_KEY) { + /* Found key that can be used to retrieve data in sorted order */ if (tab->ref.key >= 0) { - tab->ref.key= a; - table->file->index_init(a); + tab->ref.key= new_ref_key; + table->file->index_init(new_ref_key); } else { - select->quick->index= a; + select->quick->index= new_ref_key; select->quick->init(); } - ref_key= a; + ref_key= new_ref_key; } } /* Check if we get the rows in requested sorted order by using the key */ @@ -7249,7 +7291,8 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, while ((item=li++)) { - if (item->type() != Item::SUM_FUNC_ITEM && !item->marker) + if (item->type() != Item::SUM_FUNC_ITEM && !item->marker && + !item->const_item()) { my_printf_error(ER_WRONG_FIELD_WITH_GROUP, ER(ER_WRONG_FIELD_WITH_GROUP), @@ -7957,6 +8000,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, TABLE *table=tab->table; char buff[512],*buff_ptr=buff; char buff1[512], buff2[512]; + char derived_name[64]; String tmp1(buff1,sizeof(buff1),cs); String tmp2(buff2,sizeof(buff2),cs); tmp1.length(0); @@ -7970,13 +8014,13 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, cs)); if (tab->type == JT_ALL && tab->select && tab->select->quick) tab->type= JT_RANGE; - if (table->tmp_table == TMP_TABLE && table->derived_select_number != 0) + if (table->derived_select_number) { - // Derived table name generation - char buff[512]; - int len= my_snprintf(buff, 512, "<derived%u>", + /* Derived table name generation */ + int len= my_snprintf(derived_name, sizeof(derived_name)-1, + "<derived%u>", table->derived_select_number); - item_list.push_back(new Item_string(buff, len, cs)); + item_list.push_back(new Item_string(derived_name, len, cs)); } else item_list.push_back(new Item_string(table->table_name, @@ -8170,5 +8214,3 @@ void free_underlaid_joins(THD *thd, SELECT_LEX *select) unit= unit->next_unit()) unit->cleanup(); } - - diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 2b8982f2484..803280c56c6 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -679,7 +679,8 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, List<Item> field_list; field_list.push_back(new Item_empty_string("Field",NAME_LEN)); field_list.push_back(new Item_empty_string("Type",40)); - field_list.push_back(new Item_empty_string("Collation",40)); + if (verbose) + field_list.push_back(new Item_empty_string("Collation",40)); field_list.push_back(new Item_empty_string("Null",1)); field_list.push_back(new Item_empty_string("Key",3)); field_list.push_back(item=new Item_empty_string("Default",NAME_LEN)); @@ -719,8 +720,9 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, protocol->store(field->field_name, system_charset_info); field->sql_type(type); protocol->store(type.ptr(), type.length(), system_charset_info); - protocol->store(field->charset()->name, system_charset_info); - + if (verbose) + protocol->store(field->has_charset() ? field->charset()->name : "NULL", + system_charset_info); pos=(byte*) ((flags & NOT_NULL_FLAG) && field->type() != FIELD_TYPE_TIMESTAMP ? "" : "YES"); @@ -923,7 +925,10 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) protocol->store((const char*) pos, system_charset_info); protocol->store(table->file->index_type(i), system_charset_info); /* Comment */ - protocol->store("", system_charset_info); + if (!(table->keys_in_use & ((key_map) 1 << i))) + protocol->store("disabled",8, system_charset_info); + else + protocol->store("", 0, system_charset_info); if (protocol->write()) DBUG_RETURN(1); /* purecov: inspected */ } @@ -1070,23 +1075,36 @@ store_create_info(THD *thd, TABLE *table, String *packet) field->sql_type(type); packet->append(type.ptr(),type.length()); - bool has_default = (field->type() != FIELD_TYPE_BLOB && - field->type() != FIELD_TYPE_TIMESTAMP && - field->unireg_check != Field::NEXT_NUMBER); - - /* - For string types dump collation name only if - collation is not primary for the given charset - */ - if (!(field->charset()->state & MY_CS_PRIMARY) && - !limited_mysql_mode && !foreign_db_mode) + if (field->has_charset()) { - packet->append(" collate ", 9); - packet->append(field->charset()->name); + if (field->charset() == &my_charset_bin) + packet->append(" binary"); + else if (!limited_mysql_mode && !foreign_db_mode) + { + if (field->charset() != table->table_charset) + { + packet->append(" character set "); + packet->append(field->charset()->csname); + } + /* + For string types dump collation name only if + collation is not primary for the given charset + */ + if (!(field->charset()->state & MY_CS_PRIMARY)) + { + packet->append(" collate ", 9); + packet->append(field->charset()->name); + } + } } + if (flags & NOT_NULL_FLAG) packet->append(" NOT NULL", 9); + bool has_default = (field->type() != FIELD_TYPE_BLOB && + field->type() != FIELD_TYPE_TIMESTAMP && + field->unireg_check != Field::NEXT_NUMBER); + if (has_default) { packet->append(" default ", 9); @@ -1417,11 +1435,11 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) static bool write_collation(Protocol *protocol, CHARSET_INFO *cs) { protocol->prepare_for_resend(); - protocol->store(cs->csname, system_charset_info); protocol->store(cs->name, system_charset_info); + protocol->store(cs->csname, system_charset_info); protocol->store_short((longlong) cs->number); - protocol->store((cs->state & MY_CS_PRIMARY) ? "Y" : "",system_charset_info); - protocol->store((cs->state & MY_CS_COMPILED)? "Y" : "",system_charset_info); + protocol->store((cs->state & MY_CS_PRIMARY) ? "Yes" : "",system_charset_info); + protocol->store((cs->state & MY_CS_COMPILED)? "Yes" : "",system_charset_info); protocol->store_short((longlong) cs->strxfrm_multiply); return protocol->write(); } @@ -1437,11 +1455,11 @@ int mysqld_show_collations(THD *thd, const char *wild) DBUG_ENTER("mysqld_show_charsets"); - field_list.push_back(new Item_empty_string("Charset",30)); field_list.push_back(new Item_empty_string("Collation",30)); + field_list.push_back(new Item_empty_string("Charset",30)); field_list.push_back(new Item_return_int("Id",11, FIELD_TYPE_SHORT)); - field_list.push_back(new Item_empty_string("D",30)); - field_list.push_back(new Item_empty_string("C",30)); + field_list.push_back(new Item_empty_string("Default",30)); + field_list.push_back(new Item_empty_string("Compiled",30)); field_list.push_back(new Item_return_int("Sortlen",3, FIELD_TYPE_SHORT)); if (protocol->send_fields(&field_list, 1)) @@ -1587,7 +1605,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, case SHOW_QUESTION: end= int10_to_str((long) thd->query_id, buff, 10); break; -#ifndef EMBEDDED_LIBRARY +#ifdef HAVE_REPLICATION case SHOW_RPL_STATUS: end= strmov(buff, rpl_status_type[(int)rpl_status]); break; @@ -1599,7 +1617,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, UNLOCK_ACTIVE_MI; break; } -#endif /* EMBEDDED_LIBRARY */ +#endif /* HAVE_REPLICATION */ case SHOW_OPENTABLES: end= int10_to_str((long) cached_tables(), buff, 10); break; diff --git a/sql/sql_string.cc b/sql/sql_string.cc index ca38651b3b6..cf6645fa23e 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -28,15 +28,12 @@ #include <floatingpoint.h> #endif -CHARSET_INFO *system_charset_info= &my_charset_utf8; -CHARSET_INFO *files_charset_info= &my_charset_utf8; -CHARSET_INFO *national_charset_info= &my_charset_utf8; +CHARSET_INFO *system_charset_info= &my_charset_utf8_general_ci; +CHARSET_INFO *files_charset_info= &my_charset_utf8_general_ci; +CHARSET_INFO *national_charset_info= &my_charset_utf8_general_ci; extern gptr sql_alloc(unsigned size); extern void sql_element_free(void *ptr); -static uint32 -copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, - const char *from, uint32 from_length, CHARSET_INFO *from_cs); #include "sql_string.h" @@ -104,7 +101,7 @@ bool String::set(longlong num, CHARSET_INFO *cs) if (alloc(l)) return TRUE; - str_length=(uint32) (cs->longlong10_to_str)(cs,Ptr,l,-10,num); + str_length=(uint32) (cs->cset->longlong10_to_str)(cs,Ptr,l,-10,num); str_charset=cs; return FALSE; } @@ -115,7 +112,7 @@ bool String::set(ulonglong num, CHARSET_INFO *cs) if (alloc(l)) return TRUE; - str_length=(uint32) (cs->longlong10_to_str)(cs,Ptr,l,10,num); + str_length=(uint32) (cs->cset->longlong10_to_str)(cs,Ptr,l,10,num); str_charset=cs; return FALSE; } @@ -268,9 +265,9 @@ bool String::copy(const char *str, uint32 arg_length, */ -bool String::set_latin1(const char *str, uint32 arg_length) +bool String::set_ascii(const char *str, uint32 arg_length) { - if (str_charset->mbmaxlen == 1) + if (!(str_charset->state & MY_CS_NONTEXT)) { set(str, arg_length, str_charset); return 0; @@ -399,13 +396,13 @@ bool String::append(IO_CACHE* file, uint32 arg_length) uint32 String::numchars() { - return str_charset->numchars(str_charset, Ptr, Ptr+str_length); + return str_charset->cset->numchars(str_charset, Ptr, Ptr+str_length); } int String::charpos(int i,uint32 offset) { if (i<0) return i; - return str_charset->charpos(str_charset,Ptr+offset,Ptr+str_length,i); + return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i); } int String::strstr(const String &s,uint32 offset) @@ -583,7 +580,7 @@ void String::qs_append(const char &c) int sortcmp(const String *x,const String *y, CHARSET_INFO *cs) { - return cs->strnncollsp(cs, + return cs->coll->strnncollsp(cs, (unsigned char *) x->ptr(),x->length(), (unsigned char *) y->ptr(),y->length()); } @@ -630,7 +627,7 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length) */ -static uint32 +uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, const char *from, uint32 from_length, CHARSET_INFO *from_cs) { @@ -642,7 +639,7 @@ copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, while (1) { - if ((cnvres=from_cs->mb_wc(from_cs, &wc, (uchar*) from, from_end)) > 0) + if ((cnvres=from_cs->cset->mb_wc(from_cs, &wc, (uchar*) from, from_end)) > 0) from+= cnvres; else if (cnvres == MY_CS_ILSEQ) { @@ -653,7 +650,7 @@ copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, break; // Impossible char. outp: - if ((cnvres= to_cs->wc_mb(to_cs, wc, (uchar*) to, to_end)) > 0) + if ((cnvres= to_cs->cset->wc_mb(to_cs, wc, (uchar*) to, to_end)) > 0) to+= cnvres; else if (cnvres == MY_CS_ILUNI && wc != '?') { diff --git a/sql/sql_string.h b/sql/sql_string.h index 9c494600058..ee38853a2d3 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -27,6 +27,9 @@ class String; int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); +uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, + const char *from, uint32 from_length, + CHARSET_INFO *from_cs); class String { @@ -114,7 +117,7 @@ public: Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0; str_charset=cs; } - bool set_latin1(const char *str, uint32 arg_length); + bool set_ascii(const char *str, uint32 arg_length); inline void set_quick(char *str,uint32 arg_length, CHARSET_INFO *cs) { if (!alloced) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 3cac88d05b2..c53ca0b68a8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -23,6 +23,7 @@ #endif #include <hash.h> #include <myisam.h> +#include <my_dir.h> #ifdef __WIN__ #include <io.h> @@ -480,7 +481,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, { if (!sql_field->charset) sql_field->charset = create_info->table_charset ? - create_info->table_charset : thd->db_charset; + create_info->table_charset : + thd->variables.character_set_database; switch (sql_field->sql_type) { case FIELD_TYPE_BLOB: @@ -716,6 +718,14 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, column->field_name); DBUG_RETURN(-1); } + /* for fulltext keys keyseg length is 1 for blobs (it's ignored in + ft code anyway, and 0 (set to column width later) for char's. + it has to be correct col width for char's, as char data are not + prefixed with length (unlike blobs, where ft code takes data length + from a data prefix, ignoring column->length). + */ + if (key->type == Key::FULLTEXT) + column->length=test(f_is_blob(sql_field->pack_flag)); if (f_is_blob(sql_field->pack_flag)) { if (!(file->table_flags() & HA_BLOB_KEY)) @@ -726,15 +736,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, } if (!column->length) { - if (key->type == Key::FULLTEXT) - column->length=1; /* ft-code ignores it anyway :-) */ - else - { - my_printf_error(ER_BLOB_KEY_WITHOUT_LENGTH, - ER(ER_BLOB_KEY_WITHOUT_LENGTH),MYF(0), - column->field_name); - DBUG_RETURN(-1); - } + my_printf_error(ER_BLOB_KEY_WITHOUT_LENGTH, + ER(ER_BLOB_KEY_WITHOUT_LENGTH),MYF(0), + column->field_name); + DBUG_RETURN(-1); } } if (key->type == Key::SPATIAL) @@ -752,8 +757,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, { if (key->type == Key::PRIMARY) { - my_error(ER_PRIMARY_CANT_HAVE_NULL, MYF(0)); - DBUG_RETURN(-1); + /* Implicitly set primary key fields to NOT NULL for ISO conf. */ + sql_field->flags|= NOT_NULL_FLAG; + sql_field->pack_flag&= ~FIELDFLAG_MAYBE_NULL; } if (!(file->table_flags() & HA_NULL_KEY)) { @@ -1081,12 +1087,9 @@ mysql_rename_table(enum db_type base, Win32 clients must also have a WRITE LOCK on the table ! */ -bool close_cached_table(THD *thd,TABLE *table) +static void safe_remove_from_cache(THD *thd,TABLE *table) { - bool result=0; - DBUG_ENTER("close_cached_table"); - safe_mutex_assert_owner(&LOCK_open); - + DBUG_ENTER("safe_remove_from_cache"); if (table) { DBUG_PRINT("enter",("table: %s", table->real_name)); @@ -1109,16 +1112,29 @@ bool close_cached_table(THD *thd,TABLE *table) #endif /* When lock on LOCK_open is freed other threads can continue */ pthread_cond_broadcast(&COND_refresh); + } + DBUG_VOID_RETURN; +} + +bool close_cached_table(THD *thd,TABLE *table) +{ + DBUG_ENTER("close_cached_table"); + safe_mutex_assert_owner(&LOCK_open); + + if (table) + { + safe_remove_from_cache(thd,table); /* Close lock if this is not got with LOCK TABLES */ if (thd->lock) { - mysql_unlock_tables(thd, thd->lock); thd->lock=0; // Start locked threads + mysql_unlock_tables(thd, thd->lock); + thd->lock=0; // Start locked threads } /* Close all copies of 'table'. This also frees all LOCK TABLES lock */ thd->open_tables=unlink_open_table(thd,thd->open_tables,table); } - DBUG_RETURN(result); + DBUG_RETURN(0); } static int send_check_errmsg(THD *thd, TABLE_LIST* table, @@ -1199,69 +1215,105 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table, } -static int prepare_for_repair(THD* thd, TABLE_LIST* table, +static int prepare_for_repair(THD* thd, TABLE_LIST *table_list, HA_CHECK_OPT *check_opt) { + int error= 0; + TABLE tmp_table, *table; DBUG_ENTER("prepare_for_repair"); if (!(check_opt->sql_flags & TT_USEFRM)) - { DBUG_RETURN(0); - } - else + + if (!(table= table_list->table)) /* if open_ltable failed */ { + char name[FN_REFLEN]; + strxmov(name, mysql_data_home, "/", table_list->db, "/", + table_list->real_name, NullS); + if (openfrm(name, "", 0, 0, 0, &tmp_table)) + DBUG_RETURN(0); // Can't open frm file + table= &tmp_table; + } - char from[FN_REFLEN],tmp[FN_REFLEN]; - char* db = thd->db ? thd->db : table->db; + /* + User gave us USE_FRM which means that the header in the index file is + trashed. + In this case we will try to fix the table the following way: + - Rename the data file to a temporary name + - Truncate the table + - Replace the new data file with the old one + - Run a normal repair using the new index file and the old data file + */ - sprintf(from, "%s/%s/%s", mysql_real_data_home, db, table->real_name); - fn_format(from, from, "", MI_NAME_DEXT, 4); - sprintf(tmp,"%s-%lx_%lx", from, current_pid, thd->thread_id); + char from[FN_REFLEN],tmp[FN_REFLEN+32]; + const char **ext= table->file->bas_ext(); + MY_STAT stat_info; - pthread_mutex_lock(&LOCK_open); - close_cached_table(thd,table->table); - pthread_mutex_unlock(&LOCK_open); + /* + Check if this is a table type that stores index and data separately, + like ISAM or MyISAM + */ + if (!ext[0] || !ext[1]) + goto end; // No data file - if (lock_and_wait_for_table_name(thd,table)) - DBUG_RETURN(-1); + strxmov(from, table->path, ext[1], NullS); // Name of data file + if (!my_stat(from, &stat_info, MYF(0))) + goto end; // Can't use USE_FRM flag - if (my_rename(from, tmp, MYF(MY_WME))) - { - pthread_mutex_lock(&LOCK_open); - unlock_table_name(thd, table); - pthread_mutex_unlock(&LOCK_open); - DBUG_RETURN(send_check_errmsg(thd, table, "repair", - "Failed renaming .MYD file")); - } - if (mysql_truncate(thd, table, 1)) - { - pthread_mutex_lock(&LOCK_open); - unlock_table_name(thd, table); - pthread_mutex_unlock(&LOCK_open); - DBUG_RETURN(send_check_errmsg(thd, table, "repair", - "Failed generating table from .frm file")); - } - if (my_rename(tmp, from, MYF(MY_WME))) - { - pthread_mutex_lock(&LOCK_open); - unlock_table_name(thd, table); - pthread_mutex_unlock(&LOCK_open); - DBUG_RETURN(send_check_errmsg(thd, table, "repair", - "Failed restoring .MYD file")); - } + sprintf(tmp,"%s-%lx_%lx", from, current_pid, thd->thread_id); + + pthread_mutex_lock(&LOCK_open); + close_cached_table(thd,table_list->table); + pthread_mutex_unlock(&LOCK_open); + + if (lock_and_wait_for_table_name(thd,table_list)) + { + error= -1; + goto end; + } + if (my_rename(from, tmp, MYF(MY_WME))) + { + pthread_mutex_lock(&LOCK_open); + unlock_table_name(thd, table_list); + pthread_mutex_unlock(&LOCK_open); + error= send_check_errmsg(thd, table_list, "repair", + "Failed renaming data file"); + goto end; + } + if (mysql_truncate(thd, table_list, 1)) + { + pthread_mutex_lock(&LOCK_open); + unlock_table_name(thd, table_list); + pthread_mutex_unlock(&LOCK_open); + error= send_check_errmsg(thd, table_list, "repair", + "Failed generating table from .frm file"); + goto end; + } + if (my_rename(tmp, from, MYF(MY_WME))) + { + pthread_mutex_lock(&LOCK_open); + unlock_table_name(thd, table_list); + pthread_mutex_unlock(&LOCK_open); + error= send_check_errmsg(thd, table_list, "repair", + "Failed restoring .MYD file"); + goto end; } /* Now we should be able to open the partially repaired table to finish the repair in the handler later on. */ - if (!(table->table = reopen_name_locked_table(thd, table))) + if (!(table_list->table = reopen_name_locked_table(thd, table_list))) { pthread_mutex_lock(&LOCK_open); - unlock_table_name(thd, table); + unlock_table_name(thd, table_list); pthread_mutex_unlock(&LOCK_open); } - DBUG_RETURN(0); + +end: + if (table == &tmp_table) + closefrm(table); // Free allocated memory + DBUG_RETURN(error); } @@ -1759,9 +1811,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, case LEAVE_AS_IS: break; case ENABLE: - error=table->file->activate_all_index(thd); + safe_remove_from_cache(thd,table); + error= table->file->activate_all_index(thd); break; case DISABLE: + safe_remove_from_cache(thd,table); table->file->deactivate_non_unique_index(HA_POS_ERROR); break; } @@ -2403,6 +2457,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, handle_duplicates == DUP_REPLACE) to->file->extra(HA_EXTRA_IGNORE_DUP_KEY); next_field=to->next_number_field; + thd->row_count= 0; while (!(error=info.read_record(&info))) { if (thd->killed) @@ -2411,6 +2466,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, error= 1; break; } + thd->row_count++; if (next_field) next_field->reset(); for (Copy_field *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++) @@ -2428,7 +2484,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, delete_count++; } else - found_count++; + found_count++; } end_read_record(&info); free_io_cache(from); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index fe4ca49da14..1d0f37f0042 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -76,7 +76,7 @@ bool select_union::send_data(List<Item> &values) unit->offset_limit_cnt--; return 0; } - fill_record(table->field,values); + fill_record(table->field, values, 1); if (thd->net.report_error || write_record(table,&info)) { if (thd->net.last_errno == ER_RECORD_FILE_FULL) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 7c5983a0362..1f6364ec427 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -62,33 +62,46 @@ int mysql_update(THD *thd, int error=0; uint used_index, want_privilege; ulong query_id=thd->query_id, timestamp_query_id; + ha_rows updated, found; key_map old_used_keys; TABLE *table; SQL_SELECT *select; READ_RECORD info; - TABLE_LIST *update_table_list= (TABLE_LIST*) - thd->lex.select_lex.table_list.first; + TABLE_LIST *update_table_list= ((TABLE_LIST*) + thd->lex.select_lex.table_list.first); + TABLE_LIST tables; + List<Item> all_fields; DBUG_ENTER("mysql_update"); + LINT_INIT(used_index); LINT_INIT(timestamp_query_id); if ((open_and_lock_tables(thd, table_list))) DBUG_RETURN(-1); + thd->proc_info="init"; fix_tables_pointers(thd->lex.all_selects_list); table= table_list->table; - table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); - thd->proc_info="init"; /* Calculate "table->used_keys" based on the WHERE */ table->used_keys=table->keys_in_use; table->quick_keys=0; want_privilege=table->grant.want_privilege; table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege); - if (setup_tables(update_table_list) || - setup_conds(thd,update_table_list,&conds) - || setup_ftfuncs(&thd->lex.select_lex)) + + bzero((char*) &tables,sizeof(tables)); // For ORDER BY + tables.table= table; + + if (setup_tables(update_table_list) || + setup_conds(thd,update_table_list,&conds) || + setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array, + order_num) || + setup_order(thd, thd->lex.select_lex.ref_pointer_array, + &tables, all_fields, all_fields, order) || + setup_ftfuncs(&thd->lex.select_lex)) DBUG_RETURN(-1); /* purecov: inspected */ + + /* Check that we are not using table that we are updating in a sub select */ if (find_real_table_in_list(table_list->next, table_list->db, table_list->real_name)) { @@ -96,8 +109,7 @@ int mysql_update(THD *thd, DBUG_RETURN(-1); } - old_used_keys=table->used_keys; // Keys used in WHERE - + old_used_keys= table->used_keys; // Keys used in WHERE /* Change the query_id for the timestamp column so that we can check if this is modified directly @@ -151,10 +163,9 @@ int mysql_update(THD *thd, thd->lex.select_lex.options|=QUERY_NO_INDEX_USED; if (safe_update && !using_limit) { - delete select; - free_underlaid_joins(thd, &thd->lex.select_lex); - send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE); - DBUG_RETURN(1); + my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, + ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); + goto err; } } init_ftfuncs(thd, &thd->lex.select_lex, 1); @@ -175,14 +186,6 @@ int mysql_update(THD *thd, matching rows before updating the table! */ table->file->extra(HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE); - IO_CACHE tempfile; - if (open_cached_file(&tempfile, mysql_tmpdir,TEMP_PREFIX, - DISK_BUFFER_SIZE, MYF(MY_WME))) - { - delete select; /* purecov: inspected */ - free_underlaid_joins(thd, &thd->lex.select_lex); - DBUG_RETURN(-1); - } if (old_used_keys & ((key_map) 1 << used_index)) { table->key_read=1; @@ -191,94 +194,102 @@ int mysql_update(THD *thd, if (order) { + /* + Doing an ORDER BY; Let filesort find and sort the rows we are going + to update + */ uint length; SORT_FIELD *sortorder; - TABLE_LIST tables; List<Item> fields; - List<Item> all_fields; ha_rows examined_rows; - bzero((char*) &tables,sizeof(tables)); - tables.table = table; - table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE), - MYF(MY_FAE | MY_ZEROFILL)); - if (setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array, - order_num)|| - setup_order(thd, thd->lex.select_lex.ref_pointer_array, - &tables, fields, all_fields, order) || - !(sortorder=make_unireg_sortorder(order, &length)) || + MYF(MY_FAE | MY_ZEROFILL)); + if (!(sortorder=make_unireg_sortorder(order, &length)) || (table->sort.found_records = filesort(thd, table, sortorder, length, - (SQL_SELECT *) 0, - HA_POS_ERROR, &examined_rows)) + select, limit, + &examined_rows)) == HA_POS_ERROR) { - delete select; - free_underlaid_joins(thd, &thd->lex.select_lex); - DBUG_RETURN(-1); + free_io_cache(table); + goto err; } + /* + Filesort has already found and selected the rows we want to update, + so we don't need the where clause + */ + delete select; + select= 0; } + else + { + /* + We are doing a search on a key that is updated. In this case + we go trough the matching rows, save a pointer to them and + update these in a separate loop based on the pointer. + */ + + IO_CACHE tempfile; + if (open_cached_file(&tempfile, mysql_tmpdir,TEMP_PREFIX, + DISK_BUFFER_SIZE, MYF(MY_WME))) + goto err; - init_read_record(&info,thd,table,select,0,1); - thd->proc_info="Searching rows for update"; + init_read_record(&info,thd,table,select,0,1); + thd->proc_info="Searching rows for update"; + uint tmp_limit= limit; - while (!(error=info.read_record(&info)) && !thd->killed) - { - if (!(select && select->skipp_record())) + while (!(error=info.read_record(&info)) && !thd->killed) { - table->file->position(table->record[0]); - if (my_b_write(&tempfile,table->file->ref, - table->file->ref_length)) + if (!(select && select->skipp_record())) { - error=1; /* purecov: inspected */ - break; /* purecov: inspected */ + table->file->position(table->record[0]); + if (my_b_write(&tempfile,table->file->ref, + table->file->ref_length)) + { + error=1; /* purecov: inspected */ + break; /* purecov: inspected */ + } + if (!--limit && using_limit) + { + error= -1; + break; + } } } + limit= tmp_limit; + end_read_record(&info); + /* Change select to use tempfile */ + if (select) + { + delete select->quick; + if (select->free_cond) + delete select->cond; + select->quick=0; + select->cond=0; + } else { - if (!(test_flags & 512)) /* For debugging */ - { - DBUG_DUMP("record",(char*) table->record[0],table->reclength); - } + select= new SQL_SELECT; + select->head=table; } + if (reinit_io_cache(&tempfile,READ_CACHE,0L,0,0)) + error=1; /* purecov: inspected */ + select->file=tempfile; // Read row ptrs from this file + if (error >= 0) + goto err; } - end_read_record(&info); - if (table->key_read) { table->key_read=0; table->file->extra(HA_EXTRA_NO_KEYREAD); } - /* Change select to use tempfile */ - if (select) - { - delete select->quick; - if (select->free_cond) - delete select->cond; - select->quick=0; - select->cond=0; - } - else - { - select= new SQL_SELECT; - select->head=table; - } - if (reinit_io_cache(&tempfile,READ_CACHE,0L,0,0)) - error=1; /* purecov: inspected */ - select->file=tempfile; // Read row ptrs from this file - if (error >= 0) - { - delete select; - free_underlaid_joins(thd, &thd->lex.select_lex); - DBUG_RETURN(-1); - } } if (handle_duplicates == DUP_IGNORE) table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); init_read_record(&info,thd,table,select,0,1); - ha_rows updated=0L,found=0L; + updated= found= 0; thd->count_cuted_fields=1; /* calc cuted fields */ thd->cuted_fields=0L; thd->proc_info="Updating"; @@ -289,7 +300,7 @@ int mysql_update(THD *thd, if (!(select && select->skipp_record())) { store_record(table,record[1]); - if (fill_record(fields,values) || thd->net.report_error) + if (fill_record(fields,values, 0) || thd->net.report_error) break; /* purecov: inspected */ found++; if (compare_record(table, query_id)) @@ -298,11 +309,6 @@ int mysql_update(THD *thd, (byte*) table->record[0]))) { updated++; - if (!--limit && using_limit) - { - error= -1; - break; - } } else if (handle_duplicates != DUP_IGNORE || error != HA_ERR_FOUND_DUPP_KEY) @@ -312,13 +318,28 @@ int mysql_update(THD *thd, break; } } + if (!--limit && using_limit) + { + error= -1; // Simulate end of file + break; + } } else table->file->unlock_row(); + thd->row_count++; } end_read_record(&info); + free_io_cache(table); // If ORDER BY thd->proc_info="end"; VOID(table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY)); + + /* + Invalidate the table in the query cache if something changed. + This must be before binlog writing and ha_autocommit_... + */ + if (updated) + query_cache_invalidate3(thd, table_list, 1); + transactional_table= table->file->has_transactions(); log_delayed= (transactional_table || table->tmp_table); if (updated && (error <= 0 || !transactional_table)) @@ -340,14 +361,6 @@ int mysql_update(THD *thd, error=1; } - /* - Store table for future invalidation or invalidate it in - the query cache if something changed - */ - if (updated) - { - query_cache_invalidate3(thd, table_list, 1); - } if (thd->lock) { mysql_unlock_tables(thd, thd->lock); @@ -370,8 +383,17 @@ int mysql_update(THD *thd, } thd->count_cuted_fields=0; /* calc cuted fields */ free_io_cache(table); - DBUG_RETURN(0); + +err: + delete select; + free_underlaid_joins(thd, &thd->lex.select_lex); + if (table->key_read) + { + table->key_read=0; + table->file->extra(HA_EXTRA_NO_KEYREAD); + } + DBUG_RETURN(-1); } @@ -508,6 +530,8 @@ int multi_update::prepare(List<Item> ¬_used_values, SELECT_LEX_UNIT *unit) table->pos_in_table_list= tl; } } + + table_count= update.elements; update_tables= (TABLE_LIST*) update.first; @@ -732,7 +756,7 @@ bool multi_update::send_data(List<Item> ¬_used_values) { table->status|= STATUS_UPDATED; store_record(table,record[1]); - if (fill_record(*fields_for_table[offset], *values_for_table[offset])) + if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0)) DBUG_RETURN(1); found++; if (compare_record(table, thd->query_id)) @@ -760,7 +784,7 @@ bool multi_update::send_data(List<Item> ¬_used_values) { int error; TABLE *tmp_table= tmp_tables[offset]; - fill_record(tmp_table->field+1, *values_for_table[offset]); + fill_record(tmp_table->field+1, *values_for_table[offset], 1); found++; /* Store pointer to row */ memcpy((char*) tmp_table->field[0]->ptr, @@ -770,7 +794,7 @@ bool multi_update::send_data(List<Item> ¬_used_values) (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE)) { - if (create_myisam_from_heap(thd, table, tmp_table_param + offset, + if (create_myisam_from_heap(thd, tmp_table, tmp_table_param + offset, error, 1)) { do_update=0; @@ -926,6 +950,14 @@ bool multi_update::send_eof() int local_error = (table_count) ? do_updates(0) : 0; thd->proc_info= "end"; + /* We must invalidate the query cache before binlog writing and + ha_autocommit_... */ + + if (updated) + { + query_cache_invalidate3(thd, update_tables, 1); + } + /* Write the SQL statement to the binlog if we updated rows and we succeeded or if we updated some non @@ -964,10 +996,6 @@ bool multi_update::send_eof() sprintf(buff,ER(ER_UPDATE_INFO), (long) found, (long) updated, (long) thd->cuted_fields); - if (updated) - { - query_cache_invalidate3(thd, update_tables, 1); - } ::send_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, thd->insert_id_used ? thd->insert_id() : 0L,buff); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e3b2c738949..66a29a8cbd5 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -555,11 +555,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %left '^' %right NOT %right BINARY COLLATE_SYM -/* These don't actually affect the way the query is really evaluated, but - they silence a few warnings for shift/reduce conflicts. */ -%left ',' -%left STRAIGHT_JOIN JOIN_SYM -%nonassoc CROSS INNER_SYM NATURAL LEFT RIGHT %type <lex_str> IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME @@ -853,7 +848,7 @@ create: bzero((char*) &lex->create_info,sizeof(lex->create_info)); lex->create_info.options=$2 | $4; lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type; - lex->create_info.table_charset= thd->db_charset; + lex->create_info.table_charset= thd->variables.character_set_database; lex->name=0; } create2 @@ -1411,7 +1406,7 @@ opt_binary: | BINARY { Lex->charset=&my_charset_bin; } | UNICODE_SYM { - if (!(Lex->charset=get_charset_by_name("ucs2",MYF(0)))) + if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0)))) { net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2"); YYABORT; @@ -1541,7 +1536,7 @@ alter: lex->select_lex.db=lex->name=0; bzero((char*) &lex->create_info,sizeof(lex->create_info)); lex->create_info.db_type= DB_TYPE_DEFAULT; - lex->create_info.table_charset= thd->db_charset; + lex->create_info.table_charset= thd->variables.character_set_database; lex->create_info.row_type= ROW_TYPE_NOT_USED; lex->alter_keys_onoff=LEAVE_AS_IS; lex->simple_alter=1; @@ -1933,7 +1928,10 @@ select_option: Select->options|= OPTION_FOUND_ROWS; } | SQL_NO_CACHE_SYM { Lex->uncacheable(); } - | SQL_CACHE_SYM { Select->options|= OPTION_TO_QUERY_CACHE; } + | SQL_CACHE_SYM + { + Lex->select_lex.options|= OPTION_TO_QUERY_CACHE; + } | ALL {} ; @@ -2182,8 +2180,10 @@ simple_expr: simple_ident | simple_expr COLLATE_SYM ident_or_text %prec NEG { - $$= new Item_func_set_collation($1,new Item_string($3.str,$3.length, - YYTHD->charset())); + $$= new Item_func_set_collation($1, + new Item_string($3.str, + $3.length, + YYTHD->charset())); } | literal | param_marker @@ -2230,13 +2230,15 @@ simple_expr: | ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); } | BINARY expr %prec NEG { - $$= new Item_func_set_collation($2,new Item_string("BINARY",6, - &my_charset_latin1)); + $$= new Item_func_set_collation($2,new Item_string(binary_keyword, + 6, &my_charset_latin1)); } - | CAST_SYM '(' expr AS cast_type ')' { $$= create_func_cast($3, $5); } + | CAST_SYM '(' expr AS cast_type ')' + { $$= create_func_cast($3, $5, Lex->charset); } | CASE_SYM opt_expr WHEN_SYM when_list opt_else END { $$= new Item_func_case(* $4, $2, $5 ); } - | CONVERT_SYM '(' expr ',' cast_type ')' { $$= create_func_cast($3, $5); } + | CONVERT_SYM '(' expr ',' cast_type ')' + { $$= create_func_cast($3, $5, Lex->charset); } | CONVERT_SYM '(' expr USING charset_name ')' { $$= new Item_func_conv_charset($3,$5); } | CONVERT_SYM '(' expr ',' expr ',' expr ')' @@ -2581,8 +2583,12 @@ sum_expr: { $$=new Item_sum_count(new Item_int((int32) 0L,1)); } | COUNT_SYM '(' in_sum_expr ')' { $$=new Item_sum_count($3); } - | COUNT_SYM '(' DISTINCT expr_list ')' - { $$=new Item_sum_count_distinct(* $4); } + | COUNT_SYM '(' DISTINCT + { Select->select_lex()->in_sum_expr++; } + expr_list + { Select->select_lex()->in_sum_expr--; } + ')' + { $$=new Item_sum_count_distinct(* $5); } | GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')' { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); } | MIN_SYM '(' in_sum_expr ')' @@ -2641,15 +2647,15 @@ in_sum_expr: }; cast_type: - BINARY { $$=ITEM_CAST_BINARY; } - | CHAR_SYM { $$=ITEM_CAST_CHAR; } - | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; } - | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; } - | UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; } - | UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; } - | DATE_SYM { $$=ITEM_CAST_DATE; } - | TIME_SYM { $$=ITEM_CAST_TIME; } - | DATETIME { $$=ITEM_CAST_DATETIME; } + BINARY { $$=ITEM_CAST_BINARY; Lex->charset= NULL; } + | CHAR_SYM opt_binary { $$=ITEM_CAST_CHAR; } + | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; } + | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; } + | UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; } + | UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; } + | DATE_SYM { $$=ITEM_CAST_DATE; Lex->charset= NULL; } + | TIME_SYM { $$=ITEM_CAST_TIME; Lex->charset= NULL; } + | DATETIME { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; } ; expr_list: @@ -2711,7 +2717,7 @@ join_table_list: | join_table_list ',' join_table_list { $$=$3; } | join_table_list normal_join join_table_list { $$=$3; } | join_table_list STRAIGHT_JOIN join_table_list - { $$=$3 ; $$->straight=1; } + { $$=$3 ; $1->next->straight=1; } | join_table_list normal_join join_table_list ON expr { add_join_on($3,$5); $$=$3; } | join_table_list normal_join join_table_list @@ -2735,9 +2741,13 @@ join_table_list: USING '(' using_list ')' { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; } | join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list - { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; } + { + add_join_natural($1,$1->next); + $1->next->outer_join|=JOIN_TYPE_LEFT; + $$=$6; + } | join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr - { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; } + { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; } | join_table_list RIGHT opt_outer JOIN_SYM join_table_list { SELECT_LEX *sel= Select->select_lex(); @@ -2745,11 +2755,15 @@ join_table_list: sel->db2=$5->db; sel->table2=$5->alias; } USING '(' using_list ')' - { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; } + { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; } | join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list - { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; } + { + add_join_natural($1->next,$1); + $1->outer_join|=JOIN_TYPE_RIGHT; + $$=$6; + } | join_table_list NATURAL JOIN_SYM join_table_list - { add_join_natural($1,$4); $$=$4; }; + { add_join_natural($1,$1->next); $$=$4; }; normal_join: JOIN_SYM {} @@ -2849,15 +2863,15 @@ key_usage_list2: key_usage_list2 ',' ident { Select->select_lex()-> interval_list.push_back(new String((const char*) $3.str, $3.length, - default_charset_info)); } + system_charset_info)); } | ident { Select->select_lex()-> interval_list.push_back(new String((const char*) $1.str, $1.length, - default_charset_info)); } + system_charset_info)); } | PRIMARY_SYM { Select->select_lex()-> interval_list.push_back(new String("PRIMARY", 7, - default_charset_info)); }; + system_charset_info)); }; using_list: ident @@ -3076,7 +3090,7 @@ delete_limit_clause: ULONG_NUM: NUM { $$= strtoul($1.str,NULL,10); } - | LONG_NUM { $$= (ulonglong) strtoll($1.str,NULL,10); } + | LONG_NUM { $$= (ulong) strtoll($1.str,NULL,10); } | ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); } | REAL_NUM { $$= strtoul($1.str,NULL,10); } | FLOAT_NUM { $$= strtoul($1.str,NULL,10); }; @@ -3742,7 +3756,7 @@ opt_describe_column: /* empty */ {} | text_string { Lex->wild= $1; } | ident - { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); }; + { Lex->wild= new String((const char*) $1.str,$1.length,system_charset_info); }; /* flush things */ @@ -4420,24 +4434,18 @@ option_value: find_sys_var("tx_isolation"), new Item_int((int32) $4))); } - | charset old_or_new_charset_name_or_default opt_collate + | charset old_or_new_charset_name_or_default { THD *thd= YYTHD; LEX *lex= Lex; - $2= $2 ? $2: global_system_variables.collation_client; - $3= $3 ? $3 : $2; - if (!my_charset_same($2,$3)) - { - net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname); - YYABORT; - } - lex->var_list.push_back(new set_var_collation_client($3,thd->db_charset,$3)); + $2= $2 ? $2: global_system_variables.character_set_client; + lex->var_list.push_back(new set_var_collation_client($2,thd->variables.character_set_database,$2)); } | NAMES_SYM charset_name_or_default opt_collate { THD *thd= YYTHD; LEX *lex= Lex; - $2= $2 ? $2 : global_system_variables.collation_client; + $2= $2 ? $2 : global_system_variables.character_set_client; $3= $3 ? $3 : $2; if (!my_charset_same($2,$3)) { @@ -4821,7 +4829,7 @@ column_list: column_list_id: ident { - String *new_str = new String((const char*) $1.str,$1.length,default_charset_info); + String *new_str = new String((const char*) $1.str,$1.length,system_charset_info); List_iterator <LEX_COLUMN> iter(Lex->columns); class LEX_COLUMN *point; LEX *lex=Lex; diff --git a/sql/table.cc b/sql/table.cc index 3aed75c7ac6..908d6807450 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1161,6 +1161,33 @@ rename_file_ext(const char * from,const char * to,const char * ext) /* + Allocate string field in MEM_ROOT and return it as String + + SYNOPSIS + get_field() + mem MEM_ROOT for allocating + field Field for retrieving of string + res result String + + RETURN VALUES + true string is empty + false all ok +*/ + +bool get_field(MEM_ROOT *mem, Field *field, String *res) +{ + char buff[MAX_FIELD_WIDTH]; + String str(buff,sizeof(buff),&my_charset_bin); + field->val_str(&str,&str); + uint length=str.length(); + if (!length) + return true; + char *to= strmake_root(mem, str.ptr(), length); + res->set(to,length,((Field_str*)field)->charset()); + return false; +} + +/* Allocate string field in MEM_ROOT and return it as NULL-terminated string SYNOPSIS diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index 57560715fbe..fa678ec7de2 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -85,3 +85,33 @@ gptr sql_memdup(const void *ptr,uint len) void sql_element_free(void *ptr __attribute__((unused))) {} /* purecov: deadcode */ + + + +char *sql_strmake_with_convert(const char *str, uint32 arg_length, + CHARSET_INFO *from_cs, + uint32 max_res_length, + CHARSET_INFO *to_cs, uint32 *result_length) +{ + char *pos; + uint32 new_length= to_cs->mbmaxlen*arg_length; + max_res_length--; // Reserve place for end null + + set_if_smaller(new_length, max_res_length); + if (!(pos= sql_alloc(new_length+1))) + return pos; // Error + + if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin)) + { + // Safety if to_cs->mbmaxlen > 0 + new_length= min(arg_length, max_res_length); + memcpy(pos, str, new_length); + } + else + new_length= copy_and_convert((char*) pos, new_length, to_cs, str, + arg_length, from_cs); + pos[new_length]= 0; + *result_length= new_length; + return pos; +} + diff --git a/sql/time.cc b/sql/time.cc index 94f9cb2e5e8..eba664a690d 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -251,145 +251,6 @@ void get_date_from_daynr(long daynr,uint *ret_year,uint *ret_month, DBUG_VOID_RETURN; } -/* find date from string and put it in vektor - Input: pos = "YYMMDD" OR "YYYYMMDD" in any order or - "xxxxx YYxxxMMxxxDD xxxx" where xxx is anything exept - a number. Month or day mustn't exeed 2 digits, year may be 4 digits. -*/ - - -#ifdef NOT_NEEDED - -void find_date(string pos,uint *vek,uint flag) -{ - uint length,value; - string start; - DBUG_ENTER("find_date"); - DBUG_PRINT("enter",("pos: '%s' flag: %d",pos,flag)); - - bzero((char*) vek,sizeof(int)*4); - while (*pos && !my_isdigit(my_charset_latin1,*pos)) - pos++; - length=(uint) strlen(pos); - for (uint i=0 ; i< 3; i++) - { - start=pos; value=0; - while (my_isdigit(my_charset_latin1,pos[0]) && - ((pos-start) < 2 || ((pos-start) < 4 && length >= 8 && - !(flag & 3)))) - { - value=value*10 + (uint) (uchar) (*pos - '0'); - pos++; - } - vek[flag & 3]=value; flag>>=2; - while (*pos && (my_ispunct(my_charset_latin1,*pos) || - my_isspace(my_charset_latin1,*pos))) - pos++; - } - DBUG_PRINT("exit",("year: %d month: %d day: %d",vek[0],vek[1],vek[2])); - DBUG_VOID_RETURN; -} /* find_date */ - - - /* Outputs YYMMDD if input year < 100 or YYYYMMDD else */ - -static long calc_daynr_from_week(uint year,uint week,uint day) -{ - long daynr; - int weekday; - - daynr=calc_daynr(year,1,1); - if ((weekday= calc_weekday(daynr,0)) >= 3) - daynr+= (7-weekday); - else - daynr-=weekday; - - return (daynr+week*7+day-8); -} - -void convert_week_to_date(string date,uint flag,uint *res_length) -{ - string format; - uint year,vek[4]; - - find_date(date,vek,(uint) (1*4+2*16)); /* YY-WW-DD */ - year=vek[0]; - - get_date_from_daynr(calc_daynr_from_week(vek[0],vek[1],vek[2]), - &vek[0],&vek[1],&vek[2]); - *res_length=8; - format="%04d%02d%02d"; - if (year < 100) - { - vek[0]= vek[0]%100; - *res_length=6; - format="%02d%02d%02d"; - } - sprintf(date,format,vek[flag & 3],vek[(flag >> 2) & 3], - vek[(flag >> 4) & 3]); - return; -} - - /* returns YYWWDD or YYYYWWDD according to input year */ - /* flag only reflects format of input date */ - -void convert_date_to_week(string date,uint flag,uint *res_length) -{ - uint vek[4],weekday,days,year,week,day; - long daynr,first_daynr; - char buff[256],*format; - - if (! date[0]) - { - get_date(buff,0,0L); /* Use current date */ - find_date(buff+2,vek,(uint) (1*4+2*16)); /* YY-MM-DD */ - } - else - find_date(date,vek,flag); - - year= vek[0]; - daynr= calc_daynr(year,vek[1],vek[2]); - first_daynr=calc_daynr(year,1,1); - - /* Caculate year and first daynr of year */ - if (vek[1] == 1 && (weekday=calc_weekday(first_daynr,0)) >= 3 && - vek[2] <= 7-weekday) - { - if (!year--) - year=99; - first_daynr=first_daynr-calc_days_in_year(year); - } - else if (vek[1] == 12 && - (weekday=calc_weekday(first_daynr+calc_days_in_year(year)),0) < 3 && - vek[2] > 31-weekday) - { - first_daynr=first_daynr+calc_days_in_year(year); - if (year++ == 99) - year=0; - } - - /* Calulate daynr of first day of week 1 */ - if ((weekday= calc_weekday(first_daynr,0)) >= 3) - first_daynr+= (7-weekday); - else - first_daynr-=weekday; - - days=(int) (daynr-first_daynr); - week=days/7+1 ; day=calc_weekday(daynr,0)+1; - - *res_length=8; - format="%04d%02d%02d"; - if (year < 100) - { - *res_length=6; - format="%02d%02d%02d"; - } - sprintf(date,format,year,week,day); - return; -} - -#endif - /* Functions to handle periods */ ulong convert_period_to_month(ulong period) @@ -516,14 +377,14 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) else date[6]=0; - if (year_length == 2) + if (year_length == 2 && i >=2 && (date[1] || date[2])) date[0]+= (date[0] < YY_PART_YEAR ? 2000 : 1900); number_of_fields=i; while (i < 6) date[i++]=0; if (number_of_fields < 3 || date[1] > 12 || date[2] > 31 || date[3] > 23 || date[4] > 59 || date[5] > 59 || - !fuzzy_date && (date[1] == 0 || date[2] == 0)) + (!fuzzy_date && (date[1] == 0 || date[2] == 0))) { /* Only give warning for a zero date if there is some garbage after */ if (!not_zero_date) // If zero date diff --git a/sql/udf_example.cc b/sql/udf_example.cc index dfe8177bfce..7f4417bf8fe 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -284,8 +284,8 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, for (n = ntrans + 1, n_end = ntrans + sizeof(ntrans)-2; word != w_end && n < n_end; word++ ) - if ( my_isalpha ( my_charset_latin1, *word )) - *n++ = my_toupper ( my_charset_latin1, *word ); + if ( my_isalpha ( &my_charset_latin1, *word )) + *n++ = my_toupper ( &my_charset_latin1, *word ); if ( n == ntrans + 1 ) /* return empty string if 0 bytes */ { diff --git a/sql/unireg.h b/sql/unireg.h index ff942f6748a..6ddd9856724 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -45,6 +45,7 @@ #define LIBLEN FN_REFLEN-FN_LEN /* Max l{ngd p} dev */ #define MAX_DBKEY_LENGTH (FN_LEN*2+6) /* extra 4 bytes for slave tmp * tables */ +#define MAX_ALIAS_NAME 256 #define MAX_FIELD_NAME 34 /* Max colum name length +2 */ #define MAX_SYS_VAR_LENGTH 32 #define MAX_KEY 32 /* Max used keys */ @@ -55,6 +56,7 @@ #else #define MAX_REFLENGTH 4 /* Max length for record ref */ #endif +#define MAX_HOSTNAME 61 /* len+1 in mysql.user */ #define MAX_FIELD_WIDTH 256 /* Max column width +1 */ #define MAX_TABLES (sizeof(table_map)*8-2) /* Max tables in join */ diff --git a/strings/Makefile.am b/strings/Makefile.am index 1db96f5fda5..4a57ed73d20 100644 --- a/strings/Makefile.am +++ b/strings/Makefile.am @@ -22,19 +22,19 @@ pkglib_LIBRARIES = libmystrings.a # Exact one of ASSEMBLER_X if ASSEMBLER_x86 ASRCS = strings-x86.s longlong2str-x86.s -CSRCS = bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c atof.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c +CSRCS = bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c atof.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c else if ASSEMBLER_sparc32 # These file MUST all be on the same line!! Otherwise automake # generats a very broken makefile ASRCS = bmove_upp-sparc.s strappend-sparc.s strend-sparc.s strinstr-sparc.s strmake-sparc.s strmov-sparc.s strnmov-sparc.s strstr-sparc.s -CSRCS = strcont.c strfill.c strcend.c is_prefix.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c atof.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c strxmov.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c +CSRCS = strcont.c strfill.c strcend.c is_prefix.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c atof.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c strxmov.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c else #no assembler ASRCS = # These file MUST all be on the same line!! Otherwise automake # generats a very broken makefile -CSRCS = strxmov.c bmove_upp.c strappend.c strcont.c strend.c strfill.c strcend.c is_prefix.c strstr.c strinstr.c strmake.c strnmov.c strmov.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c atof.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c +CSRCS = strxmov.c bmove_upp.c strappend.c strcont.c strend.c strfill.c strcend.c is_prefix.c strstr.c strinstr.c strmake.c strnmov.c strmov.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c atof.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c endif endif @@ -44,7 +44,7 @@ DISTCLEANFILES = ctype_autoconf.c # Default charset definitions EXTRA_DIST = ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-win1250ch.c \ ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-utf8.c \ - ctype-tis620.c ctype-ujis.c \ + ctype-ucs2.c ctype-tis620.c ctype-ujis.c \ xml.c strto.c strings-x86.s \ longlong2str.c longlong2str-x86.s \ strxmov.c bmove_upp.c strappend.c strcont.c strend.c \ diff --git a/strings/conf_to_src.c b/strings/conf_to_src.c index 69dccbca0a7..b21740f9dbb 100644 --- a/strings/conf_to_src.c +++ b/strings/conf_to_src.c @@ -55,7 +55,7 @@ print_array16(FILE *f, const char *set, const char *name, uint16 *a, int n) { int i; - fprintf(f,"uchar %s_%s[] = {\n", name, set); + fprintf(f,"uint16 %s_%s[] = {\n", name, set); for (i=0 ;i<n ; i++) { @@ -123,7 +123,8 @@ static my_bool simple_cs_is_full(CHARSET_INFO *cs) { return ((cs->csname && cs->tab_to_uni && cs->ctype && cs->to_upper && cs->to_lower) && - (cs->number && cs->name && cs->sort_order)); + (cs->number && cs->name && + (cs->sort_order || (cs->state & MY_CS_BINSORT)))); } static int add_collation(CHARSET_INFO *cs) @@ -177,18 +178,23 @@ static int my_read_charset_file(const char *filename) void dispcset(FILE *f,CHARSET_INFO *cs) { fprintf(f,"{\n"); - fprintf(f," %d,\n",cs->number); - fprintf(f," MY_CS_COMPILED,\n"); + fprintf(f," %d,%d,%d,\n",cs->number,0,0); + fprintf(f," MY_CS_COMPILED%s%s,\n", + cs->state & MY_CS_BINSORT ? "|MY_CS_BINSORT" : "", + cs->state & MY_CS_PRIMARY ? "|MY_CS_PRIMARY" : ""); if (cs->name) { - fprintf(f," \"%s\",\n",cs->name); fprintf(f," \"%s\",\n",cs->csname); + fprintf(f," \"%s\",\n",cs->name); fprintf(f," \"\",\n"); fprintf(f," ctype_%s,\n",cs->name); fprintf(f," to_lower_%s,\n",cs->name); fprintf(f," to_upper_%s,\n",cs->name); - fprintf(f," sort_order_%s,\n",cs->name); + if (cs->sort_order) + fprintf(f," sort_order_%s,\n",cs->name); + else + fprintf(f," NULL,\n"); fprintf(f," to_uni_%s,\n",cs->name); fprintf(f," from_uni_%s,\n",cs->name); } @@ -205,37 +211,16 @@ void dispcset(FILE *f,CHARSET_INFO *cs) fprintf(f," NULL,\n"); } - fprintf(f," %d,\n",cs->strxfrm_multiply); - fprintf(f," my_strnncoll_simple,\n"); - fprintf(f," my_strnxfrm_simple,\n"); - fprintf(f," my_like_range_simple,\n"); - fprintf(f," my_wild_cmp_8bit,\n"); - fprintf(f," %d,\n",cs->mbmaxlen); - fprintf(f," NULL,\n"); - fprintf(f," NULL,\n"); - fprintf(f," NULL,\n"); - fprintf(f," my_mb_wc_8bit,\n"); - fprintf(f," my_wc_mb_8bit,\n"); - fprintf(f," my_caseup_str_8bit,\n"); - fprintf(f," my_casedn_str_8bit,\n"); - fprintf(f," my_caseup_8bit,\n"); - fprintf(f," my_casedn_8bit,\n"); - fprintf(f," my_tosort_8bit,\n"); - fprintf(f," my_strcasecmp_8bit,\n"); - fprintf(f," my_strncasecmp_8bit,\n"); - fprintf(f," my_hash_caseup_simple,\n"); - fprintf(f," my_hash_sort_simple,\n"); + fprintf(f," \"\",\n"); + fprintf(f," \"\",\n"); fprintf(f," 0,\n"); - fprintf(f," my_snprintf_8bit,\n"); - fprintf(f," my_long10_to_str_8bit,\n"); - fprintf(f," my_longlong10_to_str_8bit,\n"); - fprintf(f," my_fill_8bit,\n"); - fprintf(f," my_strntol_8bit,\n"); - fprintf(f," my_strntoul_8bit,\n"); - fprintf(f," my_strntoll_8bit,\n"); - fprintf(f," my_strntoull_8bit,\n"); - fprintf(f," my_strntod_8bit,\n"); - fprintf(f," my_scan_8bit\n"); + fprintf(f," 0,\n"); + fprintf(f," 0,\n"); + fprintf(f," &my_charset_8bit_handler,\n"); + if (cs->state & MY_CS_BINSORT) + fprintf(f," &my_collation_bin_handler,\n"); + else + fprintf(f," &my_collation_8bit_simple_ci_handler,\n"); fprintf(f,"}\n"); } @@ -262,9 +247,9 @@ main(int argc, char **argv __attribute__((unused))) for (cs=all_charsets; cs < all_charsets+256; cs++) { - if (cs->number) + if (cs->number && !(cs->state & MY_CS_COMPILED)) { - if ( (!simple_cs_is_full(cs)) && (cs->csname) ) + if ( (!simple_cs_is_full(cs)) && (cs->csname)) { sprintf(filename,"%s/%s.xml",argv[1],cs->csname); my_read_charset_file(filename); @@ -280,7 +265,8 @@ main(int argc, char **argv __attribute__((unused))) print_array(f, cs->name, "ctype", cs->ctype, MY_CS_CTYPE_TABLE_SIZE); print_array(f, cs->name, "to_lower", cs->to_lower, MY_CS_TO_LOWER_TABLE_SIZE); print_array(f, cs->name, "to_upper", cs->to_upper, MY_CS_TO_UPPER_TABLE_SIZE); - print_array(f, cs->name, "sort_order", cs->sort_order, MY_CS_SORT_ORDER_TABLE_SIZE); + if (cs->sort_order) + print_array(f, cs->name, "sort_order", cs->sort_order, MY_CS_SORT_ORDER_TABLE_SIZE); print_array16(f, cs->name, "to_uni", cs->tab_to_uni, MY_CS_TO_UNI_TABLE_SIZE); fprintf(f,"#endif\n"); fprintf(f,"\n"); diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c index 57ee2d7c6ae..10b6898ce24 100644 --- a/strings/ctype-big5.c +++ b/strings/ctype-big5.c @@ -6226,7 +6226,43 @@ my_mb_wc_big5(CHARSET_INFO *cs __attribute__((unused)), return 2; } -CHARSET_INFO my_charset_big5 = +static MY_COLLATION_HANDLER my_collation_big5_chinese_ci_handler = +{ + my_strnncoll_big5, + my_strnncollsp_big5, + my_strnxfrm_big5, + my_like_range_big5, + my_wildcmp_mb, + my_strcasecmp_mb, + my_hash_sort_simple +}; + +static MY_CHARSET_HANDLER my_charset_big5_handler= +{ + ismbchar_big5, + mbcharlen_big5, + my_numchars_mb, + my_charpos_mb, + my_mb_wc_big5, /* mb_wc */ + my_wc_mb_big5, /* wc_mb */ + my_caseup_str_mb, + my_casedn_str_mb, + my_caseup_mb, + my_casedn_mb, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + +CHARSET_INFO my_charset_big5_chinese_ci= { 1,0,0, /* number */ MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ @@ -6239,38 +6275,36 @@ CHARSET_INFO my_charset_big5 = sort_order_big5, NULL, /* tab_to_uni */ NULL, /* tab_from_uni */ - "","", + "", + "", 1, /* strxfrm_multiply */ - my_strnncoll_big5, - my_strnncollsp_big5, - my_strnxfrm_big5, - my_like_range_big5, - my_wildcmp_mb, 2, /* mbmaxlen */ - ismbchar_big5, - mbcharlen_big5, - my_numchars_mb, - my_charpos_mb, - my_mb_wc_big5, /* mb_wc */ - my_wc_mb_big5, /* wc_mb */ - my_caseup_str_mb, - my_casedn_str_mb, - my_caseup_mb, - my_casedn_mb, - my_strcasecmp_mb, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_big5_handler, + &my_collation_big5_chinese_ci_handler +}; + + +CHARSET_INFO my_charset_big5_bin= +{ + 84,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "big5", /* cs name */ + "big5_bin", /* name */ + "", /* comment */ + ctype_big5, + to_lower_big5, + to_upper_big5, + sort_order_big5, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_big5_handler, + &my_collation_bin_handler }; diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index 77152db845c..ebe73016db7 100644 --- a/strings/ctype-bin.c +++ b/strings/ctype-bin.c @@ -262,6 +262,42 @@ static int my_strnxfrm_bin(CHARSET_INFO *cs __attribute__((unused)), return len; } + +MY_COLLATION_HANDLER my_collation_bin_handler = +{ + my_strnncoll_binary, + my_strnncollsp_binary, + my_strnxfrm_bin, + my_like_range_simple, + my_wildcmp_bin, + my_strcasecmp_bin, + my_hash_sort_bin +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + NULL, /* ismbchar */ + NULL, /* mbcharlen */ + my_numchars_8bit, + my_charpos_8bit, + my_mb_wc_bin, + my_wc_mb_bin, + my_caseup_str_bin, + my_casedn_str_bin, + my_caseup_bin, + my_casedn_bin, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + CHARSET_INFO my_charset_bin = { 63,0,0, /* number */ @@ -277,33 +313,8 @@ CHARSET_INFO my_charset_bin = NULL, /* tab_from_uni */ "","", 0, /* strxfrm_multiply */ - my_strnncoll_binary, /* strnncoll */ - my_strnncollsp_binary, - my_strnxfrm_bin, /* strxnfrm */ - my_like_range_simple, /* like_range */ - my_wildcmp_bin, /* wildcmp */ 1, /* mbmaxlen */ - NULL, /* ismbchar */ - NULL, /* mbcharlen */ - my_numchars_8bit, - my_charpos_8bit, - my_mb_wc_bin, /* mb_wc */ - my_wc_mb_bin, /* wc_mb */ - my_caseup_str_bin, /* caseup_str */ - my_casedn_str_bin, /* casedn_str */ - my_caseup_bin, /* caseup */ - my_casedn_bin, /* casedn */ - my_strcasecmp_bin, /* strcasecmp */ - my_hash_sort_bin, /* hash_sort */ (char) 255, /* max_sort_char */ - my_snprintf_8bit, /* snprintf */ - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_handler, + &my_collation_bin_handler }; diff --git a/strings/ctype-czech.c b/strings/ctype-czech.c index 9da2103fda3..2398bc33d45 100644 --- a/strings/ctype-czech.c +++ b/strings/ctype-czech.c @@ -77,7 +77,7 @@ #endif -#ifdef HAVE_CHARSET_czech +#ifdef HAVE_CHARSET_latin2 /* These are four tables for four passes of the algorithm. Please see @@ -604,8 +604,18 @@ int my_strnncollsp_czech(CHARSET_INFO * cs, return my_strnncoll_czech(cs,s,slen,t,tlen); } +static MY_COLLATION_HANDLER my_collation_latin2_czech_ci_handler = +{ + my_strnncoll_czech, + my_strnncollsp_czech, + my_strnxfrm_czech, + my_like_range_czech, + my_wildcmp_8bit, + my_strcasecmp_8bit, + my_hash_sort_simple, +}; -CHARSET_INFO my_charset_czech = +CHARSET_INFO my_charset_latin2_czech_ci = { 2,0,0, /* number */ MY_CS_COMPILED|MY_CS_STRNXFRM, /* state */ @@ -620,37 +630,13 @@ CHARSET_INFO my_charset_czech = idx_uni_8859_2, /* tab_from_uni */ "","", 4, /* strxfrm_multiply */ - my_strnncoll_czech, - my_strnncollsp_czech, - my_strnxfrm_czech, - my_like_range_czech, - my_wildcmp_8bit, 1, /* mbmaxlen */ - NULL, /* ismbchar */ - NULL, /* mbcharlen */ - my_numchars_8bit, - my_charpos_8bit, - my_mb_wc_8bit, /* mb_wc */ - my_wc_mb_8bit, /* wc_mb */ - my_caseup_str_8bit, - my_casedn_str_8bit, - my_caseup_8bit, - my_casedn_8bit, - my_strcasecmp_8bit, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_8bit_handler, + &my_collation_latin2_czech_ci_handler }; + #endif #endif diff --git a/strings/ctype-euc_kr.c b/strings/ctype-euc_kr.c index 21f01b6509c..8e288ee8e55 100644 --- a/strings/ctype-euc_kr.c +++ b/strings/ctype-euc_kr.c @@ -30,7 +30,7 @@ #include "m_string.h" #include "m_ctype.h" -#ifdef HAVE_CHARSET_euc_kr +#ifdef HAVE_CHARSET_euckr static uchar NEAR ctype_euc_kr[257] = @@ -8634,7 +8634,44 @@ my_mb_wc_euc_kr(CHARSET_INFO *cs __attribute__((unused)), return 2; } -CHARSET_INFO my_charset_euc_kr = + +static MY_COLLATION_HANDLER my_collation_ci_handler = +{ + my_strnncoll_simple,/* strnncoll */ + my_strnncollsp_simple, + my_strnxfrm_simple, /* strnxfrm */ + my_like_range_simple,/* like_range */ + my_wildcmp_mb, /* wildcmp */ + my_strcasecmp_mb, + my_hash_sort_simple, +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + ismbchar_euc_kr, + mbcharlen_euc_kr, + my_numchars_mb, + my_charpos_mb, + my_mb_wc_euc_kr, /* mb_wc */ + my_wc_mb_euc_kr, /* wc_mb */ + my_caseup_str_mb, + my_casedn_str_mb, + my_caseup_mb, + my_casedn_mb, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + + +CHARSET_INFO my_charset_euckr_korean_ci= { 19,0,0, /* number */ MY_CS_COMPILED|MY_CS_PRIMARY, /* state */ @@ -8647,37 +8684,36 @@ CHARSET_INFO my_charset_euc_kr = sort_order_euc_kr, NULL, /* tab_to_uni */ NULL, /* tab_from_uni */ - "","", + "", + "", + 0, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + + +CHARSET_INFO my_charset_euckr_bin= +{ + 85,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "euckr", /* cs name */ + "euckr_bin", /* name */ + "", /* comment */ + ctype_euc_kr, + to_lower_euc_kr, + to_upper_euc_kr, + sort_order_euc_kr, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", 0, /* strxfrm_multiply */ - my_strnncoll_simple,/* strnncoll */ - my_strnncollsp_simple, - my_strnxfrm_simple, /* strnxfrm */ - my_like_range_simple,/* like_range */ - my_wildcmp_mb, /* wildcmp */ 2, /* mbmaxlen */ - ismbchar_euc_kr, - mbcharlen_euc_kr, - my_numchars_mb, - my_charpos_mb, - my_mb_wc_euc_kr, /* mb_wc */ - my_wc_mb_euc_kr, /* wc_mb */ - my_caseup_str_mb, - my_casedn_str_mb, - my_caseup_mb, - my_casedn_mb, - my_strcasecmp_mb, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_handler, + &my_collation_bin_handler }; #endif diff --git a/strings/ctype-extra.c b/strings/ctype-extra.c index 40d2b7ab1da..55bfa09ea5f 100644 --- a/strings/ctype-extra.c +++ b/strings/ctype-extra.c @@ -32,35 +32,9 @@ CHARSET_INFO compiled_charsets[] = { NULL, /* tab_from_uni */ "","", 0, - NULL, /* strnncoll */ - NULL, /* strnncollsp */ - NULL, /* strnxfrm */ - NULL, /* like_range */ - NULL, /* wildcmp */ 0, - NULL, - NULL, - NULL, - NULL, - NULL, /* mb_wc */ - NULL, /* wc_mb */ - - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, /* hash_sort */ 0, NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, NULL } }; diff --git a/strings/ctype-gb2312.c b/strings/ctype-gb2312.c index f1ec5a9f363..378931eecc7 100644 --- a/strings/ctype-gb2312.c +++ b/strings/ctype-gb2312.c @@ -5684,7 +5684,44 @@ my_mb_wc_gb2312(CHARSET_INFO *cs __attribute__((unused)), return 2; } -CHARSET_INFO my_charset_gb2312 = + +static MY_COLLATION_HANDLER my_collation_ci_handler = +{ + my_strnncoll_simple,/* strnncoll */ + my_strnncollsp_simple, + my_strnxfrm_simple, /* strnxfrm */ + my_like_range_simple,/* like_range */ + my_wildcmp_mb, /* wildcmp */ + my_strcasecmp_mb, + my_hash_sort_simple, +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + ismbchar_gb2312, + mbcharlen_gb2312, + my_numchars_mb, + my_charpos_mb, + my_mb_wc_gb2312, /* mb_wc */ + my_wc_mb_gb2312, /* wc_mb */ + my_caseup_str_mb, + my_casedn_str_mb, + my_caseup_mb, + my_casedn_mb, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + + +CHARSET_INFO my_charset_gb2312_chinese_ci= { 24,0,0, /* number */ MY_CS_COMPILED|MY_CS_PRIMARY, /* state */ @@ -5697,37 +5734,35 @@ CHARSET_INFO my_charset_gb2312 = sort_order_gb2312, NULL, /* tab_to_uni */ NULL, /* tab_from_uni */ - "","", + "", + "", + 0, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + +CHARSET_INFO my_charset_gb2312_bin= +{ + 86,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "gb2312", /* cs name */ + "gb2312_bin", /* name */ + "", /* comment */ + ctype_gb2312, + to_lower_gb2312, + to_upper_gb2312, + sort_order_gb2312, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", 0, /* strxfrm_multiply */ - my_strnncoll_simple,/* strnncoll */ - my_strnncollsp_simple, - my_strnxfrm_simple, /* strnxfrm */ - my_like_range_simple,/* like_range */ - my_wildcmp_mb, /* wildcmp */ 2, /* mbmaxlen */ - ismbchar_gb2312, - mbcharlen_gb2312, - my_numchars_mb, - my_charpos_mb, - my_mb_wc_gb2312, /* mb_wc */ - my_wc_mb_gb2312, /* wc_mb */ - my_caseup_str_mb, - my_casedn_str_mb, - my_caseup_mb, - my_casedn_mb, - my_strcasecmp_mb, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_handler, + &my_collation_bin_handler }; #endif diff --git a/strings/ctype-gbk.c b/strings/ctype-gbk.c index b1ea209d6ad..58d281ae485 100644 --- a/strings/ctype-gbk.c +++ b/strings/ctype-gbk.c @@ -9881,7 +9881,44 @@ my_mb_wc_gbk(CHARSET_INFO *cs __attribute__((unused)), } -CHARSET_INFO my_charset_gbk = + +static MY_COLLATION_HANDLER my_collation_ci_handler = +{ + my_strnncoll_gbk, + my_strnncollsp_gbk, + my_strnxfrm_gbk, + my_like_range_gbk, + my_wildcmp_mb, + my_strcasecmp_mb, + my_hash_sort_simple, +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + ismbchar_gbk, + mbcharlen_gbk, + my_numchars_mb, + my_charpos_mb, + my_mb_wc_gbk, + my_wc_mb_gbk, + my_caseup_str_mb, + my_casedn_str_mb, + my_caseup_mb, + my_casedn_mb, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + + +CHARSET_INFO my_charset_gbk_chinese_ci= { 28,0,0, /* number */ MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ @@ -9894,37 +9931,35 @@ CHARSET_INFO my_charset_gbk = sort_order_gbk, NULL, /* tab_to_uni */ NULL, /* tab_from_uni */ - "","", + "", + "", 1, /* strxfrm_multiply */ - my_strnncoll_gbk, - my_strnncollsp_gbk, - my_strnxfrm_gbk, - my_like_range_gbk, - my_wildcmp_mb, /* wildcmp */ 2, /* mbmaxlen */ - ismbchar_gbk, - mbcharlen_gbk, - my_numchars_mb, - my_charpos_mb, - my_mb_wc_gbk, /* mb_wc */ - my_wc_mb_gbk, /* wc_mb */ - my_caseup_str_mb, - my_casedn_str_mb, - my_caseup_mb, - my_casedn_mb, - my_strcasecmp_mb, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_handler, + &my_collation_ci_handler +}; + +CHARSET_INFO my_charset_gbk_bin= +{ + 87,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "gbk", /* cs name */ + "gbk_bin", /* name */ + "", /* comment */ + ctype_gbk, + to_lower_gbk, + to_upper_gbk, + sort_order_gbk, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_bin_handler }; diff --git a/strings/ctype-latin1.c b/strings/ctype-latin1.c index 5781013a5e9..b0c60e2e3eb 100644 --- a/strings/ctype-latin1.c +++ b/strings/ctype-latin1.c @@ -174,41 +174,18 @@ int my_wc_mb_latin1(CHARSET_INFO *cs __attribute__((unused)), return ((wc < 256) && ((str[0]=uni_latin1[wc]) || (!wc))) ? 1 : MY_CS_ILUNI; } - -CHARSET_INFO my_charset_latin1 = +static MY_CHARSET_HANDLER my_charset_handler= { - 8,0,0, /* number */ - MY_CS_COMPILED | MY_CS_PRIMARY, /* state */ - "latin1", /* cs name */ - "latin1_swedish_ci", /* name */ - "", /* comment */ - ctype_latin1, - to_lower_latin1, - to_upper_latin1, - sort_order_latin1, - latin1_uni, /* tab_to_uni */ - NULL, /* tab_from_uni */ - "","", - 0, /* strxfrm_multiply */ - my_strnncoll_simple, - my_strnncollsp_simple, - my_strnxfrm_simple, - my_like_range_simple, - my_wildcmp_8bit, /* wildcmp */ - 1, /* mbmaxlen */ - NULL, /* ismbchar */ - NULL, /* mbcharlen */ + NULL, + NULL, my_numchars_8bit, my_charpos_8bit, - my_mb_wc_latin1, /* mb_wc */ - my_wc_mb_latin1, /* wc_mb */ + my_mb_wc_latin1, + my_wc_mb_latin1, my_caseup_str_8bit, my_casedn_str_8bit, my_caseup_8bit, my_casedn_8bit, - my_strcasecmp_8bit, - my_hash_sort_simple, - 0, my_snprintf_8bit, my_long10_to_str_8bit, my_longlong10_to_str_8bit, @@ -222,6 +199,28 @@ CHARSET_INFO my_charset_latin1 = }; +CHARSET_INFO my_charset_latin1= +{ + 8,0,0, /* number */ + MY_CS_COMPILED | MY_CS_PRIMARY, /* state */ + "latin1", /* cs name */ + "latin1_swedish_ci", /* name */ + "", /* comment */ + ctype_latin1, + to_lower_latin1, + to_upper_latin1, + sort_order_latin1, + latin1_uni, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "","", + 0, /* strxfrm_multiply */ + 1, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_8bit_simple_ci_handler +}; + + /* @@ -428,7 +427,20 @@ static int my_strnxfrm_latin1_de(CHARSET_INFO *cs __attribute__((unused)), return dest - dest_orig; } -CHARSET_INFO my_charset_latin1_de = + +static MY_COLLATION_HANDLER my_collation_german2_ci_handler= +{ + my_strnncoll_latin1_de, + my_strnncollsp_latin1_de, + my_strnxfrm_latin1_de, + my_like_range_simple, + my_wildcmp_8bit, + my_strcasecmp_8bit, + my_hash_sort_simple +}; + + +CHARSET_INFO my_charset_latin1_german2_ci= { 31,0,0, /* number */ MY_CS_COMPILED|MY_CS_STRNXFRM, /* state */ @@ -443,34 +455,32 @@ CHARSET_INFO my_charset_latin1_de = NULL, /* tab_from_uni */ "","", 2, /* strxfrm_multiply */ - my_strnncoll_latin1_de, - my_strnncollsp_latin1_de, - my_strnxfrm_latin1_de, - my_like_range_simple, - my_wildcmp_8bit, /* wildcmp */ 1, /* mbmaxlen */ - NULL, /* ismbchar */ - NULL, /* mbcharlen */ - my_numchars_8bit, - my_charpos_8bit, - my_mb_wc_latin1, /* mb_wc */ - my_wc_mb_latin1, /* wc_mb */ - my_caseup_str_8bit, - my_casedn_str_8bit, - my_caseup_8bit, - my_casedn_8bit, - my_strcasecmp_8bit, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_handler, + &my_collation_german2_ci_handler +}; + + +CHARSET_INFO my_charset_latin1_bin= +{ + 47,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "latin1", /* cs name */ + "latin1_bin", /* name */ + "", /* comment */ + ctype_latin1, + to_lower_latin1, + to_upper_latin1, + sort_order_latin1_de, + latin1_uni, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 1, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_bin_handler }; diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index 7d8f5b9535b..8f3e66f782e 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -1019,3 +1019,38 @@ uint my_charpos_8bit(CHARSET_INFO *cs __attribute__((unused)), { return pos; } + +MY_CHARSET_HANDLER my_charset_8bit_handler= +{ + NULL, /* ismbchar */ + NULL, /* mbcharlen */ + my_numchars_8bit, + my_charpos_8bit, + my_mb_wc_8bit, + my_wc_mb_8bit, + my_caseup_str_8bit, + my_casedn_str_8bit, + my_caseup_8bit, + my_casedn_8bit, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + +MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler = +{ + my_strnncoll_simple, + my_strnncollsp_simple, + my_strnxfrm_simple, + my_like_range_simple, + my_wildcmp_8bit, + my_strcasecmp_8bit, + my_hash_sort_simple +}; diff --git a/strings/ctype-sjis.c b/strings/ctype-sjis.c index fd911f1867e..00d51dd23b5 100644 --- a/strings/ctype-sjis.c +++ b/strings/ctype-sjis.c @@ -4468,7 +4468,44 @@ my_mb_wc_sjis(CHARSET_INFO *cs __attribute__((unused)), return 2; } -CHARSET_INFO my_charset_sjis = + +static MY_COLLATION_HANDLER my_collation_ci_handler = +{ + my_strnncoll_sjis, + my_strnncollsp_sjis, + my_strnxfrm_sjis, + my_like_range_sjis, + my_wildcmp_mb, /* wildcmp */ + my_strcasecmp_8bit, + my_hash_sort_simple, +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + ismbchar_sjis, + mbcharlen_sjis, + my_numchars_mb, + my_charpos_mb, + my_mb_wc_sjis, /* mb_wc */ + my_wc_mb_sjis, /* wc_mb */ + my_caseup_str_8bit, + my_casedn_str_8bit, + my_caseup_8bit, + my_casedn_8bit, + my_snprintf_8bit, + my_long10_to_str_8bit, + my_longlong10_to_str_8bit, + my_fill_8bit, + my_strntol_8bit, + my_strntoul_8bit, + my_strntoll_8bit, + my_strntoull_8bit, + my_strntod_8bit, + my_scan_8bit +}; + + +CHARSET_INFO my_charset_sjis_japanese_ci= { 13,0,0, /* number */ MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ @@ -4481,37 +4518,35 @@ CHARSET_INFO my_charset_sjis = sort_order_sjis, NULL, /* tab_to_uni */ NULL, /* tab_from_uni */ - "","", + "", + "", 1, /* strxfrm_multiply */ - my_strnncoll_sjis, - my_strnncollsp_sjis, - my_strnxfrm_sjis, - my_like_range_sjis, - my_wildcmp_mb, /* wildcmp */ 2, /* mbmaxlen */ - ismbchar_sjis, - mbcharlen_sjis, - my_numchars_mb, - my_charpos_mb, - my_mb_wc_sjis, /* mb_wc */ - my_wc_mb_sjis, /* wc_mb */ - my_caseup_str_8bit, - my_casedn_str_8bit, - my_caseup_8bit, - my_casedn_8bit, - my_strcasecmp_8bit, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_handler, + &my_collation_ci_handler +}; + +CHARSET_INFO my_charset_sjis_bin= +{ + 88,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "sjis", /* cs name */ + "sjis_bin", /* name */ + "", /* comment */ + ctype_sjis, + to_lower_sjis, + to_upper_sjis, + sort_order_sjis, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_bin_handler }; #endif diff --git a/strings/ctype-tis620.c b/strings/ctype-tis620.c index 21722f317a1..ab51ddd013f 100644 --- a/strings/ctype-tis620.c +++ b/strings/ctype-tis620.c @@ -455,82 +455,78 @@ uchar NEAR sort_order_tis620[]= Arg: const source string and length of converted string Ret: Sortable string */ - +/* + NOTE: isn't it faster to alloc buffer in calling function? + */ static uchar* thai2sortable(const uchar * tstr,uint len) { /* We use only 3 levels (neglect capitalization). */ - const uchar* p = tstr; + const uchar* p= tstr; uchar *outBuf; -/* uchar *pRight1, *pRight2, *pRight3, *pRight4; */ -/* uchar *pLeft1, *pLeft2, *pLeft3, *pLeft4; */ uchar *pRight1, *pRight2, *pRight3; uchar *pLeft1, *pLeft2, *pLeft3; uint bufSize; - - len = (uint) strnlen((char*) tstr,len); - bufSize = (uint) buffsize((char*) tstr); - if(!(pRight1 = (uchar *)malloc(sizeof(uchar) * bufSize))) { - return( (uchar*) tstr); - } - pLeft1 = pRight1; - outBuf = pRight1; - if(!(pRight2 = (uchar *)malloc(sizeof(uchar) * (len + 1)))) { - free(pRight1); - return((uchar*) tstr); - } - pLeft2 = pRight2; - if(!(pRight3 = (uchar *)malloc(sizeof(uchar) * (len + 1)))) { - free(pRight1); - free(pRight2); - return((uchar*) tstr); - } - pLeft3 = pRight3; -/* if(!(pRight4 = (uchar *)malloc(sizeof(uchar) * (len + 1)))) { - free(pRight1); - free(pRight2); - free(pRight3); - return((uchar*) tstr); - } - pLeft4 = pRight4;*/ - while(len--) { - if(isldvowel(*p) && isconsnt(p[1])) { - *pRight1++ = t_ctype[p[1]][0]; - *pRight2++ = t_ctype[p[1]][1]; - *pRight3++ = t_ctype[p[1]][2]; -/* *pRight4++ = t_ctype[p[1]][3]; */ - *pRight1++ = t_ctype[*p][0]; - *pRight2++ = t_ctype[*p][1]; - *pRight3++ = t_ctype[*p][2]; -/* *pRight4++ = t_ctype[*p][3]; */ + uint RightSize; + + len= (uint) strnlen((char*) tstr,len); + bufSize= (uint) buffsize((char*) tstr); + RightSize= sizeof(uchar) * (len + 1); + if (!(outBuf= pLeft1= pRight1= + (uchar *)malloc(sizeof(uchar) * bufSize + RightSize*2))) + return (uchar*) tstr; + pLeft2= pRight2= pRight1 + sizeof(uchar) * bufSize; + pLeft3= pRight3= pRight2 + RightSize; + + while (--len) + { + int *t_ctype0= t_ctype[p[0]]; + if (isldvowel(*p) && isconsnt(p[1])) + { + int *t_ctype1= t_ctype[p[1]]; + *pRight1++= t_ctype1[0]; + *pRight2++= t_ctype1[1]; + *pRight3++= t_ctype1[2]; + *pRight1++= t_ctype0[0]; + *pRight2++= t_ctype0[1]; + *pRight3++= t_ctype0[2]; + p+= 2; len--; - p += 2; - } else { - *pRight1 = t_ctype[*p][0]; - if(*pRight1 != IGNORE) pRight1++; - *pRight2 = t_ctype[*p][1]; - if(*pRight2 != IGNORE) pRight2++; - *pRight3 = t_ctype[*p][2]; - if(*pRight3 != IGNORE) pRight3++; -/* *pRight4 = t_ctype[*p][3]; - if(*pRight4 != IGNORE) pRight4++;*/ + } + else + { + *pRight1= t_ctype0[0]; + if(*pRight1 != IGNORE) + pRight1++; + *pRight2= t_ctype0[1]; + if (*pRight2 != IGNORE) + pRight2++; + *pRight3= t_ctype0[2]; + if(*pRight3 != IGNORE) + pRight3++; p++; } } - *pRight1++ = L2_BLANK; - *pRight2++ = L3_BLANK; -/* *pRight3++ = L4_BLANK; */ - *pRight3++ = '\0'; -/* *pRight4++ = '\0'; */ + if (!len) + { + int *t_ctype0= t_ctype[p[0]]; + *pRight1= t_ctype0[0]; + if (*pRight1 != IGNORE) + pRight1++; + *pRight2= t_ctype0[1]; + if (*pRight2 != IGNORE) + pRight2++; + *pRight3= t_ctype0[2]; + if (*pRight3 != IGNORE) + pRight3++; + } + *pRight1++= L2_BLANK; + *pRight2++= L3_BLANK; + *pRight3++= '\0'; memcpy(pRight1, pLeft2, pRight2 - pLeft2); - pRight1 += pRight2 - pLeft2; + pRight1+= pRight2 - pLeft2; memcpy(pRight1, pLeft3, pRight3 - pLeft3); -/* pRight1 += pRight3 - pLeft3; */ -/* memcpy(pRight1, pLeft4, pRight4 - pLeft4); */ - free(pLeft2); - free(pLeft3); -/* free(pLeft4); */ - return(outBuf); + return outBuf; } /* strncoll() replacement, compare 2 string, both are conveted to sortable string @@ -543,12 +539,12 @@ int my_strnncoll_tis620(CHARSET_INFO *cs __attribute__((unused)), { uchar *tc1, *tc2; int i; - tc1 = thai2sortable(s1, len1); - tc2 = thai2sortable(s2, len2); - i = strcmp((char*)tc1, (char*)tc2); + tc1= thai2sortable(s1, len1); + tc2= thai2sortable(s2, len2); + i= strcmp((char*)tc1, (char*)tc2); free(tc1); free(tc2); - return(i); + return i; } static @@ -572,12 +568,12 @@ int my_strnxfrm_tis620(CHARSET_INFO *cs __attribute__((unused)), { uint bufSize; uchar *tmp; - bufSize = (uint) buffsize((char*)src); - tmp = thai2sortable(src,srclen); + bufSize= (uint) buffsize((char*)src); + tmp= thai2sortable(src,srclen); set_if_smaller(bufSize,(uint) len); memcpy((uchar *)dest, tmp, bufSize); free(tmp); - return (int) bufSize; + return (int)bufSize; } /* strcoll replacment, compare 2 strings @@ -588,12 +584,12 @@ int my_strcoll_tis620(const uchar * s1, const uchar * s2) { uchar *tc1, *tc2; int i; - tc1 = thai2sortable(s1, (uint) strlen((char*)s1)); - tc2 = thai2sortable(s2, (uint) strlen((char*)s2)); - i = strcmp((char*)tc1, (char*)tc2); + tc1= thai2sortable(s1, (uint) strlen((char*)s1)); + tc2= thai2sortable(s2, (uint) strlen((char*)s2)); + i= strcmp((char*)tc1, (char*)tc2); free(tc1); free(tc2); - return(i); + return i; } /* strxfrm replacment, convert Thai string to sortable string @@ -605,9 +601,9 @@ int my_strxfrm_tis620(uchar * dest, const uchar * src, int len) uint bufSize; uchar *tmp; - bufSize = (uint) buffsize((char*) src); - tmp = thai2sortable(src, len); - memcpy((uchar *) dest, tmp, bufSize); + bufSize= (uint)buffsize((char*) src); + tmp= thai2sortable(src, len); + memcpy((uchar *)dest, tmp, bufSize); free(tmp); return bufSize; } @@ -637,7 +633,7 @@ my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)), if (*ptr == escape && ptr+1 != end) { ptr++; /* Skipp escape */ - *min_str++= *max_str++ = *ptr; + *min_str++ = *max_str++ = *ptr; continue; } if (*ptr == w_one) /* '_' in SQL */ @@ -671,52 +667,40 @@ my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)), */ void ThNormalize(uchar* ptr, uint field_length, const uchar* from, uint length) { - const uchar* fr = from; - uchar* p = ptr; + const uchar* fr= from; + uchar* p= ptr; + + if (length > field_length) + length= field_length; - if(length > field_length) { - length = field_length; - } while (length--) - { - if((istone(*fr) || isdiacrt1(*fr)) && + if ((istone(*fr) || isdiacrt1(*fr)) && (islwrvowel(fr[1]) || isuprvowel(fr[1]))) { - *p = fr[1]; - p[1] = *fr; - fr += 2; - p += 2; + *p= fr[1]; + p[1]= *fr; + fr+= 2; + p+= 2; length--; } else - { *p++ = *fr++; - } - } } -CHARSET_INFO my_charset_tis620 = +static MY_COLLATION_HANDLER my_collation_ci_handler = { - 18,0,0, /* number */ - MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ - "tis620", /* cs name */ - "tis620_thai_ci", /* name */ - "", /* comment */ - ctype_tis620, - to_lower_tis620, - to_upper_tis620, - sort_order_tis620, - NULL, /* tab_to_uni */ - NULL, /* tab_from_uni */ - "","", - 4, /* strxfrm_multiply */ my_strnncoll_tis620, my_strnncollsp_tis620, my_strnxfrm_tis620, my_like_range_tis620, my_wildcmp_8bit, /* wildcmp */ - 1, /* mbmaxlen */ + my_strcasecmp_8bit, + my_hash_sort_simple, +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ NULL, /* ismbchar */ NULL, /* mbcharlen */ my_numchars_8bit, @@ -727,9 +711,6 @@ CHARSET_INFO my_charset_tis620 = my_casedn_str_8bit, my_caseup_8bit, my_casedn_8bit, - my_strcasecmp_8bit, - my_hash_sort_simple, - 0, my_snprintf_8bit, my_long10_to_str_8bit, my_longlong10_to_str_8bit, @@ -743,4 +724,50 @@ CHARSET_INFO my_charset_tis620 = }; + +CHARSET_INFO my_charset_tis620_thai_ci= +{ + 18,0,0, /* number */ + MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ + "tis620", /* cs name */ + "tis620_thai_ci", /* name */ + "", /* comment */ + ctype_tis620, + to_lower_tis620, + to_upper_tis620, + sort_order_tis620, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 4, /* strxfrm_multiply */ + 1, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + +CHARSET_INFO my_charset_tis620_bin= +{ + 89,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "tis620", /* cs name */ + "tis620_bin", /* name */ + "", /* comment */ + ctype_tis620, + to_lower_tis620, + to_upper_tis620, + sort_order_tis620, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 1, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_bin_handler +}; + + #endif diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c new file mode 100644 index 00000000000..5d78ab5dcff --- /dev/null +++ b/strings/ctype-ucs2.c @@ -0,0 +1,1088 @@ +/* Copyright (C) 2000 MySQL AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* UCS2 support. Written by Alexander Barkov <bar@mysql.com> */ + +#include <my_global.h> +#include "m_string.h" +#include "m_ctype.h" +#include <errno.h> + + +#ifdef HAVE_CHARSET_ucs2 + +#ifndef EILSEQ +#define EILSEQ ENOENT +#endif + +extern MY_UNICASE_INFO *uni_plane[256]; + +static uchar ctype_ucs2[] = { + 0, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16, + 16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16, + 16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +static uchar to_lower_ucs2[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, + 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, + 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, + 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, + 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 +}; + +static uchar to_upper_ucs2[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127, + 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, + 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, + 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, + 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 +}; + + +static int my_ucs2_uni (CHARSET_INFO *cs __attribute__((unused)) , + my_wc_t * pwc, const uchar *s, const uchar *e) +{ + if (s+2 > e) /* Need 2 characters */ + return MY_CS_TOOFEW(0); + + *pwc= ((unsigned char)s[0]) * 256 + ((unsigned char)s[1]); + return 2; +} + +static int my_uni_ucs2 (CHARSET_INFO *cs __attribute__((unused)) , + my_wc_t wc, uchar *r, uchar *e) +{ + if ( r+2 > e ) + return MY_CS_TOOSMALL; + + r[0]=wc >> 8; + r[1]=wc & 0xFF; + return 2; +} + + +static void my_caseup_ucs2(CHARSET_INFO *cs, char *s, uint slen) +{ + my_wc_t wc; + int res; + char *e=s+slen; + + while ((s < e) && (res=my_ucs2_uni(cs,&wc, (uchar *)s, (uchar*)e))>0 ) + { + int plane = (wc>>8) & 0xFF; + wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].toupper : wc; + if (res != my_uni_ucs2(cs,wc,(uchar*)s,(uchar*)e)) + break; + s+=res; + } +} + +static void my_hash_sort_ucs2(CHARSET_INFO *cs, const uchar *s, uint slen, ulong *n1, ulong *n2) +{ + my_wc_t wc; + int res; + const uchar *e=s+slen; + + while ((s < e) && (res=my_ucs2_uni(cs,&wc, (uchar *)s, (uchar*)e))>0 ) + { + int plane = (wc>>8) & 0xFF; + wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].sort : wc; + n1[0]^= (((n1[0] & 63)+n2[0])*(wc & 0xFF))+ (n1[0] << 8); + n2[0]+=3; + n1[0]^= (((n1[0] & 63)+n2[0])*(wc >> 8))+ (n1[0] << 8); + n2[0]+=3; + s+=res; + } +} + + +static void my_caseup_str_ucs2(CHARSET_INFO * cs __attribute__((unused)), + char * s __attribute__((unused))) +{ +} + + + +static void my_casedn_ucs2(CHARSET_INFO *cs, char *s, uint slen) +{ + my_wc_t wc; + int res; + char *e=s+slen; + + while ((s < e) && (res=my_ucs2_uni(cs, &wc, (uchar*)s, (uchar*)e))>0) + { + int plane = (wc>>8) & 0xFF; + wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].tolower : wc; + if (res != my_uni_ucs2(cs, wc, (uchar*)s, (uchar*)e)) + { + break; + } + s+=res; + } +} + +static void my_casedn_str_ucs2(CHARSET_INFO *cs __attribute__((unused)), + char * s __attribute__((unused))) +{ +} + + +static int my_strnncoll_ucs2(CHARSET_INFO *cs, + const uchar *s, uint slen, const uchar *t, uint tlen) +{ + int s_res,t_res; + my_wc_t s_wc,t_wc; + const uchar *se=s+slen; + const uchar *te=t+tlen; + + while ( s < se && t < te ) + { + int plane; + s_res=my_ucs2_uni(cs,&s_wc, s, se); + t_res=my_ucs2_uni(cs,&t_wc, t, te); + + if ( s_res <= 0 || t_res <= 0 ) + { + /* Incorrect string, compare by char value */ + return ((int)s[0]-(int)t[0]); + } + + plane=(s_wc>>8) & 0xFF; + s_wc = uni_plane[plane] ? uni_plane[plane][s_wc & 0xFF].sort : s_wc; + plane=(t_wc>>8) & 0xFF; + t_wc = uni_plane[plane] ? uni_plane[plane][t_wc & 0xFF].sort : t_wc; + if ( s_wc != t_wc ) + { + return ((int) s_wc) - ((int) t_wc); + } + + s+=s_res; + t+=t_res; + } + return ( (se-s) - (te-t) ); +} + +static int my_strncasecmp_ucs2(CHARSET_INFO *cs, + const char *s, const char *t, uint len) +{ + int s_res,t_res; + my_wc_t s_wc,t_wc; + const char *se=s+len; + const char *te=t+len; + + while ( s < se && t < te ) + { + int plane; + + s_res=my_ucs2_uni(cs,&s_wc, (const uchar*)s, (const uchar*)se); + t_res=my_ucs2_uni(cs,&t_wc, (const uchar*)t, (const uchar*)te); + + if ( s_res <= 0 || t_res <= 0 ) + { + /* Incorrect string, compare by char value */ + return ((int)s[0]-(int)t[0]); + } + + plane=(s_wc>>8) & 0xFF; + s_wc = uni_plane[plane] ? uni_plane[plane][s_wc & 0xFF].tolower : s_wc; + + plane=(t_wc>>8) & 0xFF; + t_wc = uni_plane[plane] ? uni_plane[plane][t_wc & 0xFF].tolower : t_wc; + + if ( s_wc != t_wc ) + return ((int) s_wc) - ((int) t_wc); + + s+=s_res; + t+=t_res; + } + return ( (se-s) - (te-t) ); +} + +static int my_strcasecmp_ucs2(CHARSET_INFO *cs, const char *s, const char *t) +{ + uint s_len=strlen(s); + uint t_len=strlen(t); + uint len = (s_len > t_len) ? s_len : t_len; + return my_strncasecmp_ucs2(cs, s, t, len); +} + +static int my_strnxfrm_ucs2(CHARSET_INFO *cs, + uchar *dst, uint dstlen, const uchar *src, uint srclen) +{ + my_wc_t wc; + int res; + int plane; + uchar *de = dst + dstlen; + const uchar *se = src + srclen; + const uchar *dst_orig = dst; + + while( src < se && dst < de ) + { + if ((res=my_ucs2_uni(cs,&wc, src, se))<0) + { + break; + } + src+=res; + srclen-=res; + + plane=(wc>>8) & 0xFF; + wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].sort : wc; + + if ((res=my_uni_ucs2(cs,wc,dst,de)) <0) + { + break; + } + dst+=res; + } + return dst - dst_orig; +} + +static int my_ismbchar_ucs2(CHARSET_INFO *cs __attribute__((unused)), + const char *b __attribute__((unused)), + const char *e __attribute__((unused))) +{ + return 2; +} + +static int my_mbcharlen_ucs2(CHARSET_INFO *cs __attribute__((unused)) , + uint c __attribute__((unused))) +{ + return 2; +} + + +#include <m_string.h> +#include <stdarg.h> +#include <assert.h> + +static int my_vsnprintf_ucs2(char *dst, uint n, const char* fmt, va_list ap) +{ + char *start=dst, *end=dst+n-1; + for (; *fmt ; fmt++) + { + if (fmt[0] != '%') + { + if (dst == end) /* End of buffer */ + break; + + *dst++='\0'; *dst++= *fmt; /* Copy ordinary char */ + continue; + } + + fmt++; + + /* Skip if max size is used (to be compatible with printf) */ + while ( (*fmt>='0' && *fmt<='9') || *fmt == '.' || *fmt == '-') + fmt++; + + if (*fmt == 'l') + fmt++; + + if (*fmt == 's') /* String parameter */ + { + reg2 char *par = va_arg(ap, char *); + uint plen; + uint left_len = (uint)(end-dst); + if (!par) par = (char*)"(null)"; + plen = (uint) strlen(par); + if (left_len <= plen*2) + plen = left_len/2 - 1; + + for ( ; plen ; plen--, dst+=2, par++) + { + dst[0]='\0'; + dst[1]=par[0]; + } + continue; + } + else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */ + { + register int iarg; + char nbuf[16]; + char *pbuf=nbuf; + + if ((uint) (end-dst) < 32) + break; + iarg = va_arg(ap, int); + if (*fmt == 'd') + int10_to_str((long) iarg, nbuf, -10); + else + int10_to_str((long) (uint) iarg,nbuf,10); + + for (; pbuf[0]; pbuf++) + { + *dst++='\0'; + *dst++=*pbuf; + } + continue; + } + + /* We come here on '%%', unknown code or too long parameter */ + if (dst == end) + break; + *dst++='\0'; + *dst++='%'; /* % used as % or unknown code */ + } + + DBUG_ASSERT(dst <= end); + *dst='\0'; /* End of errmessage */ + return (uint) (dst - start); +} + +static int my_snprintf_ucs2(CHARSET_INFO *cs __attribute__((unused)) + ,char* to, uint n, const char* fmt, ...) +{ + va_list args; + va_start(args,fmt); + return my_vsnprintf_ucs2(to, n, fmt, args); +} + + +long my_strntol_ucs2(CHARSET_INFO *cs, + const char *nptr, uint l, int base, + char **endptr, int *err) +{ + int negative=0; + int overflow; + int cnv; + my_wc_t wc; + register unsigned int cutlim; + register ulong cutoff; + register ulong res; + register const uchar *s= (const uchar*) nptr; + register const uchar *e= (const uchar*) nptr+l; + const uchar *save; + + *err= 0; + do + { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + switch (wc) + { + case ' ' : break; + case '\t': break; + case '-' : negative= !negative; break; + case '+' : break; + default : goto bs; + } + } + else /* No more characters or bad multibyte sequence */ + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; + return 0; + } + s+=cnv; + } while (1); + +bs: + +#ifdef NOT_USED + if (base <= 0 || base == 1 || base > 36) + base = 10; +#endif + + overflow = 0; + res = 0; + save = s; + cutoff = ((ulong)~0L) / (unsigned long int) base; + cutlim = (uint) (((ulong)~0L) % (unsigned long int) base); + + do { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + s+=cnv; + if ( wc>='0' && wc<='9') + wc -= '0'; + else if ( wc>='A' && wc<='Z') + wc = wc - 'A' + 10; + else if ( wc>='a' && wc<='z') + wc = wc - 'a' + 10; + else + break; + if ((int)wc >= base) + break; + if (res > cutoff || (res == cutoff && wc > cutlim)) + overflow = 1; + else + { + res *= (ulong) base; + res += wc; + } + } + else if (cnv==MY_CS_ILSEQ) + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0]=EILSEQ; + return 0; + } + else + { + /* No more characters */ + break; + } + } while(1); + + if (endptr != NULL) + *endptr = (char *) s; + + if (s == save) + { + err[0]=EDOM; + return 0L; + } + + if (negative) + { + if (res > (ulong) LONG_MIN) + overflow = 1; + } + else if (res > (ulong) LONG_MAX) + overflow = 1; + + if (overflow) + { + err[0]=ERANGE; + return negative ? LONG_MIN : LONG_MAX; + } + + return (negative ? -((long) res) : (long) res); +} + + +ulong my_strntoul_ucs2(CHARSET_INFO *cs, + const char *nptr, uint l, int base, + char **endptr, int *err) +{ + int negative=0; + int overflow; + int cnv; + my_wc_t wc; + register unsigned int cutlim; + register ulong cutoff; + register ulong res; + register const uchar *s= (const uchar*) nptr; + register const uchar *e= (const uchar*) nptr+l; + const uchar *save; + + *err= 0; + do + { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + switch (wc) + { + case ' ' : break; + case '\t': break; + case '-' : negative= !negative; break; + case '+' : break; + default : goto bs; + } + } + else /* No more characters or bad multibyte sequence */ + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; + return 0; + } + s+=cnv; + } while (1); + +bs: + +#ifdef NOT_USED + if (base <= 0 || base == 1 || base > 36) + base = 10; +#endif + + overflow = 0; + res = 0; + save = s; + cutoff = ((ulong)~0L) / (unsigned long int) base; + cutlim = (uint) (((ulong)~0L) % (unsigned long int) base); + + do + { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + s+=cnv; + if ( wc>='0' && wc<='9') + wc -= '0'; + else if ( wc>='A' && wc<='Z') + wc = wc - 'A' + 10; + else if ( wc>='a' && wc<='z') + wc = wc - 'a' + 10; + else + break; + if ((int)wc >= base) + break; + if (res > cutoff || (res == cutoff && wc > cutlim)) + overflow = 1; + else + { + res *= (ulong) base; + res += wc; + } + } + else if (cnv==MY_CS_ILSEQ) + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0]=EILSEQ; + return 0; + } + else + { + /* No more characters */ + break; + } + } while(1); + + if (endptr != NULL) + *endptr = (char *) s; + + if (s == save) + { + err[0]=EDOM; + return 0L; + } + + if (overflow) + { + err[0]=(ERANGE); + return ((ulong)~0L); + } + + return (negative ? -((long) res) : (long) res); + +} + + + +longlong my_strntoll_ucs2(CHARSET_INFO *cs, + const char *nptr, uint l, int base, + char **endptr, int *err) +{ + int negative=0; + int overflow; + int cnv; + my_wc_t wc; + register ulonglong cutoff; + register unsigned int cutlim; + register ulonglong res; + register const uchar *s= (const uchar*) nptr; + register const uchar *e= (const uchar*) nptr+l; + const uchar *save; + + *err= 0; + do + { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + switch (wc) + { + case ' ' : break; + case '\t': break; + case '-' : negative= !negative; break; + case '+' : break; + default : goto bs; + } + } + else /* No more characters or bad multibyte sequence */ + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; + return 0; + } + s+=cnv; + } while (1); + +bs: + +#ifdef NOT_USED + if (base <= 0 || base == 1 || base > 36) + base = 10; +#endif + + overflow = 0; + res = 0; + save = s; + cutoff = (~(ulonglong) 0) / (unsigned long int) base; + cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base); + + do { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + s+=cnv; + if ( wc>='0' && wc<='9') + wc -= '0'; + else if ( wc>='A' && wc<='Z') + wc = wc - 'A' + 10; + else if ( wc>='a' && wc<='z') + wc = wc - 'a' + 10; + else + break; + if ((int)wc >= base) + break; + if (res > cutoff || (res == cutoff && wc > cutlim)) + overflow = 1; + else + { + res *= (ulonglong) base; + res += wc; + } + } + else if (cnv==MY_CS_ILSEQ) + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0]=EILSEQ; + return 0; + } + else + { + /* No more characters */ + break; + } + } while(1); + + if (endptr != NULL) + *endptr = (char *) s; + + if (s == save) + { + err[0]=EDOM; + return 0L; + } + + if (negative) + { + if (res > (ulonglong) LONGLONG_MIN) + overflow = 1; + } + else if (res > (ulonglong) LONGLONG_MAX) + overflow = 1; + + if (overflow) + { + err[0]=ERANGE; + return negative ? LONGLONG_MIN : LONGLONG_MAX; + } + + return (negative ? -((longlong)res) : (longlong)res); +} + + + + +ulonglong my_strntoull_ucs2(CHARSET_INFO *cs, + const char *nptr, uint l, int base, + char **endptr, int *err) +{ + int negative=0; + int overflow; + int cnv; + my_wc_t wc; + register ulonglong cutoff; + register unsigned int cutlim; + register ulonglong res; + register const uchar *s= (const uchar*) nptr; + register const uchar *e= (const uchar*) nptr+l; + const uchar *save; + + *err= 0; + do + { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + switch (wc) + { + case ' ' : break; + case '\t': break; + case '-' : negative= !negative; break; + case '+' : break; + default : goto bs; + } + } + else /* No more characters or bad multibyte sequence */ + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0]= (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; + return 0; + } + s+=cnv; + } while (1); + +bs: + +#ifdef NOT_USED + if (base <= 0 || base == 1 || base > 36) + base = 10; +#endif + + overflow = 0; + res = 0; + save = s; + cutoff = (~(ulonglong) 0) / (unsigned long int) base; + cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base); + + do + { + if ((cnv=cs->cset->mb_wc(cs,&wc,s,e))>0) + { + s+=cnv; + if ( wc>='0' && wc<='9') + wc -= '0'; + else if ( wc>='A' && wc<='Z') + wc = wc - 'A' + 10; + else if ( wc>='a' && wc<='z') + wc = wc - 'a' + 10; + else + break; + if ((int)wc >= base) + break; + if (res > cutoff || (res == cutoff && wc > cutlim)) + overflow = 1; + else + { + res *= (ulonglong) base; + res += wc; + } + } + else if (cnv==MY_CS_ILSEQ) + { + if (endptr !=NULL ) + *endptr = (char*)s; + err[0]= EILSEQ; + return 0; + } + else + { + /* No more characters */ + break; + } + } while(1); + + if (endptr != NULL) + *endptr = (char *) s; + + if (s == save) + { + err[0]= EDOM; + return 0L; + } + + if (overflow) + { + err[0]= ERANGE; + return (~(ulonglong) 0); + } + + return (negative ? -((longlong) res) : (longlong) res); +} + + +double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), + char *nptr, uint length, + char **endptr, int *err) +{ + char buf[256]; + double res; + register char *b=buf; + register const uchar *s= (const uchar*) nptr; + register const uchar *end; + my_wc_t wc; + int cnv; + + *err= 0; + /* Cut too long strings */ + if (length >= sizeof(buf)) + length= sizeof(buf)-1; + end= s+length; + + while ((cnv=cs->cset->mb_wc(cs,&wc,s,end)) > 0) + { + s+=cnv; + if (wc > (int) (uchar) 'e' || !wc) + break; /* Can't be part of double */ + *b++=wc; + } + *b= 0; + + errno= 0; + res=strtod(buf, endptr); + *err= errno; + if (endptr) + *endptr=(char*) (*endptr-buf+nptr); + return res; +} + + +/* + This is a fast version optimized for the case of radix 10 / -10 +*/ + +int my_l10tostr_ucs2(CHARSET_INFO *cs, + char *dst, uint len, int radix, long int val) +{ + char buffer[66]; + register char *p, *db, *de; + long int new_val; + int sl=0; + + p = &buffer[sizeof(buffer)-1]; + *p='\0'; + + if (radix < 0) + { + if (val < 0) + { + sl = 1; + val = -val; + } + } + + new_val = (long) ((unsigned long int) val / 10); + *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); + val = new_val; + + while (val != 0) + { + new_val=val/10; + *--p = '0' + (char) (val-new_val*10); + val= new_val; + } + + if (sl) + { + *--p='-'; + } + + for ( db=dst, de=dst+len ; (dst<de) && *p ; p++) + { + int cnvres=cs->cset->wc_mb(cs,(my_wc_t)p[0],(uchar*) dst, (uchar*) de); + if (cnvres>0) + dst+=cnvres; + else + break; + } + return (int) (dst-db); +} + +int my_ll10tostr_ucs2(CHARSET_INFO *cs __attribute__((unused)), + char *dst, uint len, int radix, longlong val) +{ + char buffer[65]; + register char *p, *db, *de; + long long_val; + int sl=0; + + if (radix < 0) + { + if (val < 0) + { + sl=1; + val = -val; + } + } + + p = &buffer[sizeof(buffer)-1]; + *p='\0'; + + if (val == 0) + { + *--p='0'; + goto cnv; + } + + while ((ulonglong) val > (ulonglong) LONG_MAX) + { + ulonglong quo=(ulonglong) val/(uint) 10; + uint rem= (uint) (val- quo* (uint) 10); + *--p = '0' + rem; + val= quo; + } + + long_val= (long) val; + while (long_val != 0) + { + long quo= long_val/10; + *--p = '0' + (long_val - quo*10); + long_val= quo; + } + +cnv: + if (sl) + { + *--p='-'; + } + + for ( db=dst, de=dst+len ; (dst<de) && *p ; p++) + { + int cnvres=cs->cset->wc_mb(cs, (my_wc_t) p[0], (uchar*) dst, (uchar*) de); + if (cnvres>0) + dst+=cnvres; + else + break; + } + return (int) (dst-db); +} + +static +uint my_numchars_ucs2(CHARSET_INFO *cs __attribute__((unused)), + const char *b, const char *e) +{ + return (e-b)/2; +} + +static +uint my_charpos_ucs2(CHARSET_INFO *cs __attribute__((unused)), + const char *b __attribute__((unused)), + const char *e __attribute__((unused)), + uint pos) +{ + return pos*2; +} + + +static MY_COLLATION_HANDLER my_collation_ci_handler = +{ + my_strnncoll_ucs2, + my_strnncoll_ucs2, + my_strnxfrm_ucs2, + my_like_range_simple, + my_wildcmp_mb, + my_strcasecmp_ucs2, + my_hash_sort_ucs2 +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + my_ismbchar_ucs2, /* ismbchar */ + my_mbcharlen_ucs2, /* mbcharlen */ + my_numchars_ucs2, + my_charpos_ucs2, + my_ucs2_uni, /* mb_wc */ + my_uni_ucs2, /* wc_mb */ + my_caseup_str_ucs2, + my_casedn_str_ucs2, + my_caseup_ucs2, + my_casedn_ucs2, + my_snprintf_ucs2, + my_l10tostr_ucs2, + my_ll10tostr_ucs2, + my_fill_8bit, + my_strntol_ucs2, + my_strntoul_ucs2, + my_strntoll_ucs2, + my_strntoull_ucs2, + my_strntod_ucs2, + my_scan_8bit +}; + + + +CHARSET_INFO my_charset_ucs2_general_ci= +{ + 35,0,0, /* number */ + MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONTEXT, + "ucs2", /* cs name */ + "ucs2_general_ci", /* name */ + "", /* comment */ + ctype_ucs2, /* ctype */ + to_lower_ucs2, /* to_lower */ + to_upper_ucs2, /* to_upper */ + to_upper_ucs2, /* sort_order */ + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 1, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + + +CHARSET_INFO my_charset_ucs2_bin= +{ + 90,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT|MY_CS_UNICODE|MY_CS_NONTEXT, + "ucs2", /* cs name */ + "ucs2_bin", /* name */ + "", /* comment */ + ctype_ucs2, /* ctype */ + to_lower_ucs2, /* to_lower */ + to_upper_ucs2, /* to_upper */ + to_upper_ucs2, /* sort_order */ + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 2, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_bin_handler +}; + + +#endif diff --git a/strings/ctype-ujis.c b/strings/ctype-ujis.c index 92214868018..eb31c49013a 100644 --- a/strings/ctype-ujis.c +++ b/strings/ctype-ujis.c @@ -8257,7 +8257,7 @@ my_mb_wc_euc_jp(CHARSET_INFO *cs,my_wc_t *pwc, const uchar *s, const uchar *e) { int c1,c2,c3; - if (s>e) + if (s >= e) return MY_CS_TOOFEW(0); c1=s[0]; @@ -8425,27 +8425,20 @@ my_wc_mb_euc_jp(CHARSET_INFO *c,my_wc_t wc, unsigned char *s, unsigned char *e) return MY_CS_ILUNI; } -CHARSET_INFO my_charset_ujis = + +static MY_COLLATION_HANDLER my_collation_ci_handler = { - 12,0,0, /* number */ - MY_CS_COMPILED|MY_CS_PRIMARY, /* state */ - "ujis", /* cs name */ - "ujis_japanese_ci", /* name */ - "", /* comment */ - ctype_ujis, - to_lower_ujis, - to_upper_ujis, - sort_order_ujis, - NULL, /* tab_to_uni */ - NULL, /* tab_from_uni */ - "","", - 0, /* strxfrm_multiply */ my_strnncoll_simple,/* strnncoll */ my_strnncollsp_simple, my_strnxfrm_simple, /* strnxfrm */ my_like_range_simple,/* like_range */ my_wildcmp_mb, /* wildcmp */ - 3, /* mbmaxlen */ + my_strcasecmp_mb, + my_hash_sort_simple, +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ ismbchar_ujis, mbcharlen_ujis, my_numchars_mb, @@ -8456,9 +8449,6 @@ CHARSET_INFO my_charset_ujis = my_casedn_str_mb, my_caseup_mb, my_casedn_mb, - my_strcasecmp_mb, - my_hash_sort_simple, - 0, my_snprintf_8bit, my_long10_to_str_8bit, my_longlong10_to_str_8bit, @@ -8472,4 +8462,49 @@ CHARSET_INFO my_charset_ujis = }; + +CHARSET_INFO my_charset_ujis_japanese_ci= +{ + 12,0,0, /* number */ + MY_CS_COMPILED|MY_CS_PRIMARY, /* state */ + "ujis", /* cs name */ + "ujis_japanese_ci", /* name */ + "", /* comment */ + ctype_ujis, + to_lower_ujis, + to_upper_ujis, + sort_order_ujis, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "","", + 0, /* strxfrm_multiply */ + 3, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + + +CHARSET_INFO my_charset_ujis_bin= +{ + 91,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT, /* state */ + "ujis", /* cs name */ + "ujis_bin", /* name */ + "", /* comment */ + ctype_ujis, + to_lower_ujis, + to_upper_ujis, + sort_order_ujis, + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "","", + 0, /* strxfrm_multiply */ + 3, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_bin_handler +}; + + #endif diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index 4c908014994..4d9c735de21 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -1482,7 +1482,7 @@ static MY_UNICASE_INFO planeFF[]={ {0xFFFE,0xFFFE,0xFFFE}, {0xFFFF,0xFFFF,0xFFFF} }; -static MY_UNICASE_INFO *uni_plane[256]={ +MY_UNICASE_INFO *uni_plane[256]={ plane00, plane01, plane02, plane03, plane04, plane05, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -1950,40 +1950,30 @@ static int my_mbcharlen_utf8(CHARSET_INFO *cs __attribute__((unused)) , uint c) return 0; /* Illegal mb head */; } -CHARSET_INFO my_charset_utf8 = + +static MY_COLLATION_HANDLER my_collation_ci_handler = { - 33,0,0, /* number */ - MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ - "utf8", /* cs name */ - "utf8_general_ci", /* name */ - "", /* comment */ - ctype_utf8, /* ctype */ - to_lower_utf8, /* to_lower */ - to_upper_utf8, /* to_upper */ - to_upper_utf8, /* sort_order */ - NULL, /* tab_to_uni */ - NULL, /* tab_from_uni */ - "","", - 1, /* strxfrm_multiply */ - my_strnncoll_utf8, /* strnncoll */ + my_strnncoll_utf8, my_strnncollsp_utf8, - my_strnxfrm_utf8, /* strnxfrm */ - my_like_range_simple,/* like_range */ - my_wildcmp_mb, /* wildcmp */ - 3, /* mbmaxlen */ - my_ismbchar_utf8, /* ismbchar */ - my_mbcharlen_utf8, /* mbcharlen */ + my_strnxfrm_utf8, + my_like_range_simple, + my_wildcmp_mb, + my_strcasecmp_utf8, + my_hash_sort_utf8 +}; + +static MY_CHARSET_HANDLER my_charset_handler= +{ + my_ismbchar_utf8, + my_mbcharlen_utf8, my_numchars_mb, my_charpos_mb, - my_utf8_uni, /* mb_wc */ - my_uni_utf8, /* wc_mb */ + my_utf8_uni, + my_uni_utf8, my_caseup_str_utf8, my_casedn_str_utf8, my_caseup_utf8, my_casedn_utf8, - my_strcasecmp_utf8, - my_hash_sort_utf8, /* hash_sort */ - 0, my_snprintf_8bit, my_long10_to_str_8bit, my_longlong10_to_str_8bit, @@ -1997,6 +1987,53 @@ CHARSET_INFO my_charset_utf8 = }; + +CHARSET_INFO my_charset_utf8_general_ci= +{ + 33,0,0, /* number */ + MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM|MY_CS_UNICODE, /* state */ + "utf8", /* cs name */ + "utf8_general_ci", /* name */ + "", /* comment */ + ctype_utf8, /* ctype */ + to_lower_utf8, /* to_lower */ + to_upper_utf8, /* to_upper */ + to_upper_utf8, /* sort_order */ + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 1, /* strxfrm_multiply */ + 3, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + + +CHARSET_INFO my_charset_utf8_bin= +{ + 83,0,0, /* number */ + MY_CS_COMPILED|MY_CS_BINSORT|MY_CS_UNICODE, /* state */ + "utf8", /* cs name */ + "utf8_bin", /* name */ + "", /* comment */ + ctype_utf8, /* ctype */ + to_lower_utf8, /* to_lower */ + to_upper_utf8, /* to_upper */ + to_upper_utf8, /* sort_order */ + NULL, /* tab_to_uni */ + NULL, /* tab_from_uni */ + "", + "", + 0, /* strxfrm_multiply */ + 3, /* mbmaxlen */ + 0, + &my_charset_handler, + &my_collation_ci_handler +}; + + #ifdef MY_TEST_UTF8 #include <stdio.h> @@ -2053,1023 +2090,3 @@ int main() -#ifdef HAVE_CHARSET_ucs2 - -static uchar ctype_ucs2[] = { - 0, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16, - 16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16, - 16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -static uchar to_lower_ucs2[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 -}; - -static uchar to_upper_ucs2[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 -}; - - -static int my_ucs2_uni (CHARSET_INFO *cs __attribute__((unused)) , - my_wc_t * pwc, const uchar *s, const uchar *e) -{ - if (s+2 > e) /* Need 2 characters */ - return MY_CS_TOOFEW(0); - - *pwc= ((unsigned char)s[0]) * 256 + ((unsigned char)s[1]); - return 2; -} - -static int my_uni_ucs2 (CHARSET_INFO *cs __attribute__((unused)) , - my_wc_t wc, uchar *r, uchar *e) -{ - if ( r+2 > e ) - return MY_CS_TOOSMALL; - - r[0]=wc >> 8; - r[1]=wc & 0xFF; - return 2; -} - - -static void my_caseup_ucs2(CHARSET_INFO *cs, char *s, uint slen) -{ - my_wc_t wc; - int res; - char *e=s+slen; - - while ((s < e) && (res=my_ucs2_uni(cs,&wc, (uchar *)s, (uchar*)e))>0 ) - { - int plane = (wc>>8) & 0xFF; - wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].toupper : wc; - if (res != my_uni_ucs2(cs,wc,(uchar*)s,(uchar*)e)) - break; - s+=res; - } -} - -static void my_hash_sort_ucs2(CHARSET_INFO *cs, const uchar *s, uint slen, ulong *n1, ulong *n2) -{ - my_wc_t wc; - int res; - const uchar *e=s+slen; - - while ((s < e) && (res=my_ucs2_uni(cs,&wc, (uchar *)s, (uchar*)e))>0 ) - { - int plane = (wc>>8) & 0xFF; - wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].sort : wc; - n1[0]^= (((n1[0] & 63)+n2[0])*(wc & 0xFF))+ (n1[0] << 8); - n2[0]+=3; - n1[0]^= (((n1[0] & 63)+n2[0])*(wc >> 8))+ (n1[0] << 8); - n2[0]+=3; - s+=res; - } -} - - -static void my_caseup_str_ucs2(CHARSET_INFO * cs __attribute__((unused)), - char * s __attribute__((unused))) -{ -} - - - -static void my_casedn_ucs2(CHARSET_INFO *cs, char *s, uint slen) -{ - my_wc_t wc; - int res; - char *e=s+slen; - - while ((s < e) && (res=my_ucs2_uni(cs, &wc, (uchar*)s, (uchar*)e))>0) - { - int plane = (wc>>8) & 0xFF; - wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].tolower : wc; - if (res != my_uni_ucs2(cs, wc, (uchar*)s, (uchar*)e)) - { - break; - } - s+=res; - } -} - -static void my_casedn_str_ucs2(CHARSET_INFO *cs __attribute__((unused)), - char * s __attribute__((unused))) -{ -} - - -static int my_strnncoll_ucs2(CHARSET_INFO *cs, - const uchar *s, uint slen, const uchar *t, uint tlen) -{ - int s_res,t_res; - my_wc_t s_wc,t_wc; - const uchar *se=s+slen; - const uchar *te=t+tlen; - - while ( s < se && t < te ) - { - int plane; - s_res=my_ucs2_uni(cs,&s_wc, s, se); - t_res=my_ucs2_uni(cs,&t_wc, t, te); - - if ( s_res <= 0 || t_res <= 0 ) - { - /* Incorrect string, compare by char value */ - return ((int)s[0]-(int)t[0]); - } - - plane=(s_wc>>8) & 0xFF; - s_wc = uni_plane[plane] ? uni_plane[plane][s_wc & 0xFF].sort : s_wc; - plane=(t_wc>>8) & 0xFF; - t_wc = uni_plane[plane] ? uni_plane[plane][t_wc & 0xFF].sort : t_wc; - if ( s_wc != t_wc ) - { - return ((int) s_wc) - ((int) t_wc); - } - - s+=s_res; - t+=t_res; - } - return ( (se-s) - (te-t) ); -} - -static int my_strncasecmp_ucs2(CHARSET_INFO *cs, - const char *s, const char *t, uint len) -{ - int s_res,t_res; - my_wc_t s_wc,t_wc; - const char *se=s+len; - const char *te=t+len; - - while ( s < se && t < te ) - { - int plane; - - s_res=my_ucs2_uni(cs,&s_wc, (const uchar*)s, (const uchar*)se); - t_res=my_ucs2_uni(cs,&t_wc, (const uchar*)t, (const uchar*)te); - - if ( s_res <= 0 || t_res <= 0 ) - { - /* Incorrect string, compare by char value */ - return ((int)s[0]-(int)t[0]); - } - - plane=(s_wc>>8) & 0xFF; - s_wc = uni_plane[plane] ? uni_plane[plane][s_wc & 0xFF].tolower : s_wc; - - plane=(t_wc>>8) & 0xFF; - t_wc = uni_plane[plane] ? uni_plane[plane][t_wc & 0xFF].tolower : t_wc; - - if ( s_wc != t_wc ) - return ((int) s_wc) - ((int) t_wc); - - s+=s_res; - t+=t_res; - } - return ( (se-s) - (te-t) ); -} - -static int my_strcasecmp_ucs2(CHARSET_INFO *cs, const char *s, const char *t) -{ - uint s_len=strlen(s); - uint t_len=strlen(t); - uint len = (s_len > t_len) ? s_len : t_len; - return my_strncasecmp_ucs2(cs, s, t, len); -} - -static int my_strnxfrm_ucs2(CHARSET_INFO *cs, - uchar *dst, uint dstlen, const uchar *src, uint srclen) -{ - my_wc_t wc; - int res; - int plane; - uchar *de = dst + dstlen; - const uchar *se = src + srclen; - const uchar *dst_orig = dst; - - while( src < se && dst < de ) - { - if ((res=my_ucs2_uni(cs,&wc, src, se))<0) - { - break; - } - src+=res; - srclen-=res; - - plane=(wc>>8) & 0xFF; - wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].sort : wc; - - if ((res=my_uni_ucs2(cs,wc,dst,de)) <0) - { - break; - } - dst+=res; - } - return dst - dst_orig; -} - -static int my_ismbchar_ucs2(CHARSET_INFO *cs __attribute__((unused)), - const char *b __attribute__((unused)), - const char *e __attribute__((unused))) -{ - return 2; -} - -static int my_mbcharlen_ucs2(CHARSET_INFO *cs __attribute__((unused)) , - uint c __attribute__((unused))) -{ - return 2; -} - - -#include <m_string.h> -#include <stdarg.h> -#include <assert.h> - -static int my_vsnprintf_ucs2(char *dst, uint n, const char* fmt, va_list ap) -{ - char *start=dst, *end=dst+n-1; - for (; *fmt ; fmt++) - { - if (fmt[0] != '%') - { - if (dst == end) /* End of buffer */ - break; - - *dst++='\0'; *dst++= *fmt; /* Copy ordinary char */ - continue; - } - - fmt++; - - /* Skip if max size is used (to be compatible with printf) */ - while ( (*fmt>='0' && *fmt<='9') || *fmt == '.' || *fmt == '-') - fmt++; - - if (*fmt == 'l') - fmt++; - - if (*fmt == 's') /* String parameter */ - { - reg2 char *par = va_arg(ap, char *); - uint plen; - uint left_len = (uint)(end-dst); - if (!par) par = (char*)"(null)"; - plen = (uint) strlen(par); - if (left_len <= plen*2) - plen = left_len/2 - 1; - - for ( ; plen ; plen--, dst+=2, par++) - { - dst[0]='\0'; - dst[1]=par[0]; - } - continue; - } - else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */ - { - register int iarg; - char nbuf[16]; - char *pbuf=nbuf; - - if ((uint) (end-dst) < 32) - break; - iarg = va_arg(ap, int); - if (*fmt == 'd') - int10_to_str((long) iarg, nbuf, -10); - else - int10_to_str((long) (uint) iarg,nbuf,10); - - for (; pbuf[0]; pbuf++) - { - *dst++='\0'; - *dst++=*pbuf; - } - continue; - } - - /* We come here on '%%', unknown code or too long parameter */ - if (dst == end) - break; - *dst++='\0'; - *dst++='%'; /* % used as % or unknown code */ - } - - DBUG_ASSERT(dst <= end); - *dst='\0'; /* End of errmessage */ - return (uint) (dst - start); -} - -static int my_snprintf_ucs2(CHARSET_INFO *cs __attribute__((unused)) - ,char* to, uint n, const char* fmt, ...) -{ - va_list args; - va_start(args,fmt); - return my_vsnprintf_ucs2(to, n, fmt, args); -} - - -long my_strntol_ucs2(CHARSET_INFO *cs, - const char *nptr, uint l, int base, - char **endptr, int *err) -{ - int negative=0; - int overflow; - int cnv; - my_wc_t wc; - register unsigned int cutlim; - register ulong cutoff; - register ulong res; - register const uchar *s= (const uchar*) nptr; - register const uchar *e= (const uchar*) nptr+l; - const uchar *save; - - *err= 0; - do - { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - switch (wc) - { - case ' ' : break; - case '\t': break; - case '-' : negative= !negative; break; - case '+' : break; - default : goto bs; - } - } - else /* No more characters or bad multibyte sequence */ - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; - return 0; - } - s+=cnv; - } while (1); - -bs: - -#ifdef NOT_USED - if (base <= 0 || base == 1 || base > 36) - base = 10; -#endif - - overflow = 0; - res = 0; - save = s; - cutoff = ((ulong)~0L) / (unsigned long int) base; - cutlim = (uint) (((ulong)~0L) % (unsigned long int) base); - - do { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - s+=cnv; - if ( wc>='0' && wc<='9') - wc -= '0'; - else if ( wc>='A' && wc<='Z') - wc = wc - 'A' + 10; - else if ( wc>='a' && wc<='z') - wc = wc - 'a' + 10; - else - break; - if ((int)wc >= base) - break; - if (res > cutoff || (res == cutoff && wc > cutlim)) - overflow = 1; - else - { - res *= (ulong) base; - res += wc; - } - } - else if (cnv==MY_CS_ILSEQ) - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0]=EILSEQ; - return 0; - } - else - { - /* No more characters */ - break; - } - } while(1); - - if (endptr != NULL) - *endptr = (char *) s; - - if (s == save) - { - err[0]=EDOM; - return 0L; - } - - if (negative) - { - if (res > (ulong) LONG_MIN) - overflow = 1; - } - else if (res > (ulong) LONG_MAX) - overflow = 1; - - if (overflow) - { - err[0]=ERANGE; - return negative ? LONG_MIN : LONG_MAX; - } - - return (negative ? -((long) res) : (long) res); -} - - -ulong my_strntoul_ucs2(CHARSET_INFO *cs, - const char *nptr, uint l, int base, - char **endptr, int *err) -{ - int negative=0; - int overflow; - int cnv; - my_wc_t wc; - register unsigned int cutlim; - register ulong cutoff; - register ulong res; - register const uchar *s= (const uchar*) nptr; - register const uchar *e= (const uchar*) nptr+l; - const uchar *save; - - *err= 0; - do - { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - switch (wc) - { - case ' ' : break; - case '\t': break; - case '-' : negative= !negative; break; - case '+' : break; - default : goto bs; - } - } - else /* No more characters or bad multibyte sequence */ - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; - return 0; - } - s+=cnv; - } while (1); - -bs: - -#ifdef NOT_USED - if (base <= 0 || base == 1 || base > 36) - base = 10; -#endif - - overflow = 0; - res = 0; - save = s; - cutoff = ((ulong)~0L) / (unsigned long int) base; - cutlim = (uint) (((ulong)~0L) % (unsigned long int) base); - - do - { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - s+=cnv; - if ( wc>='0' && wc<='9') - wc -= '0'; - else if ( wc>='A' && wc<='Z') - wc = wc - 'A' + 10; - else if ( wc>='a' && wc<='z') - wc = wc - 'a' + 10; - else - break; - if ((int)wc >= base) - break; - if (res > cutoff || (res == cutoff && wc > cutlim)) - overflow = 1; - else - { - res *= (ulong) base; - res += wc; - } - } - else if (cnv==MY_CS_ILSEQ) - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0]=EILSEQ; - return 0; - } - else - { - /* No more characters */ - break; - } - } while(1); - - if (endptr != NULL) - *endptr = (char *) s; - - if (s == save) - { - err[0]=EDOM; - return 0L; - } - - if (overflow) - { - err[0]=(ERANGE); - return ((ulong)~0L); - } - - return (negative ? -((long) res) : (long) res); - -} - - - -longlong my_strntoll_ucs2(CHARSET_INFO *cs, - const char *nptr, uint l, int base, - char **endptr, int *err) -{ - int negative=0; - int overflow; - int cnv; - my_wc_t wc; - register ulonglong cutoff; - register unsigned int cutlim; - register ulonglong res; - register const uchar *s= (const uchar*) nptr; - register const uchar *e= (const uchar*) nptr+l; - const uchar *save; - - *err= 0; - do - { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - switch (wc) - { - case ' ' : break; - case '\t': break; - case '-' : negative= !negative; break; - case '+' : break; - default : goto bs; - } - } - else /* No more characters or bad multibyte sequence */ - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; - return 0; - } - s+=cnv; - } while (1); - -bs: - -#ifdef NOT_USED - if (base <= 0 || base == 1 || base > 36) - base = 10; -#endif - - overflow = 0; - res = 0; - save = s; - cutoff = (~(ulonglong) 0) / (unsigned long int) base; - cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base); - - do { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - s+=cnv; - if ( wc>='0' && wc<='9') - wc -= '0'; - else if ( wc>='A' && wc<='Z') - wc = wc - 'A' + 10; - else if ( wc>='a' && wc<='z') - wc = wc - 'a' + 10; - else - break; - if ((int)wc >= base) - break; - if (res > cutoff || (res == cutoff && wc > cutlim)) - overflow = 1; - else - { - res *= (ulonglong) base; - res += wc; - } - } - else if (cnv==MY_CS_ILSEQ) - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0]=EILSEQ; - return 0; - } - else - { - /* No more characters */ - break; - } - } while(1); - - if (endptr != NULL) - *endptr = (char *) s; - - if (s == save) - { - err[0]=EDOM; - return 0L; - } - - if (negative) - { - if (res > (ulonglong) LONGLONG_MIN) - overflow = 1; - } - else if (res > (ulonglong) LONGLONG_MAX) - overflow = 1; - - if (overflow) - { - err[0]=ERANGE; - return negative ? LONGLONG_MIN : LONGLONG_MAX; - } - - return (negative ? -((longlong)res) : (longlong)res); -} - - - - -ulonglong my_strntoull_ucs2(CHARSET_INFO *cs, - const char *nptr, uint l, int base, - char **endptr, int *err) -{ - int negative=0; - int overflow; - int cnv; - my_wc_t wc; - register ulonglong cutoff; - register unsigned int cutlim; - register ulonglong res; - register const uchar *s= (const uchar*) nptr; - register const uchar *e= (const uchar*) nptr+l; - const uchar *save; - - *err= 0; - do - { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - switch (wc) - { - case ' ' : break; - case '\t': break; - case '-' : negative= !negative; break; - case '+' : break; - default : goto bs; - } - } - else /* No more characters or bad multibyte sequence */ - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0]= (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM; - return 0; - } - s+=cnv; - } while (1); - -bs: - -#ifdef NOT_USED - if (base <= 0 || base == 1 || base > 36) - base = 10; -#endif - - overflow = 0; - res = 0; - save = s; - cutoff = (~(ulonglong) 0) / (unsigned long int) base; - cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base); - - do - { - if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) - { - s+=cnv; - if ( wc>='0' && wc<='9') - wc -= '0'; - else if ( wc>='A' && wc<='Z') - wc = wc - 'A' + 10; - else if ( wc>='a' && wc<='z') - wc = wc - 'a' + 10; - else - break; - if ((int)wc >= base) - break; - if (res > cutoff || (res == cutoff && wc > cutlim)) - overflow = 1; - else - { - res *= (ulonglong) base; - res += wc; - } - } - else if (cnv==MY_CS_ILSEQ) - { - if (endptr !=NULL ) - *endptr = (char*)s; - err[0]= EILSEQ; - return 0; - } - else - { - /* No more characters */ - break; - } - } while(1); - - if (endptr != NULL) - *endptr = (char *) s; - - if (s == save) - { - err[0]= EDOM; - return 0L; - } - - if (overflow) - { - err[0]= ERANGE; - return (~(ulonglong) 0); - } - - return (negative ? -((longlong) res) : (longlong) res); -} - - -double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), - char *nptr, uint length, - char **endptr, int *err) -{ - char buf[256]; - double res; - register char *b=buf; - register const uchar *s= (const uchar*) nptr; - register const uchar *end; - my_wc_t wc; - int cnv; - - *err= 0; - /* Cut too long strings */ - if (length >= sizeof(buf)) - length= sizeof(buf)-1; - end= s+length; - - while ((cnv=cs->mb_wc(cs,&wc,s,end)) > 0) - { - s+=cnv; - if (wc > (int) (uchar) 'e' || !wc) - break; /* Can't be part of double */ - *b++=wc; - } - *b= 0; - - errno= 0; - res=strtod(buf, endptr); - *err= errno; - if (endptr) - *endptr=(char*) (*endptr-buf+nptr); - return res; -} - - -/* - This is a fast version optimized for the case of radix 10 / -10 -*/ - -int my_l10tostr_ucs2(CHARSET_INFO *cs, - char *dst, uint len, int radix, long int val) -{ - char buffer[66]; - register char *p, *db, *de; - long int new_val; - int sl=0; - - p = &buffer[sizeof(buffer)-1]; - *p='\0'; - - if (radix < 0) - { - if (val < 0) - { - sl = 1; - val = -val; - } - } - - new_val = (long) ((unsigned long int) val / 10); - *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); - val = new_val; - - while (val != 0) - { - new_val=val/10; - *--p = '0' + (char) (val-new_val*10); - val= new_val; - } - - if (sl) - { - *--p='-'; - } - - for ( db=dst, de=dst+len ; (dst<de) && *p ; p++) - { - int cnvres=cs->wc_mb(cs,(my_wc_t)p[0],(uchar*) dst, (uchar*) de); - if (cnvres>0) - dst+=cnvres; - else - break; - } - return (int) (dst-db); -} - -int my_ll10tostr_ucs2(CHARSET_INFO *cs __attribute__((unused)), - char *dst, uint len, int radix, longlong val) -{ - char buffer[65]; - register char *p, *db, *de; - long long_val; - int sl=0; - - if (radix < 0) - { - if (val < 0) - { - sl=1; - val = -val; - } - } - - p = &buffer[sizeof(buffer)-1]; - *p='\0'; - - if (val == 0) - { - *--p='0'; - goto cnv; - } - - while ((ulonglong) val > (ulonglong) LONG_MAX) - { - ulonglong quo=(ulonglong) val/(uint) 10; - uint rem= (uint) (val- quo* (uint) 10); - *--p = '0' + rem; - val= quo; - } - - long_val= (long) val; - while (long_val != 0) - { - long quo= long_val/10; - *--p = '0' + (long_val - quo*10); - long_val= quo; - } - -cnv: - if (sl) - { - *--p='-'; - } - - for ( db=dst, de=dst+len ; (dst<de) && *p ; p++) - { - int cnvres=cs->wc_mb(cs, (my_wc_t) p[0], (uchar*) dst, (uchar*) de); - if (cnvres>0) - dst+=cnvres; - else - break; - } - return (int) (dst-db); -} - -static -uint my_numchars_ucs2(CHARSET_INFO *cs __attribute__((unused)), - const char *b, const char *e) -{ - return (e-b)/2; -} - -static -uint my_charpos_ucs2(CHARSET_INFO *cs __attribute__((unused)), - const char *b __attribute__((unused)), - const char *e __attribute__((unused)), - uint pos) -{ - return pos*2; -} - -CHARSET_INFO my_charset_ucs2 = -{ - 35,0,0, /* number */ - MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ - "ucs2", /* cs name */ - "ucs2_general_ci", /* name */ - "", /* comment */ - ctype_ucs2, /* ctype */ - to_lower_ucs2, /* to_lower */ - to_upper_ucs2, /* to_upper */ - to_upper_ucs2, /* sort_order */ - NULL, /* tab_to_uni */ - NULL, /* tab_from_uni */ - "","", - 1, /* strxfrm_multiply */ - my_strnncoll_ucs2, /* strnncoll */ - my_strnncoll_ucs2, - my_strnxfrm_ucs2, /* strnxfrm */ - my_like_range_simple,/* like_range */ - my_wildcmp_mb, /* wildcmp */ - 2, /* mbmaxlen */ - my_ismbchar_ucs2, /* ismbchar */ - my_mbcharlen_ucs2, /* mbcharlen */ - my_numchars_ucs2, - my_charpos_ucs2, - my_ucs2_uni, /* mb_wc */ - my_uni_ucs2, /* wc_mb */ - my_caseup_str_ucs2, - my_casedn_str_ucs2, - my_caseup_ucs2, - my_casedn_ucs2, - my_strcasecmp_ucs2, - my_hash_sort_ucs2, /* hash_sort */ - 0, - my_snprintf_ucs2, - my_l10tostr_ucs2, - my_ll10tostr_ucs2, - my_fill_8bit, - my_strntol_ucs2, - my_strntoul_ucs2, - my_strntoll_ucs2, - my_strntoull_ucs2, - my_strntod_ucs2, - my_scan_8bit -}; - - -#endif diff --git a/strings/ctype-win1250ch.c b/strings/ctype-win1250ch.c index 2769925b54f..12a8edc4a8f 100644 --- a/strings/ctype-win1250ch.c +++ b/strings/ctype-win1250ch.c @@ -45,6 +45,16 @@ #include "m_string.h" #include "m_ctype.h" +#else + +#include <stdio.h> +#define uchar unsigned char + +#endif + +#ifdef HAVE_CHARSET_cp1250 + + static uint16 tab_cp1250_uni[256]={ 0,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, @@ -250,12 +260,6 @@ static uchar NEAR to_upper_win1250ch[] = { 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xff }; -#else - -#include <stdio.h> -#define uchar unsigned char - -#endif static uchar NEAR sort_order_win1250ch[] = { @@ -286,7 +290,7 @@ static uchar NEAR _sort_order_win1250ch1[] = { 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, /* 0 ord 48 0x30 */ -0x92, 0x93, 0x94, 0x95, 0x95, 0x97, 0x98, 0x99, +0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, /* colon ord 58 0x3a */ 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, @@ -640,7 +644,18 @@ static my_bool my_like_range_win1250ch(CHARSET_INFO *cs __attribute__((unused)), } -CHARSET_INFO my_charset_win1250ch = +static MY_COLLATION_HANDLER my_collation_czech_ci_handler = +{ + my_strnncoll_win1250ch, + my_strnncollsp_win1250ch, + my_strnxfrm_win1250ch, + my_like_range_win1250ch, + my_wildcmp_8bit, + my_strcasecmp_8bit, + my_hash_sort_simple +}; + +CHARSET_INFO my_charset_cp1250_czech_ci = { 34,0,0, /* number */ MY_CS_COMPILED|MY_CS_STRNXFRM, /* state */ @@ -655,36 +670,13 @@ CHARSET_INFO my_charset_win1250ch = idx_uni_cp1250, /* tab_from_uni */ "","", 2, /* strxfrm_multiply */ - my_strnncoll_win1250ch, - my_strnncollsp_win1250ch, - my_strnxfrm_win1250ch, - my_like_range_win1250ch, - my_wildcmp_8bit, /* wildcmp */ 1, /* mbmaxlen */ - NULL, /* ismbchar */ - NULL, /* mbcharlen */ - my_numchars_8bit, - my_charpos_8bit, - my_mb_wc_8bit, /* mb_wc */ - my_wc_mb_8bit, /* wc_mb */ - my_caseup_str_8bit, - my_casedn_str_8bit, - my_caseup_8bit, - my_casedn_8bit, - my_strcasecmp_8bit, - my_hash_sort_simple, 0, - my_snprintf_8bit, - my_long10_to_str_8bit, - my_longlong10_to_str_8bit, - my_fill_8bit, - my_strntol_8bit, - my_strntoul_8bit, - my_strntoll_8bit, - my_strntoull_8bit, - my_strntod_8bit, - my_scan_8bit + &my_charset_8bit_handler, + &my_collation_czech_ci_handler }; #endif + +#endif diff --git a/strings/ctype.c b/strings/ctype.c index 68d9a30048f..ce7bb9ca4a4 100644 --- a/strings/ctype.c +++ b/strings/ctype.c @@ -220,6 +220,8 @@ static int cs_value(MY_XML_PARSER *st,const char *attr, uint len) i->cs.state|= MY_CS_PRIMARY; else if (!strncmp("binary",attr,len)) i->cs.state|= MY_CS_BINSORT; + else if (!strncmp("compiled",attr,len)) + i->cs.state|= MY_CS_COMPILED; break; case _CS_UPPERMAP: fill_uchar(i->to_upper,MY_CS_TO_UPPER_TABLE_SIZE,attr,len); diff --git a/support-files/MacOSX/Makefile.am b/support-files/MacOSX/Makefile.am index d030ff39d84..b8047942190 100644 --- a/support-files/MacOSX/Makefile.am +++ b/support-files/MacOSX/Makefile.am @@ -34,7 +34,8 @@ CLEANFILES = Info.plist \ Description.plist \ StartupParameters.plist \ postinstall \ - preinstall + preinstall \ + ReadMe.txt SUFFIXES = .sh diff --git a/support-files/MacOSX/ReadMe.txt b/support-files/MacOSX/ReadMe.txt deleted file mode 100644 index a18c5f3aa41..00000000000 --- a/support-files/MacOSX/ReadMe.txt +++ /dev/null @@ -1,80 +0,0 @@ -Installation notes for MySQL on Mac OS X - -PLEASE READ! - -For more details about installing and running -MySQL on Mac OS X, also refer to the manual, -which is available online: - -http://www.mysql.com/doc/en/Mac_OS_X_installation.html - -NOTE: Before proceeding with the installation, please -make sure that no other MySQL server is running! - -Please shut down all running MySQL instances before -continuing by either using the MySQL Manager -Application (on Mac OS X Server) or via "mysqladmin -shutdown" on the command line. - -This MySQL package will be installed into -"/usr/local/mysql-<version>" and will also create a -symbolic link "/usr/local/mysql", pointing to the new -location. - -A previously existing /usr/local/mysql directory will -be renamed to /usr/local/mysql.bak before proceeding -with the installation. - -Additionally, it will install the mysql grant tables by -executing "mysql_install_db" after the installation. - -If you are running Mac OS X Server, you already have a -version MySQL installed. Make sure to read Apple's help -about installing MySQL (Run the "Help View" application, -select "Mac OS X Server help", and do a search for MySQL -and read the item entitled "Installing MySQL"). - -If you previously used Marc Liyanage's MySQL packages -for MacOS X from http://www.entropy.ch, you can simply -follow the update instructions given on his pages. - -After the installation (and restoring the old database -files, if necessary), you can start up MySQL by running -the following commands in a terminal window: - - cd /usr/local/mysql - sudo ./bin/mysqld_safe - (Enter your password) - (Press CTRL+Z) - bg - (Press CTRL+D to exit the shell) - -You should now be able to connect to the MySQL server, -e.g. by running /usr/local/mysql/bin/mysql - -If you installed MySQL for the first time, -PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER! -This is done with the following two commands: - -/usr/local/mysql/bin/mysqladmin -u root password 'new-password' - -/usr/local/mysql/bin/mysqladmin -u root -h $hostname password 'new-password' - -Please note, that after upgrading from MySQL 3.23 to -MySQL 4.0 it is recommended to convert the MySQL -privilege tables using the mysql_fix_privilege_tables -script, since some new security privileges have been -added. - -Please see -http://www.mysql.com/doc/en/Upgrading-from-3.23.html -for more information on how to upgrade from MySQL 3.23. - -If you do not want to have to type the full path -"/usr/local/mysql/bin" in front of every command, you -can to add this directory to your PATH environment -variable in your login script. For the default shell -"tcsh", you can do this by running this command once: - -echo 'setenv PATH $PATH:/usr/local/mysql/bin' >> ~/.tcshrc - diff --git a/support-files/MacOSX/postinstall.sh b/support-files/MacOSX/postinstall.sh index daaf10bda8f..f46f4480e3e 100644 --- a/support-files/MacOSX/postinstall.sh +++ b/support-files/MacOSX/postinstall.sh @@ -10,7 +10,7 @@ if cd @prefix@ ; then if [ ! -f data/mysql/db.frm ] ; then - ./scripts/mysql_install_db + ./scripts/mysql_install_db -IN-RPM fi if [ -d data ] ; then diff --git a/support-files/Makefile.am b/support-files/Makefile.am index ec88972c821..58808b5e255 100644 --- a/support-files/Makefile.am +++ b/support-files/Makefile.am @@ -25,7 +25,8 @@ EXTRA_DIST = mysql.spec.sh \ mysql-log-rotate.sh \ mysql.server.sh \ binary-configure.sh \ - magic + magic \ + MySQL-shared-compat.spec.sh SUBDIRS = MacOSX @@ -34,7 +35,7 @@ pkgdata_DATA = my-small.cnf \ my-large.cnf \ my-huge.cnf \ mysql-log-rotate \ - mysql-@VERSION@.spec + MySQL-shared-compat.spec pkgdata_SCRIPTS = mysql.server @@ -46,7 +47,8 @@ CLEANFILES = my-small.cnf \ mysql-@VERSION@.spec \ mysql-log-rotate \ mysql.server \ - binary-configure + binary-configure \ + MySQL-shared-compat.spec mysql-@VERSION@.spec: mysql.spec rm -f $@ diff --git a/support-files/MySQL-shared-compat.spec.sh b/support-files/MySQL-shared-compat.spec.sh new file mode 100644 index 00000000000..f569dc20f42 --- /dev/null +++ b/support-files/MySQL-shared-compat.spec.sh @@ -0,0 +1,72 @@ +# +# MySQL-shared-compat.spec +# +# RPM build instructions to create a "meta" package that includes two +# versions of the MySQL shared libraries (for compatibility with +# distributions that ship older versions of MySQL and do not provide a +# separate "MySQL-shared" package. This spec file simply repackages two +# already existing MySQL-shared RPMs into a single package. +# +# Copyright (C) 2003 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; either version 2 of the License, or (at your option) +# any later version. +# +# 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 + +# +# Change this to match the version of the shared libs you want to include +# +%define version4 @VERSION@ +%define version3 3.23.56 + +Name: MySQL-shared-compat +Packager: Lenz Grimmer <build@mysql.com> +Vendor: MySQL AB +License: GPL +Group: Applications/Databases +URL: http://www.mysql.com/ +Autoreqprov: on +Version: %{version4} +Release: 0 +BuildRoot: %{_tmppath}/%{name}-%{version}-build +Obsoletes: MySQL-shared, mysql-shared +Provides: MySQL-shared +Summary: MySQL shared libraries for MySQL %{version4} and %{version3} +Source0: MySQL-shared-%{version4}-0.i386.rpm +Source1: MySQL-shared-%{version3}-1.i386.rpm +# No need to include the RPMs once more - they can be downloaded seperately +# if you want to rebuild this package +NoSource: 0 +NoSource: 1 +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%description +This package includes the shared libraries for both MySQL %{version3} and +MySQL %{version4}. Install this package instead of "MySQL-shared", if you +have applications installed that are dynamically linked against MySQL +3.23.xx but you want to upgrade to MySQL 4.0.xx without breaking the library +dependencies. + +%install +[ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT; +mkdir -p $RPM_BUILD_ROOT +cd $RPM_BUILD_ROOT +rpm2cpio %{SOURCE0} | cpio -iv --make-directories +rpm2cpio %{SOURCE1} | cpio -iv --make-directories + +%clean +[ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT; + +%files +%defattr(-, root, root) +/usr/lib/libmysqlclient* diff --git a/support-files/my-huge.cnf.sh b/support-files/my-huge.cnf.sh index 50a14b0fc96..18e926b1400 100644 --- a/support-files/my-huge.cnf.sh +++ b/support-files/my-huge.cnf.sh @@ -26,40 +26,96 @@ socket = @MYSQL_UNIX_ADDR@ port = @MYSQL_TCP_PORT@ socket = @MYSQL_UNIX_ADDR@ skip-locking -set-variable = key_buffer=384M -set-variable = max_allowed_packet=1M -set-variable = table_cache=512 -set-variable = sort_buffer=2M -set-variable = record_buffer=2M -set-variable = thread_cache=8 +key_buffer = 384M +max_allowed_packet = 1M +table_cache = 512 +sort_buffer_size = 2M +read_buffer_size = 2M +myisam_sort_buffer_size = 64M +thread_cache = 8 +query_cache_size = 32M # Try number of CPU's*2 for thread_concurrency -set-variable = thread_concurrency=8 -set-variable = myisam_sort_buffer_size=64M +thread_concurrency = 8 + +# Don't listen on a TCP/IP port at all. This can be a security enhancement, +# if all processes that need to connect to mysqld run on the same host. +# All interaction with mysqld must be made via Unix sockets or named pipes. +# Note that using this option without enabling named pipes on Windows +# (via the "enable-named-pipe" option) will render mysqld useless! +# +#skip-networking # Replication Master Server (default) -log-bin # required for replication -server-id = 1 # required unique id between 1 and 2^32 - 1 - # defaults to 1 if master-host is not set - # but will not function as a master if omitted +# binary logging is required for replication +log-bin + +# required unique id between 1 and 2^32 - 1 +# defaults to 1 if master-host is not set +# but will not function as a master if omitted +server-id = 1 -# Replication Slave Server (comment out master section to use this) -#master-host = # MUST BE SET -#master-user = # MUST BE SET -#master-password = # MUST BE SET -#master-port = # optional--defaults to 3306 -#log-bin # not required for slaves, but recommended -#server-id = 2 # required unique id between 2 and 2^32 - 1 - # (and different from the master) - # defaults to 2 if master-host is set - # but will not function as a slave if omitted +# Replication Slave (comment out master section to use this) +# +# To configure this host as a replication slave, you can choose between +# two methods : +# +# 1) Use the CHANGE MASTER TO command (fully described in our manual) - +# the syntax is: +# +# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, +# MASTER_USER=<user>, MASTER_PASSWORD=<password> ; +# +# where you replace <host>, <user>, <password> by quoted strings and +# <port> by the master's port number (3306 by default). +# +# Example: +# +# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, +# MASTER_USER='joe', MASTER_PASSWORD='secret'; +# +# OR +# +# 2) Set the variables below. However, in case you choose this method, then +# start replication for the first time (even unsuccessfully, for example +# if you mistyped the password in master-password and the slave fails to +# connect), the slave will create a master.info file, and any later +# change in this file to the variables' values below will be ignored and +# overridden by the content of the master.info file, unless you shutdown +# the slave server, delete master.info and restart the slaver server. +# For that reason, you may want to leave the lines below untouched +# (commented) and instead use CHANGE MASTER TO (see above) +# +# required unique id between 2 and 2^32 - 1 +# (and different from the master) +# defaults to 2 if master-host is set +# but will not function as a slave if omitted +#server-id = 2 +# +# The replication master for this slave - required +#master-host = <hostname> +# +# The username the slave will use for authentication when connecting +# to the master - required +#master-user = <username> +# +# The password the slave will authenticate with when connecting to +# the master - required +#master-password = <password> +# +# The port the master is listening on. +# optional - defaults to 3306 +#master-port = <port> +# +# binary logging - not required for slaves, but recommended +#log-bin # Point the following paths to different dedicated disks #tmpdir = /tmp/ #log-update = /path-to-dedicated-directory/hostname # Uncomment the following if you are using BDB tables -#set-variable = bdb_cache_size=384M -#set-variable = bdb_max_lock=100000 +#bdb_cache_size = 384M +#bdb_max_lock = 100000 # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = @localstatedir@/ @@ -68,17 +124,17 @@ server-id = 1 # required unique id between 1 and 2^32 - 1 #innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high -#set-variable = innodb_buffer_pool_size=384M -#set-variable = innodb_additional_mem_pool_size=20M +#innodb_buffer_pool_size = 384M +#innodb_additional_mem_pool_size = 20M # Set .._log_file_size to 25 % of buffer pool size -#set-variable = innodb_log_file_size=100M -#set-variable = innodb_log_buffer_size=8M -#innodb_flush_log_at_trx_commit=1 -#set-variable = innodb_lock_wait_timeout=50 +#innodb_log_file_size = 100M +#innodb_log_buffer_size = 8M +#innodb_flush_log_at_trx_commit = 1 +#innodb_lock_wait_timeout = 50 [mysqldump] quick -set-variable = max_allowed_packet=16M +max_allowed_packet = 16M [mysql] no-auto-rehash @@ -86,16 +142,16 @@ no-auto-rehash #safe-updates [isamchk] -set-variable = key_buffer=256M -set-variable = sort_buffer=256M -set-variable = read_buffer=2M -set-variable = write_buffer=2M +key_buffer = 256M +sort_buffer_size = 256M +read_buffer = 2M +write_buffer = 2M [myisamchk] -set-variable = key_buffer=256M -set-variable = sort_buffer=256M -set-variable = read_buffer=2M -set-variable = write_buffer=2M +key_buffer = 256M +sort_buffer_size = 256M +read_buffer = 2M +write_buffer = 2M [mysqlhotcopy] interactive-timeout diff --git a/support-files/my-large.cnf.sh b/support-files/my-large.cnf.sh index 3c388d611d8..2b92dc61053 100644 --- a/support-files/my-large.cnf.sh +++ b/support-files/my-large.cnf.sh @@ -26,21 +26,96 @@ socket = @MYSQL_UNIX_ADDR@ port = @MYSQL_TCP_PORT@ socket = @MYSQL_UNIX_ADDR@ skip-locking -set-variable = key_buffer=256M -set-variable = max_allowed_packet=1M -set-variable = table_cache=256 -set-variable = sort_buffer=1M -set-variable = record_buffer=1M -set-variable = myisam_sort_buffer_size=64M -set-variable = thread_cache=8 +key_buffer = 256M +max_allowed_packet = 1M +table_cache = 256 +sort_buffer_size = 1M +read_buffer_size = 1M +myisam_sort_buffer_size = 64M +thread_cache = 8 +query_cache_size= 16M # Try number of CPU's*2 for thread_concurrency -set-variable = thread_concurrency=8 +thread_concurrency = 8 + +# Don't listen on a TCP/IP port at all. This can be a security enhancement, +# if all processes that need to connect to mysqld run on the same host. +# All interaction with mysqld must be made via Unix sockets or named pipes. +# Note that using this option without enabling named pipes on Windows +# (via the "enable-named-pipe" option) will render mysqld useless! +# +#skip-networking + +# Replication Master Server (default) +# binary logging is required for replication log-bin + +# required unique id between 1 and 2^32 - 1 +# defaults to 1 if master-host is not set +# but will not function as a master if omitted server-id = 1 +# Replication Slave (comment out master section to use this) +# +# To configure this host as a replication slave, you can choose between +# two methods : +# +# 1) Use the CHANGE MASTER TO command (fully described in our manual) - +# the syntax is: +# +# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, +# MASTER_USER=<user>, MASTER_PASSWORD=<password> ; +# +# where you replace <host>, <user>, <password> by quoted strings and +# <port> by the master's port number (3306 by default). +# +# Example: +# +# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, +# MASTER_USER='joe', MASTER_PASSWORD='secret'; +# +# OR +# +# 2) Set the variables below. However, in case you choose this method, then +# start replication for the first time (even unsuccessfully, for example +# if you mistyped the password in master-password and the slave fails to +# connect), the slave will create a master.info file, and any later +# change in this file to the variables' values below will be ignored and +# overridden by the content of the master.info file, unless you shutdown +# the slave server, delete master.info and restart the slaver server. +# For that reason, you may want to leave the lines below untouched +# (commented) and instead use CHANGE MASTER TO (see above) +# +# required unique id between 2 and 2^32 - 1 +# (and different from the master) +# defaults to 2 if master-host is set +# but will not function as a slave if omitted +#server-id = 2 +# +# The replication master for this slave - required +#master-host = <hostname> +# +# The username the slave will use for authentication when connecting +# to the master - required +#master-user = <username> +# +# The password the slave will authenticate with when connecting to +# the master - required +#master-password = <password> +# +# The port the master is listening on. +# optional - defaults to 3306 +#master-port = <port> +# +# binary logging - not required for slaves, but recommended +#log-bin + +# Point the following paths to different dedicated disks +#tmpdir = /tmp/ +#log-update = /path-to-dedicated-directory/hostname + # Uncomment the following if you are using BDB tables -#set-variable = bdb_cache_size=64M -#set-variable = bdb_max_lock=100000 +#bdb_cache_size = 64M +#bdb_max_lock = 100000 # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = @localstatedir@/ @@ -49,21 +124,17 @@ server-id = 1 #innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high -#set-variable = innodb_buffer_pool_size=256M -#set-variable = innodb_additional_mem_pool_size=20M +#innodb_buffer_pool_size = 256M +#innodb_additional_mem_pool_size = 20M # Set .._log_file_size to 25 % of buffer pool size -#set-variable = innodb_log_file_size=64M -#set-variable = innodb_log_buffer_size=8M -#innodb_flush_log_at_trx_commit=1 -#set-variable = innodb_lock_wait_timeout=50 - -# Point the following paths to different dedicated disks -#tmpdir = /tmp/ -#log-update = /path-to-dedicated-directory/hostname +#innodb_log_file_size = 64M +#innodb_log_buffer_size = 8M +#innodb_flush_log_at_trx_commit = 1 +#innodb_lock_wait_timeout = 50 [mysqldump] quick -set-variable = max_allowed_packet=16M +max_allowed_packet = 16M [mysql] no-auto-rehash @@ -71,16 +142,16 @@ no-auto-rehash #safe-updates [isamchk] -set-variable = key_buffer=128M -set-variable = sort_buffer=128M -set-variable = read_buffer=2M -set-variable = write_buffer=2M +key_buffer = 128M +sort_buffer_size = 128M +read_buffer = 2M +write_buffer = 2M [myisamchk] -set-variable = key_buffer=128M -set-variable = sort_buffer=128M -set-variable = read_buffer=2M -set-variable = write_buffer=2M +key_buffer = 128M +sort_buffer_size = 128M +read_buffer = 2M +write_buffer = 2M [mysqlhotcopy] interactive-timeout diff --git a/support-files/my-medium.cnf.sh b/support-files/my-medium.cnf.sh index a92494358cb..601ffc503c0 100644 --- a/support-files/my-medium.cnf.sh +++ b/support-files/my-medium.cnf.sh @@ -27,22 +27,92 @@ socket = @MYSQL_UNIX_ADDR@ port = @MYSQL_TCP_PORT@ socket = @MYSQL_UNIX_ADDR@ skip-locking -set-variable = key_buffer=16M -set-variable = max_allowed_packet=1M -set-variable = table_cache=64 -set-variable = sort_buffer=512K -set-variable = net_buffer_length=8K -set-variable = myisam_sort_buffer_size=8M +key_buffer = 16M +max_allowed_packet = 1M +table_cache = 64 +sort_buffer_size = 512K +net_buffer_length = 8K +myisam_sort_buffer_size = 8M + +# Don't listen on a TCP/IP port at all. This can be a security enhancement, +# if all processes that need to connect to mysqld run on the same host. +# All interaction with mysqld must be made via Unix sockets or named pipes. +# Note that using this option without enabling named pipes on Windows +# (via the "enable-named-pipe" option) will render mysqld useless! +# +#skip-networking + +# Replication Master Server (default) +# binary logging is required for replication log-bin + +# required unique id between 1 and 2^32 - 1 +# defaults to 1 if master-host is not set +# but will not function as a master if omitted server-id = 1 +# Replication Slave (comment out master section to use this) +# +# To configure this host as a replication slave, you can choose between +# two methods : +# +# 1) Use the CHANGE MASTER TO command (fully described in our manual) - +# the syntax is: +# +# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, +# MASTER_USER=<user>, MASTER_PASSWORD=<password> ; +# +# where you replace <host>, <user>, <password> by quoted strings and +# <port> by the master's port number (3306 by default). +# +# Example: +# +# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, +# MASTER_USER='joe', MASTER_PASSWORD='secret'; +# +# OR +# +# 2) Set the variables below. However, in case you choose this method, then +# start replication for the first time (even unsuccessfully, for example +# if you mistyped the password in master-password and the slave fails to +# connect), the slave will create a master.info file, and any later +# change in this file to the variables' values below will be ignored and +# overridden by the content of the master.info file, unless you shutdown +# the slave server, delete master.info and restart the slaver server. +# For that reason, you may want to leave the lines below untouched +# (commented) and instead use CHANGE MASTER TO (see above) +# +# required unique id between 2 and 2^32 - 1 +# (and different from the master) +# defaults to 2 if master-host is set +# but will not function as a slave if omitted +#server-id = 2 +# +# The replication master for this slave - required +#master-host = <hostname> +# +# The username the slave will use for authentication when connecting +# to the master - required +#master-user = <username> +# +# The password the slave will authenticate with when connecting to +# the master - required +#master-password = <password> +# +# The port the master is listening on. +# optional - defaults to 3306 +#master-port = <port> +# +# binary logging - not required for slaves, but recommended +#log-bin + # Point the following paths to different dedicated disks #tmpdir = /tmp/ #log-update = /path-to-dedicated-directory/hostname # Uncomment the following if you are using BDB tables -#set-variable = bdb_cache_size=4M -#set-variable = bdb_max_lock=10000 +#bdb_cache_size = 4M +#bdb_max_lock = 10000 # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = @localstatedir@/ @@ -51,17 +121,17 @@ server-id = 1 #innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high -#set-variable = innodb_buffer_pool_size=16M -#set-variable = innodb_additional_mem_pool_size=2M +#innodb_buffer_pool_size = 16M +#innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size -#set-variable = innodb_log_file_size=5M -#set-variable = innodb_log_buffer_size=8M -#innodb_flush_log_at_trx_commit=1 -#set-variable = innodb_lock_wait_timeout=50 +#innodb_log_file_size = 5M +#innodb_log_buffer_size = 8M +#innodb_flush_log_at_trx_commit = 1 +#innodb_lock_wait_timeout = 50 [mysqldump] quick -set-variable = max_allowed_packet=16M +max_allowed_packet = 16M [mysql] no-auto-rehash @@ -69,16 +139,16 @@ no-auto-rehash #safe-updates [isamchk] -set-variable = key_buffer=20M -set-variable = sort_buffer=20M -set-variable = read_buffer=2M -set-variable = write_buffer=2M +key_buffer = 20M +sort_buffer_size = 20M +read_buffer = 2M +write_buffer = 2M [myisamchk] -set-variable = key_buffer=20M -set-variable = sort_buffer=20M -set-variable = read_buffer=2M -set-variable = write_buffer=2M +key_buffer = 20M +sort_buffer_size = 20M +read_buffer = 2M +write_buffer = 2M [mysqlhotcopy] interactive-timeout diff --git a/support-files/my-small.cnf.sh b/support-files/my-small.cnf.sh index b8941184fe0..f9e30da78ac 100644 --- a/support-files/my-small.cnf.sh +++ b/support-files/my-small.cnf.sh @@ -27,12 +27,20 @@ socket = @MYSQL_UNIX_ADDR@ port = @MYSQL_TCP_PORT@ socket = @MYSQL_UNIX_ADDR@ skip-locking -set-variable = key_buffer=16K -set-variable = max_allowed_packet=1M -set-variable = thread_stack=64K -set-variable = table_cache=4 -set-variable = sort_buffer=64K -set-variable = net_buffer_length=2K +key_buffer = 16K +max_allowed_packet = 1M +table_cache = 4 +sort_buffer_size = 64K +net_buffer_length = 2K +thread_stack = 64K + +# Don't listen on a TCP/IP port at all. This can be a security enhancement, +# if all processes that need to connect to mysqld run on the same host. +# All interaction with mysqld must be made via Unix sockets or named pipes. +# Note that using this option without enabling named pipes on Windows +# (using the "enable-named-pipe" option) will render mysqld useless! +# +#skip-networking server-id = 1 # Uncomment the following if you want to log updates @@ -48,17 +56,17 @@ server-id = 1 #innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high -#set-variable = innodb_buffer_pool_size=16M -#set-variable = innodb_additional_mem_pool_size=2M +#innodb_buffer_pool_size = 16M +#innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size -#set-variable = innodb_log_file_size=5M -#set-variable = innodb_log_buffer_size=8M -#innodb_flush_log_at_trx_commit=1 -#set-variable = innodb_lock_wait_timeout=50 +#innodb_log_file_size = 5M +#innodb_log_buffer_size = 8M +#innodb_flush_log_at_trx_commit = 1 +#innodb_lock_wait_timeout = 50 [mysqldump] quick -set-variable = max_allowed_packet=16M +max_allowed_packet = 16M [mysql] no-auto-rehash @@ -66,12 +74,12 @@ no-auto-rehash #safe-updates [isamchk] -set-variable = key_buffer=8M -set-variable = sort_buffer=8M +key_buffer = 8M +sort_buffer_size = 8M [myisamchk] -set-variable = key_buffer=8M -set-variable = sort_buffer=8M +key_buffer = 8M +sort_buffer_size = 8M [mysqlhotcopy] interactive-timeout diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index 7340cff9cad..de01142beac 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -10,7 +10,7 @@ # started and shut down when the systems goes down. # Comments to support chkconfig on RedHat Linux -# chkconfig: 2345 90 90 +# chkconfig: 2345 90 20 # description: A very fast and reliable SQL database engine. # Comments to support LSB init script conventions @@ -18,8 +18,8 @@ # Provides: mysql # Required-Start: $local_fs $network $remote_fs # Required-Stop: $local_fs $network $remote_fs -# Default-Start: 3 5 -# Default-Stop: 3 5 +# Default-Start: 2 3 4 5 +# Default-Stop: 2 3 4 5 # Short-Description: start and stop MySQL # Description: MySQL is a very fast and reliable SQL database engine. ### END INIT INFO @@ -118,7 +118,18 @@ else test -z "$print_defaults" && print_defaults="my_print_defaults" fi -parse_arguments `$print_defaults mysqld mysql_server mysql.server` +# +# Test if someone changed datadir; In this case we should also read the +# default arguments from this directory +# + +extra_args="" +if test "$datadir" != "@localstatedir@" +then + extra_args="-e $datadir/my.cnf" +fi + +parse_arguments `$print_defaults $extra_args mysqld mysql_server mysql.server` # Safeguard (relative paths, core dumps..) cd $basedir diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index 42d9ef5391c..11e850206c3 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -16,7 +16,7 @@ Copyright: GPL Source: http://www.mysql.com/Downloads/MySQL-@MYSQL_BASE_VERSION@/mysql-%{mysql_version}.tar.gz Icon: mysql.gif URL: http://www.mysql.com/ -Packager: Lenz Grimmer <lenz@mysql.com> +Packager: Lenz Grimmer <build@mysql.com> Vendor: MySQL AB Requires: fileutils sh-utils Provides: msqlormysql MySQL-server mysql @@ -154,7 +154,7 @@ Requires: MySQL >= 4.0 %description Max Optional MySQL server binary that supports additional features like -Berkeley DB, OpenSSL, RAID and User Defined Functions (UDF). +Berkeley DB, OpenSSL, RAID and User Defined Functions (UDFs). To activate this binary, just install this package in addition to the standard MySQL package. @@ -536,6 +536,14 @@ fi %attr(644, root, root) /usr/lib/mysql/libmysqld.a %changelog +* Fri May 16 2003 Lenz Grimmer <lenz@mysql.com> + +- re-enabled RAID again + +* Wed Apr 30 2003 Lenz Grimmer <lenz@mysql.com> + +- disabled MyISAM RAID (--with-raid) - it throws an assertion which + needs to be investigated first. * Mon Mar 10 2003 Lenz Grimmer <lenz@mysql.com> diff --git a/tests/big_record.pl b/tests/big_record.pl index 08547b50823..fbe94e3540f 100755 --- a/tests/big_record.pl +++ b/tests/big_record.pl @@ -11,12 +11,13 @@ use Getopt::Long; $opt_host=""; $opt_user=$opt_password=""; $opt_db="test"; -$opt_rows=200; # Test of blobs up to ($rows-1)*100000+1 bytes +$opt_rows=20; # Test of blobs up to ($rows-1)*100000+1 bytes $opt_compress=0; $opt_table="test_big_record"; +$opt_loop_count=100000; # Change this to make test harder/easier GetOptions("host=s","db=s","user=s", "password=s", "table=s", "rows=i", - "compress") || die "Aborted"; + "compress", "loop-count=i") || die "Aborted"; print "Connection to database $test_db\n"; @@ -42,12 +43,12 @@ $|=1; # Flush output to stdout to be able to monitor process for ($i=0 ; $i < $opt_rows ; $i++) { $tmp= chr(65+($i % 16)) x ($i*100000+1); - print $i," ",length($tmp),"\n"; $tmp= $dbh->quote($tmp); $dbh->do("insert into $opt_table (test) values ($tmp)") or die $DBI::errstr; + print "."; } -print "Reading records\n"; +print "\nReading records\n"; $sth=$dbh->prepare("select * from $opt_table", { "mysql_use_result" => 1}) or die $dbh->errstr; @@ -56,14 +57,40 @@ $sth->execute() or die $sth->errstr; $i=0; while (($row = $sth->fetchrow_arrayref)) { - print $row->[0]," ",length($row->[1]),"\n"; die "Record $i had wrong data in blob" if ($row->[1] ne (chr(65+($i % 16)) x ($i*100000+1))); $i++; } die "Didn't get all rows from server" if ($i != $opt_rows); -$dbh->do("drop table $opt_table") or die $DBI::errstr; +# +# Test by insert/updating/deleting random rows for a while +# -print "Test ok\n"; +print "Testing insert/update/delete\n"; + +$max_row_id= $rows; +for ($i= 0 ; $i < $opt_loop_count ; $i++) +{ + $length= int(rand 65535); + $tmp= chr(65+($i % 16)) x $length; + $tmp= $dbh->quote($tmp); + $dbh->do("insert into $opt_table (test) values ($tmp)") or die $DBI::errstr; + $max_row_id++; + $length=int(rand 65535); + $tmp= chr(65+($i % 16)) x $length; + $tmp= $dbh->quote($tmp); + $id= int(rand $max_row_id); + $dbh->do("update $opt_table set test= $tmp where auto= $id") or die $DBI::errstr; + if (($i % 2) == 1) + { + $id= int(rand $max_row_id); + $dbh->do("delete from $opt_table where auto= $id") or die $DBI::errstr; + } + print "." if ($i % ($opt_loop_count/100) == 1); +} + +# $dbh->do("drop table $opt_table") or die $DBI::errstr; + +print "\nTest ok\n"; exit 0; diff --git a/tests/client_test.c b/tests/client_test.c index bd2ec4930ef..859c06ba243 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -72,10 +72,12 @@ static double total_time; static void print_error(const char *msg); static void print_st_error(MYSQL_STMT *stmt, const char *msg); +static void check_errcode(const unsigned int err); static void client_disconnect(); #define myerror(msg) print_error(msg) #define mysterror(stmt, msg) print_st_error(stmt, msg) +#define myerrno(n) check_errcode(n) #define myassert(exp) assert(exp) #define myassert_r(exp) assert(!(exp)) @@ -141,6 +143,16 @@ static void print_error(const char *msg) else if (msg) fprintf(stderr, " [MySQL] %s\n", msg); } +static void check_errcode(const unsigned int err) +{ + if (mysql->server_version) + fprintf(stdout,"\n [MySQL-%s]",mysql->server_version); + else + fprintf(stdout,"\n [MySQL]"); + fprintf(stdout,"[%d] %s\n",mysql_errno(mysql),mysql_error(mysql)); + myassert(mysql_errno(mysql) == err); +} + static void print_st_error(MYSQL_STMT *stmt, const char *msg) { if (stmt && mysql_stmt_errno(stmt)) @@ -368,6 +380,20 @@ int my_process_result_set(MYSQL_RES *result) return row_count; } +int my_process_result(MYSQL *mysql) +{ + MYSQL_RES *result; + int row_count; + + if (!(result = mysql_store_result(mysql))) + return 0; + + row_count= my_process_result_set(result); + + mysql_free_result(result); + return row_count; +} + /******************************************************** * process the stmt result set * *********************************************************/ @@ -2656,7 +2682,7 @@ static void test_bind_result_ext() /*myassert(f_data == 2345.60);*/ /*myassert(d_data == 5678.89563);*/ myassert(strcmp(szData,"venu")==0); - myassert(strcmp(bData,"mysql")==0); + myassert(strncmp(bData,"mysql",5)==0); myassert(szLength == 4); myassert(bLength == 5); @@ -4837,8 +4863,9 @@ static void test_store_result2() static void test_subselect() { #if TO_BE_FIXED_IN_SERVER + MYSQL_STMT *stmt; - int rc; + int rc, id; MYSQL_BIND bind[1]; myheader("test_subselect"); @@ -6078,6 +6105,7 @@ static void test_prepare_grant() rc = mysql_query(mysql,"delete from mysql.tables_priv where User='test_grant'"); myquery(rc); myassert(1 == mysql_affected_rows(mysql)); + } } @@ -6375,7 +6403,677 @@ static void test_explain_bug() mysql_stmt_close(stmt); } +/* + To test math functions + bug #148 (reported by salle@mysql.com). +*/ +static void test_drop_temp() +{ + int rc; + + myheader("test_drop_temp"); + + rc= mysql_query(mysql,"DROP DATABASE IF EXISTS test_drop_temp_db"); + myquery(rc); + + rc= mysql_query(mysql,"CREATE DATABASE test_drop_temp_db"); + myquery(rc); + + rc= mysql_query(mysql,"CREATE TABLE test_drop_temp_db.t1(c1 int, c2 char(1))"); + myquery(rc); + + rc = mysql_query(mysql,"delete from mysql.db where Db='test_drop_temp_db'"); + myquery(rc); + + rc = mysql_query(mysql,"delete from mysql.db where Db='test_drop_temp_db'"); + myquery(rc); + + strxmov(query,"GRANT SELECT,USAGE,DROP ON test_drop_temp_db.* TO test_temp@", + opt_host ? opt_host : "localhost", NullS); + + if (mysql_query(mysql,query)) + { + myerror("GRANT failed"); + + /* + If server started with --skip-grant-tables, skip this test, else + exit to indicate an error + + ER_UNKNOWN_COM_ERROR = 1047 + */ + if (mysql_errno(mysql) != 1047) + exit(0); + } + else + { + MYSQL *org_mysql= mysql, *lmysql; + + fprintf(stdout, "\n Establishing a test connection ..."); + if (!(lmysql = mysql_init(NULL))) + { + myerror("mysql_init() failed"); + exit(0); + } + + rc = mysql_query(mysql,"flush privileges"); + myquery(rc); + + if (!(mysql_real_connect(lmysql,opt_host ? opt_host : "localhost","test_temp", + "", "test_drop_temp_db", opt_port, + opt_unix_socket, 0))) + { + mysql= lmysql; + myerror("connection failed"); + mysql_close(lmysql); + exit(0); + } + fprintf(stdout," OK"); + + mysql= lmysql; + rc = mysql_query(mysql,"INSERT INTO t1 VALUES(10,'C')"); + myerrno((uint)1142); + + rc = mysql_query(mysql,"DROP TABLE t1"); + myerrno((uint)1142); + + mysql= org_mysql; + rc= mysql_query(mysql,"CREATE TEMPORARY TABLE test_drop_temp_db.t1(c1 int)"); + myquery(rc); + + rc= mysql_query(mysql,"CREATE TEMPORARY TABLE test_drop_temp_db.t2 LIKE test_drop_temp_db.t1"); + myquery(rc); + + mysql= lmysql; + + rc = mysql_query(mysql,"DROP TABLE t1,t2"); + myquery_r(rc); + + rc = mysql_query(mysql,"DROP TEMPORARY TABLE t1"); + myquery_r(rc); + + rc = mysql_query(mysql,"DROP TEMPORARY TABLE t2"); + myquery_r(rc); + + mysql_close(lmysql); + mysql= org_mysql; + + rc = mysql_query(mysql,"drop database test_drop_temp_db"); + myquery(rc); + myassert(1 == mysql_affected_rows(mysql)); + + rc = mysql_query(mysql,"delete from mysql.user where User='test_temp'"); + myquery(rc); + myassert(1 == mysql_affected_rows(mysql)); + + + rc = mysql_query(mysql,"delete from mysql.tables_priv where User='test_temp'"); + myquery(rc); + myassert(1 == mysql_affected_rows(mysql)); + } +} + +/* + To test warnings for cuted rows +*/ +static void test_cuted_rows() +{ + int rc, count; + MYSQL_RES *result; + + myheader("test_cuted_rows"); + + mysql_query(mysql, "DROP TABLE if exists t1"); + mysql_query(mysql, "DROP TABLE if exists t2"); + + rc = mysql_query(mysql, "CREATE TABLE t1(c1 tinyint)"); + myquery(rc); + + rc = mysql_query(mysql, "CREATE TABLE t2(c1 int not null)"); + myquery(rc); + + rc = mysql_query(mysql, "INSERT INTO t1 values(10),(NULL),(NULL)"); + myquery(rc); + + count= mysql_warning_count(mysql); + fprintf(stdout, "\n total warnings: %d", count); + myassert(count == 0); + + rc = mysql_query(mysql, "INSERT INTO t2 SELECT * FROM t1"); + myquery(rc); + + count= mysql_warning_count(mysql); + fprintf(stdout, "\n total warnings: %d", count); + myassert(count == 2); + + rc = mysql_query(mysql, "SHOW WARNINGS"); + myquery(rc); + + result = mysql_store_result(mysql); + mytest(result); + + myassert(2 == my_process_result_set(result)); + mysql_free_result(result); + + rc = mysql_query(mysql, "INSERT INTO t1 VALUES('junk'),(876789)"); + myquery(rc); + + count= mysql_warning_count(mysql); + fprintf(stdout, "\n total warnings: %d", count); + myassert(count == 2); + + rc = mysql_query(mysql, "SHOW WARNINGS"); + myquery(rc); + + result = mysql_store_result(mysql); + mytest(result); + + myassert(2 == my_process_result_set(result)); + mysql_free_result(result); +} + +/* + To test update/binary logs +*/ +static void test_logs() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + char data[255]; + ulong length; + int rc; + short id; + + myheader("test_logs"); + + + rc = mysql_real_query(mysql, "DROP TABLE IF EXISTS test_logs", 100); + myquery(rc); + + rc = mysql_real_query(mysql, "CREATE TABLE test_logs(id smallint, name varchar(20))", 100); + myquery(rc); + + length= (ulong)(strmov((char *)data,"INSERT INTO test_logs VALUES(?,?)") - data); + stmt = mysql_prepare(mysql, data, length); + mystmt_init(stmt); + + bind[0].buffer_type= MYSQL_TYPE_SHORT; + bind[0].buffer= (char *)&id; + bind[0].is_null= 0; + bind[0].length= 0; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)&data; + bind[1].is_null= 0; + bind[1].buffer_length= 255; + bind[1].length= &length; + + id= 9876; + length= (ulong)(strmov((char *)data,"MySQL - Open Source Database")- data); + + rc = mysql_bind_param(stmt, bind); + mystmt(stmt, rc); + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + strmov((char *)data, "'"); + length= 1; + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + strmov((char *)data, "\""); + length= 1; + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + length= (ulong)(strmov((char *)data, "my\'sql\'")-data); + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + length= (ulong)(strmov((char *)data, "my\"sql\"")-data); + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + mysql_stmt_close(stmt); + + length= (ulong)(strmov((char *)data,"INSERT INTO test_logs VALUES(20,'mysql')") - data); + stmt = mysql_prepare(mysql, data, length); + mystmt_init(stmt); + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + mysql_stmt_close(stmt); + + length= (ulong)(strmov((char *)data, "SELECT * FROM test_logs WHERE id=?") - data); + stmt = mysql_prepare(mysql, data, length+2); + mystmt_init(stmt); + + rc = mysql_bind_param(stmt, bind); + mystmt(stmt, rc); + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + bind[1].buffer_length= 255; + rc = mysql_bind_result(stmt, bind); + mystmt(stmt, rc); + + rc = mysql_fetch(stmt); + mystmt(stmt, rc); + + fprintf(stdout, "\n id : %d", id); + fprintf(stdout, "\n name : %s(%ld)", data, length); + + myassert(id == 9876); + myassert(length == 19);//Due to VARCHAR(20) + myassert(strcmp(data,"MySQL - Open Source")==0); + + rc = mysql_fetch(stmt); + mystmt(stmt, rc); + + fprintf(stdout, "\n name : %s(%ld)", data, length); + + myassert(length == 1); + myassert(strcmp(data,"'")==0); + + rc = mysql_fetch(stmt); + mystmt(stmt, rc); + + fprintf(stdout, "\n name : %s(%ld)", data, length); + + myassert(length == 1); + myassert(strcmp(data,"\"")==0); + + rc = mysql_fetch(stmt); + mystmt(stmt, rc); + + fprintf(stdout, "\n name : %s(%ld)", data, length); + + myassert(length == 7); + myassert(strcmp(data,"my\'sql\'")==0); + + rc = mysql_fetch(stmt); + mystmt(stmt, rc); + + fprintf(stdout, "\n name : %s(%ld)", data, length); + + myassert(length == 7); + myassert(strcmp(data,"my\"sql\"")==0); + + rc = mysql_fetch(stmt); + myassert(rc == MYSQL_NO_DATA); + + mysql_stmt_close(stmt); + + rc = mysql_query(mysql,"DROP TABLE test_logs"); + myquery(rc); +} + +/* + To test 'n' statements create and close +*/ + +static void test_nstmts() +{ + MYSQL_STMT *stmt; + char query[255]; + int rc; + static uint i, total_stmts= 2000; + long length; + MYSQL_BIND bind[1]; + + myheader("test_nstmts"); + + mysql_autocommit(mysql,TRUE); + + rc = mysql_query(mysql, "DROP TABLE IF EXISTS test_nstmts"); + myquery(rc); + + rc = mysql_query(mysql, "CREATE TABLE test_nstmts(id int)"); + myquery(rc); + + bind[0].buffer= (char *)&i; + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].length= 0; + bind[0].is_null= 0; + bind[0].buffer_length= 0; + + for (i=0; i < total_stmts; i++) + { + fprintf(stdout, "\r stmt: %d", i); + + length = (long)(strmov(query, "insert into test_nstmts values(?)")-query); + stmt = mysql_prepare(mysql, query, length); + mystmt_init(stmt); + + rc = mysql_bind_param(stmt, bind); + mystmt(stmt, rc); + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + mysql_stmt_close(stmt); + } + + stmt = mysql_prepare(mysql," select count(*) from test_nstmts", 50); + mystmt_init(stmt); + + rc = mysql_execute(stmt); + mystmt(stmt, rc); + + i = 0; + rc = mysql_bind_result(stmt, bind); + mystmt(stmt, rc); + + rc = mysql_fetch(stmt); + mystmt(stmt, rc); + fprintf(stdout, "\n total rows: %d", i); + myassert( i == total_stmts); + + rc = mysql_fetch(stmt); + myassert(rc == MYSQL_NO_DATA); + + mysql_stmt_close(stmt); + + rc = mysql_query(mysql,"DROP TABLE test_nstmts"); + myquery(rc); +} + +/* + To test stmt seek() functions +*/ +static void test_fetch_seek() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[3]; + MYSQL_ROW_OFFSET row; + int rc; + long c1; + char c2[11], c3[20]; + + myheader("test_fetch_seek"); + + rc= mysql_query(mysql,"drop table if exists test_seek"); + myquery(rc); + + rc = mysql_query(mysql, "create table test_seek(c1 int primary key auto_increment, c2 char(10), c3 timestamp(14))"); + myquery(rc); + + rc = mysql_query(mysql, "insert into test_seek(c2) values('venu'),('mysql'),('open'),('source')"); + myquery(rc); + + stmt = mysql_prepare(mysql,"select * from test_seek",50); + mystmt_init(stmt); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&c1; + bind[0].buffer_length= 0; + bind[0].is_null= 0; + bind[0].length= 0; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)c2; + bind[1].buffer_length= sizeof(c2); + bind[1].is_null= 0; + bind[1].length= 0; + + bind[2]= bind[1]; + bind[2].buffer= (char *)c3; + bind[2].buffer_length= sizeof(c3); + + rc = mysql_execute(stmt); + mystmt(stmt,rc); + + rc = mysql_bind_result(stmt, bind); + mystmt(stmt,rc); + + rc = mysql_stmt_store_result(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + fprintf(stdout, "\n row 0: %ld,%s,%s", c1,c2,c3); + + row = mysql_stmt_row_tell(stmt); + + row = mysql_stmt_row_seek(stmt, row); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + fprintf(stdout, "\n row 2: %ld,%s,%s", c1,c2,c3); + + row = mysql_stmt_row_seek(stmt, row); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + fprintf(stdout, "\n row 2: %ld,%s,%s", c1,c2,c3); + + mysql_stmt_data_seek(stmt, 0); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + fprintf(stdout, "\n row 0: %ld,%s,%s", c1,c2,c3); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + myassert(rc == MYSQL_NO_DATA); + + mysql_stmt_close(stmt); +} + +/* + To test mysql_fetch_column() with offset +*/ +static void test_fetch_offset() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + char data[11]; + ulong length; + int rc; + my_bool is_null; + + + myheader("test_fetch_offset"); + + rc= mysql_query(mysql,"drop table if exists test_column"); + myquery(rc); + + rc = mysql_query(mysql, "create table test_column(a char(10))"); + myquery(rc); + + rc = mysql_query(mysql, "insert into test_column values('abcdefghij'),(null)"); + myquery(rc); + + stmt = mysql_prepare(mysql,"select * from test_column",50); + mystmt_init(stmt); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= (char *)data; + bind[0].buffer_length= 11; + bind[0].is_null= &is_null; + bind[0].length= &length; + + rc = mysql_execute(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch_column(stmt,bind,0,0); + mystmt_r(stmt,rc); + + rc = mysql_stmt_store_result(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch_column(stmt,bind,4,0); + mystmt_r(stmt,rc); + + data[0]= '\0'; + rc = mysql_fetch_column(stmt,bind,0,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 1: %s (%ld)", data, length); + myassert(strncmp(data,"abcd",4) == 0 && length == 10); + + rc = mysql_fetch_column(stmt,bind,0,5); + mystmt(stmt,rc); + fprintf(stdout, "\n col 1: %s (%ld)", data, length); + myassert(strncmp(data,"fg",2) == 0 && length == 10); + + rc = mysql_fetch_column(stmt,bind,0,9); + mystmt(stmt,rc); + fprintf(stdout, "\n col 0: %s (%ld)", data, length); + myassert(strncmp(data,"j",1) == 0 && length == 10); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + is_null= 0; + + rc = mysql_fetch_column(stmt,bind,0,0); + mystmt(stmt,rc); + + myassert(is_null == 1); + + rc = mysql_fetch(stmt); + myassert(rc == MYSQL_NO_DATA); + + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt_r(stmt,rc); + + mysql_stmt_close(stmt); +} +/* + To test mysql_fetch_column() +*/ +static void test_fetch_column() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + char c2[20]; + ulong l1, l2; + int rc, c1; + + myheader("test_fetch_column"); + + rc= mysql_query(mysql,"drop table if exists test_column"); + myquery(rc); + + rc = mysql_query(mysql, "create table test_column(c1 int primary key auto_increment, c2 char(10))"); + myquery(rc); + + rc = mysql_query(mysql, "insert into test_column(c2) values('venu'),('mysql')"); + myquery(rc); + + stmt = mysql_prepare(mysql,"select * from test_column",50); + mystmt_init(stmt); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= (char *)c2; + bind[0].buffer_length= 7; + bind[0].is_null= 0; + bind[0].length= &l2; + + rc = mysql_execute(stmt); + mystmt(stmt,rc); + + rc = mysql_stmt_store_result(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt_r(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + c2[0]= '\0'; l2= 0; + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + myassert(strncmp(c2,"venu",4)==0 && l2 == 4); + + c2[0]= '\0'; l2= 0; + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + myassert(strcmp(c2,"venu")==0 && l2 == 4); + + c1= 0; + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&c1; + bind[0].buffer_length= 0; + bind[0].is_null= 0; + bind[0].length= &l1; + + rc = mysql_fetch_column(stmt,bind,0,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); + myassert(c1 == 1 && l1 == 4); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= (char *)c2; + bind[0].buffer_length= 7; + bind[0].is_null= 0; + bind[0].length= &l2; + + fprintf(stdout, "\n row 1: %d,%s", c1,c2); + + c2[0]= '\0'; l2= 0; + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + myassert(strncmp(c2,"mysq",4)==0 && l2 == 5); + + c2[0]= '\0'; l2= 0; + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 1: %si(%ld)", c2, l2); + myassert(strcmp(c2,"mysql")==0 && l2 == 5); + + c1= 0; + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&c1; + bind[0].buffer_length= 0; + bind[0].is_null= 0; + bind[0].length= &l1; + + rc = mysql_fetch_column(stmt,bind,0,0); + mystmt(stmt,rc); + fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); + myassert(c1 == 2 && l1 == 4); + + rc = mysql_fetch(stmt); + myassert(rc == MYSQL_NO_DATA); + + rc = mysql_fetch_column(stmt,bind,1,0); + mystmt_r(stmt,rc); + + mysql_stmt_close(stmt); +} /* Read and parse arguments and MySQL options from my.cnf @@ -6408,7 +7106,6 @@ static struct my_option client_test_long_options[] = { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; - static void client_test_print_version(void) { fprintf(stdout, "%s Distrib %s, for %s (%s)\n\n", @@ -6517,7 +7214,13 @@ int main(int argc, char **argv) start_time= time((time_t *)0); - test_fetch_nobuffs(); /* to fecth without prior bound buffers */ + client_query(); /* simple client query test */ + client_store_result(); /* usage of mysql_store_result() */ + client_use_result(); /* usage of mysql_use_result() */ +#if NOT_YET_WORKING + /* Used for internal new development debugging */ + test_drop_temp(); /* to test DROP TEMPORARY TABLE Access checks */ +#endif test_open_direct(); /* direct execution in the middle of open stmts */ test_fetch_null(); /* to fetch null data */ test_fetch_date(); /* to fetch date,time and timestamp */ @@ -6559,9 +7262,6 @@ int main(int argc, char **argv) test_simple_update(); /* simple prepare with update */ test_simple_delete(); /* prepare with delete */ test_double_compare(); /* float comparision */ - client_query(); /* simple client query test */ - client_store_result(); /* usage of mysql_store_result() */ - client_use_result(); /* usage of mysql_use_result() */ test_tran_bdb(); /* transaction test on BDB table type */ test_tran_innodb(); /* transaction test on InnoDB table type */ test_prepare_ext(); /* test prepare with all types conversion -- TODO */ @@ -6600,6 +7300,14 @@ int main(int argc, char **argv) test_frm_bug(); /* test the crash when .frm is invalid, bug #93 */ test_explain_bug(); /* test for the EXPLAIN, bug #115 */ test_decimal_bug(); /* test for the decimal bug */ + test_nstmts(); /* test n statements */ + test_logs(); ; /* to test logs */ + test_cuted_rows(); /* to test for WARNINGS from cuted rows */ + test_fetch_seek(); /* to test stmt seek() functions */ + test_fetch_nobuffs(); /* to fecth without prior bound buffers */ + test_open_direct(); /* direct execution in the middle of open stmts */ + test_fetch_offset(); /* to test mysql_fetch_column with offset */ + test_fetch_column(); /* to test mysql_fetch_column */ end_time= time((time_t *)0); total_time+= difftime(end_time, start_time); diff --git a/tests/grant.pl b/tests/grant.pl index 5a24127d79d..3146b7b6c25 100644 --- a/tests/grant.pl +++ b/tests/grant.pl @@ -63,6 +63,12 @@ user_connect(1); #goto test; # +# Enable column grant code +# +safe_query("grant select(user) on mysql.user to $user"); +safe_query("revoke select(user) on mysql.user from $user"); + +# # Test grants on user level # @@ -76,6 +82,7 @@ user_query("select * from mysql.user where user = '$opt_user'"); user_query("select * from mysql.db where user = '$opt_user'"); safe_query("grant select on *.* to $user,$user"); safe_query("show grants for $user"); +user_connect(0); # The following should fail user_query("insert into mysql.user (host,user) values ('error','$opt_user')",1); @@ -89,16 +96,21 @@ safe_query("grant select on $opt_database.not_exists to $opt_user",1); safe_query("grant FILE on $opt_database.test to $opt_user",1); safe_query("grant select on *.* to wrong___________user_name",1); safe_query("grant select on $opt_database.* to wrong___________user_name",1); +user_connect(0); user_query("grant select on $opt_database.test to $opt_user with grant option",1); safe_query("set password FOR ''\@''=''",1); user_query("set password FOR root\@$opt_host = password('test')",1); # Change privileges for user safe_query("revoke select on *.* from $user"); -safe_query("grant create on *.* to $user"); +safe_query("grant create,update on *.* to $user"); user_connect(0); +safe_query("flush privileges"); user_query("create table $opt_database.test (a int,b int)"); - +user_query("update $opt_database.test set b=b+1 where a > 0",1); +safe_query("show grants for $user"); +safe_query("revoke update on *.* from $user"); +user_connect(0); safe_query("grant select(c) on $opt_database.test to $user",1); safe_query("revoke select(c) on $opt_database.test from $user",1); safe_query("grant select on $opt_database.test to wrong___________user_name",1); @@ -217,8 +229,21 @@ user_query("update $opt_database.test set b=b+1",1); safe_query("grant SELECT on *.* to $user"); user_connect(0); user_query("update $opt_database.test set b=b+1"); +user_query("update $opt_database.test set b=b+1 where a > 0"); safe_query("revoke SELECT on *.* from $user"); +safe_query("grant SELECT on $opt_database.* to $user"); user_connect(0); +user_query("update $opt_database.test set b=b+1"); +user_query("update $opt_database.test set b=b+1 where a > 0"); +safe_query("grant UPDATE on *.* to $user"); +user_connect(0); +user_query("update $opt_database.test set b=b+1"); +user_query("update $opt_database.test set b=b+1 where a > 0"); +safe_query("revoke UPDATE on *.* from $user"); +safe_query("revoke SELECT on $opt_database.* from $user"); +user_connect(0); +user_query("update $opt_database.test set b=b+1 where a > 0",1); +user_query("update $opt_database.test set b=b+1",1); # Add one privilege at a time until the user has all privileges user_query("select * from test",1); @@ -408,21 +433,29 @@ safe_query("grant ALL PRIVILEGES on $opt_database.test to $user identified by 'd user_connect(0,"dummy"); safe_query("grant SELECT on $opt_database.* to $user identified by ''"); user_connect(0); -safe_query("revoke ALL PRIVILEGES on $opt_database.test from $user identified by ''"); +safe_query("revoke ALL PRIVILEGES on $opt_database.test from $user identified by '', ${opt_user}\@127.0.0.1 identified by 'dummy2'"); safe_query("revoke ALL PRIVILEGES on $opt_database.* from $user identified by ''"); + safe_query("show grants for $user"); # # Test bug reported in SELECT INTO OUTFILE # -safe_query("create table $opt_database.test3 (a int)"); +safe_query("create table $opt_database.test3 (a int, b int)"); safe_query("grant SELECT on $opt_database.test3 to $user"); safe_query("grant FILE on *.* to $user"); -safe_query("insert into $opt_database.test3 values (1)"); +safe_query("insert into $opt_database.test3 values (1,1)"); user_connect(0); user_query("select * into outfile '$tmp_table' from $opt_database.test3"); safe_query("revoke SELECT on $opt_database.test3 from $user"); +safe_query("grant SELECT(a) on $opt_database.test3 to $user"); +user_query("select a from $opt_database.test3"); +user_query("select * from $opt_database.test3",1); +user_query("select a,b from $opt_database.test3",1); +user_query("select b from $opt_database.test3",1); + +safe_query("revoke SELECT(a) on $opt_database.test3 from $user"); safe_query("revoke FILE on *.* from $user"); safe_query("drop table $opt_database.test3"); diff --git a/tests/grant.res b/tests/grant.res index adb4494eb28..7b244f099f8 100644 --- a/tests/grant.res +++ b/tests/grant.res @@ -10,6 +10,8 @@ Error in execute: Can't drop database 'grant_test'. Database doesn't exist create database grant_test Connecting grant_user Error on connect: Access denied for user: '@localhost' to database 'grant_test' +grant select(user) on mysql.user to grant_user@localhost +revoke select(user) on mysql.user from grant_user@localhost grant select on *.* to grant_user@localhost set password FOR grant_user2@localhost = password('test') Error in execute: Can't find any matching row in the user table @@ -26,6 +28,7 @@ grant select on *.* to grant_user@localhost,grant_user@localhost show grants for grant_user@localhost GRANT SELECT ON *.* TO 'grant_user'@'localhost' +Connecting grant_user insert into mysql.user (host,user) values ('error','grant_user') Error in execute: Access denied for user: 'grant_user@localhost' to database 'mysql' update mysql.user set host='error' WHERE user='grant_user' @@ -48,6 +51,7 @@ grant select on *.* to wrong___________user_name Error in execute: The host or user argument to GRANT is too long grant select on grant_test.* to wrong___________user_name Error in execute: The host or user argument to GRANT is too long +Connecting grant_user grant select on grant_test.test to grant_user with grant option Error in execute: grant command denied to user: 'grant_user@localhost' for table 'test' set password FOR ''@''='' @@ -55,9 +59,17 @@ Error in execute: Can't find any matching row in the user table set password FOR root@localhost = password('test') Error in execute: Access denied for user: 'grant_user@localhost' to database 'mysql' revoke select on *.* from grant_user@localhost -grant create on *.* to grant_user@localhost +grant create,update on *.* to grant_user@localhost Connecting grant_user +flush privileges create table grant_test.test (a int,b int) +update grant_test.test set b=b+1 where a > 0 +Error in execute: SELECT command denied to user: 'grant_user@localhost' for column 'a' in table 'test' +show grants for grant_user@localhost +GRANT UPDATE, CREATE ON *.* TO 'grant_user'@'localhost' + +revoke update on *.* from grant_user@localhost +Connecting grant_user grant select(c) on grant_test.test to grant_user@localhost Error in execute: Unknown column 'c' in 'test' revoke select(c) on grant_test.test from grant_user@localhost @@ -198,9 +210,24 @@ Error in execute: SELECT command denied to user: 'grant_user@localhost' for colu grant SELECT on *.* to grant_user@localhost Connecting grant_user update grant_test.test set b=b+1 +update grant_test.test set b=b+1 where a > 0 revoke SELECT on *.* from grant_user@localhost +grant SELECT on grant_test.* to grant_user@localhost +Connecting grant_user +update grant_test.test set b=b+1 +update grant_test.test set b=b+1 where a > 0 +grant UPDATE on *.* to grant_user@localhost Connecting grant_user -lect * from test +update grant_test.test set b=b+1 +update grant_test.test set b=b+1 where a > 0 +revoke UPDATE on *.* from grant_user@localhost +revoke SELECT on grant_test.* from grant_user@localhost +Connecting grant_user +update grant_test.test set b=b+1 where a > 0 +Error in execute: SELECT command denied to user: 'grant_user@localhost' for column 'a' in table 'test' +update grant_test.test set b=b+1 +Error in execute: SELECT command denied to user: 'grant_user@localhost' for column 'b' in table 'test' +select * from test Error in execute: select command denied to user: 'grant_user@localhost' for table 'test' grant select on grant_test.test to grant_user@localhost delete from grant_test.test where a=1 @@ -448,21 +475,34 @@ grant ALL PRIVILEGES on grant_test.test to grant_user@localhost identified by 'd Connecting grant_user grant SELECT on grant_test.* to grant_user@localhost identified by '' Connecting grant_user -revoke ALL PRIVILEGES on grant_test.test from grant_user@localhost identified by '' +revoke ALL PRIVILEGES on grant_test.test from grant_user@localhost identified by '', grant_user@127.0.0.1 identified by 'dummy2' revoke ALL PRIVILEGES on grant_test.* from grant_user@localhost identified by '' show grants for grant_user@localhost -create table grant_test.test3 (a int) +GRANT USAGE ON *.* TO 'grant_user'@'localhost' + +create table grant_test.test3 (a int, b int) grant SELECT on grant_test.test3 to grant_user@localhost grant FILE on *.* to grant_user@localhost -insert into grant_test.test3 values (1) +insert into grant_test.test3 values (1,1) Connecting grant_user select * into outfile '/tmp/mysql-grant.test' from grant_test.test3 revoke SELECT on grant_test.test3 from grant_user@localhost +grant SELECT(a) on grant_test.test3 to grant_user@localhost +select a from grant_test.test3 +1 + +select * from grant_test.test3 +Error in execute: select command denied to user: 'grant_user@localhost' for column 'b' in table 'test3' +select a,b from grant_test.test3 +Error in execute: SELECT command denied to user: 'grant_user@localhost' for column 'b' in table 'test3' +select b from grant_test.test3 +Error in execute: SELECT command denied to user: 'grant_user@localhost' for column 'b' in table 'test3' +revoke SELECT(a) on grant_test.test3 from grant_user@localhost revoke FILE on *.* from grant_user@localhost drop table grant_test.test3 create table grant_test.test3 (a int) Connecting grant_user -Access denied for user: 'grant_user@localhost' to database 'grant_test' +Error on connect: Access denied for user: 'grant_user@localhost' to database 'grant_test' grant INSERT on grant_test.test3 to grant_user@localhost Connecting grant_user select * into outfile '/tmp/mysql-grant.test' from grant_test.test3 @@ -474,7 +514,7 @@ Error in execute: Access denied for user: 'grant_user@localhost' to database 'gr grant LOCK TABLES on *.* to grant_user@localhost show grants for grant_user@localhost GRANT LOCK TABLES ON *.* TO 'grant_user'@'localhost' -GRANT SELECT, INSERT ON grant_test.test3 TO 'grant_user'@'localhost' +GRANT SELECT, INSERT ON `grant_test`.`test3` TO 'grant_user'@'localhost' select * from mysql.user where user='grant_user' 127.0.0.1 grant_user *042a99b3d247ae587783f647f2d69496d390aa71eab3 N N N N N N N N N N N N N N N N N N N N N 0 0 0 @@ -487,9 +527,11 @@ revoke SELECT,INSERT,UPDATE,DELETE on grant_test.test3 from grant_user@localhost Connecting grant_user revoke LOCK TABLES on *.* from grant_user@localhost Connecting grant_user -Access denied for user: 'grant_user@localhost' to database 'grant_test' +Error on connect: Access denied for user: 'grant_user@localhost' to database 'grant_test' drop table grant_test.test3 show grants for grant_user@localhost +GRANT USAGE ON *.* TO 'grant_user'@'localhost' + grant all on *.* to grant_user@localhost WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 show grants for grant_user@localhost GRANT ALL PRIVILEGES ON *.* TO 'grant_user'@'localhost' WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 @@ -501,6 +543,8 @@ GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, F revoke ALL PRIVILEGES on *.* from grant_user@localhost show grants for grant_user@localhost +GRANT USAGE ON *.* TO 'grant_user'@'localhost' WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 + drop database grant_test delete from user where user='grant_user' delete from db where user='grant_user' diff --git a/tests/table_types.pl b/tests/table_types.pl index 8198cd9ba86..4dbcdcb975c 100755 --- a/tests/table_types.pl +++ b/tests/table_types.pl @@ -66,13 +66,6 @@ $dbh = $server->connect(); #### $table_name="bench1"; -<<<<<<< table_types.pl -||||||| 1.2 -test("n","type=isam","char"); test("m","type=myisam pack_keys=1","char"); exit(1); - -======= - ->>>>>>> /tmp/T4a17019 test($table_name,"type=isam","char"); test($table_name,"type=myisam pack_keys=0","char"); test($table_name,"type=myisam pack_keys=0","char"); @@ -91,7 +84,7 @@ exit (0); sub test { my ($name,$options,$chartype)=@_; - + print "\nTesting with options: '$options'\n"; $dbh->do("drop table $name"); do_many($dbh,$server->create("$name", @@ -102,23 +95,23 @@ sub test { ["primary key (id,id2)", "index index_id3 (id3)"], $options)); - + if ($opt_lock_tables) { $sth = $dbh->do("LOCK TABLES $name WRITE") || die $DBI::errstr; } - + if ($opt_fast && defined($server->{vacuum})) { $server->vacuum(\$dbh,1); } - + #### #### Insert $total_rows records in order, in reverse order and random. #### - + $loop_time=new Benchmark; - + if ($opt_fast_insert) { $query="insert into $name values "; @@ -127,11 +120,11 @@ sub test { { $query="insert into $name (id,id2,id3,dummy1) values "; } - + if (($opt_fast || $opt_fast_insert) && $limits->{'multi_value_insert'}) { $query_size=$server->{'limits'}->{'query_size'}; - + print "Inserting $opt_loop_count multiple-value rows in order\n"; $res=$query; for ($i=0 ; $i < $opt_loop_count ; $i++) @@ -186,7 +179,7 @@ sub test { { $sth = $dbh->do($query . "($i,$i,$i,'ABCDEFGHIJ')") or die $DBI::errstr; } - + print "Inserting $opt_loop_count rows in reverse order\n"; for ($i=0 ; $i < $opt_loop_count ; $i++) { @@ -195,25 +188,25 @@ sub test { ($total_rows-1-$i) . ",'BCDEFGHIJK')") or die $DBI::errstr; } - + print "Inserting $opt_loop_count rows in random order\n"; - + for ($i=0 ; $i < $opt_loop_count ; $i++) { $sth = $dbh->do($query . "(". $random[$i] . "," . $random[$i] . "," . $random[$i] . ",'CDEFGHIJKL')") or die $DBI::errstr; } } - + $end_time=new Benchmark; print "Time for insert (" . ($total_rows) . "): " . timestr(timediff($end_time, $loop_time),"all") . "\n\n"; - + if ($opt_fast && defined($server->{vacuum})) { $server->vacuum(\$dbh,1); } - + $sth=$dbh->prepare("show table status like '$name'"); $sth->execute || die "Show table status returned error: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) diff --git a/vio/viossl.c b/vio/viossl.c index cf1c98b5382..834343a77d9 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -212,13 +212,14 @@ my_socket vio_ssl_fd(Vio* vio) } -my_bool vio_ssl_peer_addr(Vio * vio, char *buf) +my_bool vio_ssl_peer_addr(Vio * vio, char *buf, uint16 *port) { DBUG_ENTER("vio_ssl_peer_addr"); DBUG_PRINT("enter", ("sd=%d", vio->sd)); if (vio->localhost) { strmov(buf,"127.0.0.1"); + *port=0; } else { @@ -229,8 +230,13 @@ my_bool vio_ssl_peer_addr(Vio * vio, char *buf) DBUG_PRINT("exit", ("getpeername, error: %d", socket_errno)); DBUG_RETURN(1); } - /* FIXME */ -/* my_inet_ntoa(vio->remote.sin_addr,buf); */ +#ifdef TO_BE_FIXED + my_inet_ntoa(vio->remote.sin_addr,buf); + *port= 0; +#else + strmov(buf, "unknown"); + *port= 0; +#endif } DBUG_PRINT("exit", ("addr=%s", buf)); DBUG_RETURN(0); @@ -281,7 +287,8 @@ int sslaccept(struct st_VioSSLAcceptorFd* ptr, Vio* vio, long timeout) SSL_SESSION_set_timeout(SSL_get_session(vio->ssl_), timeout); SSL_set_fd(vio->ssl_,vio->sd); SSL_set_accept_state(vio->ssl_); - if (SSL_do_handshake(vio->ssl_) < 1) + if (SSL_do_handshake(vio->ssl_) < 1 || + SSL_get_verify_result(vio->ssl_) != X509_V_OK) { DBUG_PRINT("error", ("SSL_do_handshake failure")); report_errors(); @@ -354,7 +361,8 @@ int sslconnect(struct st_VioSSLConnectorFd* ptr, Vio* vio, long timeout) SSL_SESSION_set_timeout(SSL_get_session(vio->ssl_), timeout); SSL_set_fd (vio->ssl_, vio->sd); SSL_set_connect_state(vio->ssl_); - if (SSL_do_handshake(vio->ssl_) < 1) + if (SSL_do_handshake(vio->ssl_) < 1 || + SSL_get_verify_result(vio->ssl_) != X509_V_OK) { DBUG_PRINT("error", ("SSL_do_handshake failure")); report_errors(); |