From b947bc4aedc75a9d6fb2604d5b87c4c254e87ab3 Mon Sep 17 00:00:00 2001 From: "monty@donna.mysql.fi" <> Date: Thu, 8 Mar 2001 17:44:30 +0200 Subject: [PATCH 1/6] Added documentation about GEMINI tables --- Docs/manual.texi | 180 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 146 insertions(+), 34 deletions(-) diff --git a/Docs/manual.texi b/Docs/manual.texi index 62441251780..4f3946b4741 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -487,7 +487,8 @@ MySQL Table Types * ISAM:: ISAM tables * HEAP:: HEAP tables * BDB:: BDB or Berkeley_db tables -* INNOBASE:: +* GEMINI:: GEMINI tables +* INNOBASE:: INNOBASE tables MyISAM Tables @@ -509,11 +510,18 @@ BDB or Berkeley_db Tables * BDB TODO:: * BDB errors:: +GEMINI tables + +* GEMINI overview:: +* GEMINI start:: +* GEMINI features:: +* GEMINI TODO:: + INNOBASE Tables * INNOBASE overview:: -* Innobase startup options:: -* Using Innobase tables:: +* INNOBASE start:: +* Using INNOBASE tables:: * INNOBASE restrictions:: MySQL Tutorial @@ -582,7 +590,7 @@ Replication in MySQL * Replication Options:: Replication Options in my.cnf * Replication SQL:: SQL Commands related to replication * Replication FAQ:: Frequently Asked Questions about replication -* Troubleshooting Replication:: Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. +* Troubleshooting Replication:: Troubleshooting Replication Getting Maximum Performance from MySQL @@ -4198,7 +4206,7 @@ Please report bad or out-of-date mirrors to @email{webmaster@@mysql.com}. @c @uref{http://mysql.tradenet.ee, WWW} @item -@c EMAIL: tonu@spamm.ee (Tõnu Samuel) +@c EMAIL: tonu@spam.ee (Tõnu Samuel) @image{Flags/estonia} Estonia [OKinteractive] @ @uref{http://mysql.mirror.ok.ee, WWW} @@ -9527,6 +9535,12 @@ problems. @xref{Windows}. If you are using BDB (Berkeley DB) tables, you should familiarize yourself with the different BDB specific startup options. @xref{BDB start}. +If you are using Gemini tables, refer to the Gemini-specific startup options. +@xref{GEMINI start}. + +If you are using Innobase tables, refer to the Innobase-specific startup +options. @xref{INNOBASE start}. + @node Automatic start, Command-line options, Starting server, Post-installation @subsection Starting and Stopping MySQL Automatically @cindex starting, the server automatically @@ -10911,9 +10925,10 @@ Many of our users who have speed foremost in their minds are not at all concerned about transactions. For them transactions are not an issue. For those of our users who are concerned with or have wondered about transactions vis-a-vis @strong{MySQL}, there is a ``@strong{MySQL} -way'' as we have outlined above. For those where safety is more important -than speed, we recommend them to use the @code{BDB} tables for all their -critical data. @xref{BDB}. +way'' as we have outlined above. For those where safety is more +important than speed, we recommend them to use the @code{BDB}, +@code{GEMINI} or @code{INNOBASE} tables for all their critical +data. @xref{Table types}. One final note: We are currently working on a safe replication schema that we believe to be better than any commercial replication system we @@ -11139,12 +11154,14 @@ Entry level SQL92. ODBC levels 0-2. @cindex tables, updating @cindex updating, tables @cindex @code{BDB} tables - +@cindex @code{GEMINI} tables +@cindex @code{INNOBASE} tables The following mostly applies only for @code{ISAM}, @code{MyISAM}, and -@code{HEAP} tables. If you only use transaction-safe tables (@code{BDB} -tables) in an a update, you can do @code{COMMIT} and @code{ROLLBACK} also -with @strong{MySQL}. @xref{COMMIT}. +@code{HEAP} tables. If you only use transaction-safe tables (@code{BDB}, +@code{GEMINI} or @code{INNOBASE} tables) in an a update, you can do +@code{COMMIT} and @code{ROLLBACK} also with @strong{MySQL}. +@xref{COMMIT}. The problem with handling @code{COMMIT}-@code{ROLLBACK} efficiently with the above table types would require a completely different table layout @@ -18339,6 +18356,7 @@ The different table types are: @multitable @columnfractions .20 .80 @item BDB or Berkeley_db @tab Transaction-safe tables with page locking. @xref{BDB}. +@item GEMINI @tab Transaction-safe tables with row-level locking @xref{GEMINI}. @item HEAP @tab The data for this table is only stored in memory. @xref{HEAP}. @item ISAM @tab The original table handler. @xref{ISAM}. @item INNOBASE @tab Transaction-safe tables with row locking. @xref{INNOBASE}. @@ -22608,6 +22626,7 @@ used them. @cindex table types, choosing @cindex @code{BDB} table type @cindex @code{Berkeley_db} table type +@cindex @code{GEMINI} table type @cindex @code{HEAP} table type @cindex @code{ISAM} table type @cindex @code{INNOBASE} table type @@ -22678,7 +22697,8 @@ of both worlds. * ISAM:: ISAM tables * HEAP:: HEAP tables * BDB:: BDB or Berkeley_db tables -* INNOBASE:: +* GEMINI:: GEMINI tables +* INNOBASE:: INNOBASE tables @end menu @node MyISAM, MERGE, Table types, Table types @@ -23295,7 +23315,7 @@ SUM_OVER_ALL_KEYS(max_length_of_key + sizeof(char*) * 2) @cindex tables, @code{BDB} @cindex tables, @code{Berkeley DB} -@node BDB, INNOBASE, HEAP, Table types +@node BDB, GEMINI, HEAP, Table types @section BDB or Berkeley_db Tables @menu @@ -23310,9 +23330,8 @@ SUM_OVER_ALL_KEYS(max_length_of_key + sizeof(char*) * 2) @node BDB overview, BDB install, BDB, BDB @subsection Overview over BDB tables -BDB tables are included in the @strong{MySQL} source distribution -starting from 3.23.34 and will be activated in the @strong{MySQL}-max -binary. +BDB is included in the @strong{MySQL} source distribution starting +from 3.23.34 and will be activated in the @strong{MySQL}-max binary. Berkeley DB (@uref{http://www.sleepycat.com}) has provided @strong{MySQL} with a transaction-safe table handler. This will survive @@ -23509,22 +23528,103 @@ This is not fatal but we don't recommend that you delete tables if you are not in @code{auto_commit} mode, until this problem is fixed (the fix is not trivial). -@node INNOBASE, , BDB, Table types +@cindex tables, @code{GEMINI} +@node GEMINI, INNOBASE, BDB, Table types +@section GEMINI Tables + +@menu +* GEMINI overview:: +* GEMINI start:: +* GEMINI features:: +* GEMINI TODO:: +@end menu + +@node GEMINI overview, GEMINI start, GEMINI, GEMINI +@subsection Overview of GEMINI tables + +The @code{GEMINI} table type is developed and supported by NuSphere Corporation +(@uref{http://www.nusphere.com}). It features row-level locking, transaction +support (@code{COMMIT} and @code{ROLLBACK}), and automatic crash recovery. + +@code{GEMINI} tables will be included in the @strong{MySQL} 4.0 source +distribution. + +@node GEMINI start, GEMINI features, GEMINI overview, GEMINI +@subsection GEMINI startup options + +If you are running with @code{AUTOCOMMIT=0} then your changes in @code{GEMINI} +tables will not be updated until you execute @code{COMMIT}. Instead of commit +you can execute @code{ROLLBACK} to forget your changes. @xref{COMMIT}. + +If you are running with @code{AUTOCOMMIT=1} (the default), your changes +will be committed immediately. You can start an extended transaction with +the @code{BEGIN WORK} SQL command, after which your changes will not be +committed until you execute @code{COMMIT} (or decide to @code{ROLLBACK} +the changes). + +The following options to @code{mysqld} can be used to change the behavior of +GEMINI tables: + +@multitable @columnfractions .30 .70 +@item @strong{Option} @tab @strong{Meaning} +@item @code{--gemini-full-recovery} @tab Default. +@item @code{--gemini-no-recovery} @tab Turn off recovery logging. Not recommended. +@item @code{--gemini-lazy-commit} @tab Relaxes the flush log at commit rule. +@item @code{--gemini-unbuffered-io} @tab All database writes bypass OS cache. +@item @code{--skip-gemini} @tab Don't use Gemini. +@item @code{--O gemini_db_buffers=#} @tab Number of database buffers in database cache. +@item @code{--O gemini_connection_limit=#} @tab Maximum number of connections to Gemini. +@item @code{--O gemini_spin_retries=#} @tab Spin lock retries (optimization). +@item @code{--O gemini_io_threads=#} @tab Number of background I/O threads. +@item @code{--O gemini_lock_table_size=#} @tab Set the maximum number of locks. Default 4096. +@end multitable + +If you use @code{--skip-gemini}, @strong{MySQL} will not initialize the +Gemini table handler, saving memory; you cannot use Gemini tables if you +use @code{--skip-gemini}. + +@node GEMINI features, GEMINI TODO, GEMINI start, GEMINI +@subsection Features of @code{GEMINI} tables: + +@itemize @bullet +@item +If a query result can be resolved solely from the index key, Gemini will +not read the actual row stored in the database. +@item +Locking on Gemini tables is done at row level. +@item +@code{SELECT COUNT(*) FROM table_name} is fast; Gemini maintains a count +of the number of rows in the table. +@end itemize + +@node GEMINI TODO, , GEMINI features, GEMINI +@subsection Current limitations of @code{GEMINI} tables: + +@itemize @bullet +@item +BLOB columns are not supported in @code{GEMINI} tables. +@item +The maximum number of concurrent users accessing @code{GEMINI} tables is +limited by @code{gemini_connection_limit}. The default is 100 users. +@end itemize + +NuSphere is working on removing these limitations. + +@node INNOBASE, , GEMINI, Table types @section INNOBASE Tables @menu * INNOBASE overview:: -* Innobase startup options:: -* Using Innobase tables:: -* INNOBASE restrictions:: +* INNOBASE start:: INNOBASE startup options +* Using INNOBASE tables:: Using INNOBASE tables +* INNOBASE restrictions:: Some restrictions on @code{INNOBASE} tables: @end menu -@node INNOBASE overview, Innobase startup options, INNOBASE, INNOBASE +@node INNOBASE overview, INNOBASE start, INNOBASE, INNOBASE @subsection INNOBASE Tables overview -Innobase tables are included in the @strong{MySQL} source distribution -starting from 3.23.34 and will be activated in the @strong{MySQL}-max -binary. +Innobase is included in the @strong{MySQL} source distribution starting +from 3.23.34 and will be activated in the @strong{MySQL}-max binary. If you have downloaded a binary version of @strong{MySQL} that includes support for Berkeley DB, simply follow the instructions for @@ -23550,8 +23650,8 @@ Innobase is a table handler that is under the GNU GPL License Version 2 (of June 1991). In the source distribution of MySQL, Innobase appears as a subdirectory. -@node Innobase startup options, Using Innobase tables, INNOBASE overview, INNOBASE -@subsection Innobase startup options +@node INNOBASE start, Using INNOBASE tables, INNOBASE overview, INNOBASE +@subsection INNOBASE startup options To use Innobase tables you must specify configuration parameters in the MySQL configuration file in the @code{[mysqld]} section of @@ -23647,8 +23747,8 @@ Innobase cannot notice. In cases like this the timeout is useful to resolve the situation. @end multitable -@node Using Innobase tables, INNOBASE restrictions, Innobase startup options, INNOBASE -@subsection Using Innobase tables +@node Using INNOBASE tables, INNOBASE restrictions, INNOBASE start, INNOBASE +@subsection Using INNOBASE tables Technically, Innobase is a database backend placed under MySQL. Innobase has its own buffer pool for caching data and indexes in main @@ -23721,7 +23821,7 @@ P.O.Box 800 Finland @end example -@node INNOBASE restrictions, , Using Innobase tables, INNOBASE +@node INNOBASE restrictions, , Using INNOBASE tables, INNOBASE @subsection Some restrictions on @code{INNOBASE} tables: @itemize @bullet @@ -26472,7 +26572,7 @@ tables}. * Replication Options:: Replication Options in my.cnf * Replication SQL:: SQL Commands related to replication * Replication FAQ:: Frequently Asked Questions about replication -* Troubleshooting Replication:: Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. +* Troubleshooting Replication:: Troubleshooting Replication @end menu @node Replication Intro, Replication Implementation, Replication, Replication @@ -29911,7 +30011,7 @@ performance in a threaded system! @xref{Multiple servers}. -This is an example of the config file on behalf of @code{mysqld_multi}. +This is an example of the config file on behalf of @code{mysqld_multi}. @example # This file should probably be in your home dir (~/.my.cnf) or /etc/my.cnf @@ -39136,8 +39236,7 @@ Two APIs are available in the @strong{MySQL} @section MySQL Python APIs The @strong{MySQL} @uref{http://www.mysql.com/Downloads/Contrib/,Contrib directory} -contains a Python -interface written by Joseph Skinner. +contains a Python interface written by Joseph Skinner. You can also use the Python interface to iODBC to access a @strong{MySQL} server. @@ -41447,6 +41546,12 @@ Our security expert. @item Vio interface (foundation for the the encrypted client/server protocol). @item +MySQL Filesystem (Way to use MySQL databases as files and directories). +@item +CASE Expression +@item +MD5(), COALESCE() functions. +@item @code{RAID} support for @code{MyISAM} tables. @end itemize @@ -41902,6 +42007,8 @@ not yet 100 % confident in this code. Added the @code{INNOBASE} table handler and the @code{BDB} table handler to the @strong{MySQL} source distribution. @item +Updated the documentation about @code{GEMINI} tables. +@item @code{REPLACE} will not replace a row that conflicts with an @code{auto_increment} generated key. @item @@ -46804,6 +46911,11 @@ ORDER BY columns in the result, something that is you are not allowed to do in ANSI SQL. @item +Because @strong{MySQL} allows you to work with table types that doesn't +support transactions (and thus can't @code{rollback} data) some things +behaves a little different in @strong{MySQL} than in other SQL servers: +(This is just to ensure that @strong{MySQL} never need to do a rollback +for a SQL command). This may be a little akward at times as column Because @strong{MySQL} allows you to work with table types that don't support transactions, and thus can't @code{rollback} data, some things behave a little differently in @strong{MySQL} than in other SQL servers. From 55217d8cefc1c520d679d30d920c0c896b003af6 Mon Sep 17 00:00:00 2001 From: "tim@work.mysql.com" <> Date: Thu, 8 Mar 2001 18:02:48 +0100 Subject: [PATCH 2/6] Make configure generate a fake bdb/build_unix/db.h file, so that 'make distcheck' will work. I hope. This is an ugly hack.... --- configure.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/configure.in b/configure.in index 1939f6191d1..e4987802ebb 100644 --- a/configure.in +++ b/configure.in @@ -1906,6 +1906,28 @@ dnl echo "bdb = '$bdb'; inc = '$bdb_includes', lib = '$bdb_libs'" fi AC_DEFINE(HAVE_BERKELEY_DB) + else + if test -d bdb; then : + else + mkdir bdb && mkdir bdb/build_unix && cat < bdb/build_unix/db.h + +This file is a placeholder to fool make. The way that automake +handles 'make distcheck' (calling the VPATH configure with different +options from the original configure) causes make to think that mysqld +depends on this file, even though Berkeley DB isn't being used. + +Obviously, if this file *is* used, it'll break and hopefully we can find +out why this file was generated by $(top_srcdir)/configure instead of +the real db.h. + +If you run into some problems because of this file, please use mysql_bug +to generate a bug report, and give the exact output of make and any +details you can think of. Send the message to bugs@lists.mysql.com. + +Thank you! + +EOF + fi fi if test X"$have_innobase_db" = Xyes From c91715e3e51595522a0ead641a0798b45876294b Mon Sep 17 00:00:00 2001 From: "tim@work.mysql.com" <> Date: Thu, 8 Mar 2001 20:06:08 +0100 Subject: [PATCH 3/6] Make configure always generate a dummy bdb/build_unix/db.h file. Ugh. --- configure.in | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/configure.in b/configure.in index e4987802ebb..908cfcd67a9 100644 --- a/configure.in +++ b/configure.in @@ -1909,12 +1909,16 @@ dnl echo "bdb = '$bdb'; inc = '$bdb_includes', lib = '$bdb_libs'" else if test -d bdb; then : else - mkdir bdb && mkdir bdb/build_unix && cat < bdb/build_unix/db.h + mkdir bdb && mkdir bdb/build_unix + fi + + if test -r bdb/build_unix/db.h; then : + else + cat < bdb/build_unix/db.h This file is a placeholder to fool make. The way that automake -handles 'make distcheck' (calling the VPATH configure with different -options from the original configure) causes make to think that mysqld -depends on this file, even though Berkeley DB isn't being used. +and GNU make work together causes some files to depend on this +header, even if we're not building with Berkeley DB. Obviously, if this file *is* used, it'll break and hopefully we can find out why this file was generated by $(top_srcdir)/configure instead of From 32d403f087116419d52b021963a5a4b13dda95a4 Mon Sep 17 00:00:00 2001 From: "monty@donna.mysql.fi" <> Date: Thu, 8 Mar 2001 21:49:15 +0200 Subject: [PATCH 4/6] Fixed bug in INSERT DELAYED when INSERT generated an error --- Docs/manual.texi | 158 +++++++++++++++++++++++------------- mysql-test/r/delayed.result | 5 ++ mysql-test/t/delayed.test | 14 ++++ scripts/mysqldumpslow.sh | 148 +++++++++++++++++++++++---------- sql/field_conv.cc | 3 +- sql/sql_insert.cc | 20 +++-- 6 files changed, 242 insertions(+), 106 deletions(-) diff --git a/Docs/manual.texi b/Docs/manual.texi index 4f3946b4741..00fca7457a8 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -469,6 +469,11 @@ Functions for Use in @code{SELECT} and @code{WHERE} Clauses * Silent column changes:: Silent column changes +@code{INSERT} Syntax + +* INSERT SELECT:: +* INSERT DELAYED:: + @code{SHOW} Syntax (Get Information About Tables, Columns,...) * SHOW DATABASE INFO:: @@ -510,19 +515,19 @@ BDB or Berkeley_db Tables * BDB TODO:: * BDB errors:: -GEMINI tables +GEMINI Tables -* GEMINI overview:: -* GEMINI start:: -* GEMINI features:: -* GEMINI TODO:: +* GEMINI overview:: +* GEMINI start:: +* GEMINI features:: +* GEMINI TODO:: INNOBASE Tables * INNOBASE overview:: -* INNOBASE start:: -* Using INNOBASE tables:: -* INNOBASE restrictions:: +* INNOBASE start:: INNOBASE startup options +* Using INNOBASE tables:: Using INNOBASE tables +* INNOBASE restrictions:: Some restrictions on @code{INNOBASE} tables: MySQL Tutorial @@ -590,7 +595,7 @@ Replication in MySQL * Replication Options:: Replication Options in my.cnf * Replication SQL:: SQL Commands related to replication * Replication FAQ:: Frequently Asked Questions about replication -* Troubleshooting Replication:: Troubleshooting Replication +* Troubleshooting Replication:: Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication Getting Maximum Performance from MySQL @@ -6154,7 +6159,9 @@ source tree: @itemize @item -Download @strong{BitKeeper} from @uref{http://www.bitmover.com/cgi-bin/download.cgi}. +Download @strong{BitKeeper} from +@uref{http://www.bitmover.com/cgi-bin/download.cgi}. You will need +@strong{Bitkeeper} 2.0 or newer to access our repository. @item Follow the instructions to install it. @item @@ -10810,7 +10817,7 @@ other contexts, however. @strong{MySQL} doesn't yet support the Oracle SQL extension: @code{SELECT ... INTO TABLE ...}. @strong{MySQL} supports instead the ANSI SQL syntax @code{INSERT INTO ... SELECT ...}, which is basically -the same thing. @xref{INSERT}. +the same thing. @xref{INSERT SELECT}. @example INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID FROM tblTemp1 WHERE @@ -10902,7 +10909,7 @@ still allowed to happen. The new inserted records will not be seen by any of the clients that have a @code{READ} lock until they release their read locks. With @code{INSERT DELAYED} you can queue inserts into a local queue, until the locks are released, without having the client wait for the insert -to complete. +to complete. @xref{INSERT DELAYED}. ``Atomic,'' in the sense that we mean it, is nothing magical. It only means that you can be sure that while each specific update is running, no other @@ -19635,12 +19642,13 @@ mysql> INSERT INTO tbl_name (col1,col2) VALUES(col2*2,15); @item If you specify the keyword @code{LOW_PRIORITY}, execution of the -@code{INSERT} is delayed until no other clients are reading from the table. -In this case the client has to wait until the insert statement is completed, -which may take a long time if the table is in heavy use. This is in -contrast to @code{INSERT DELAYED}, which lets the client continue at once. -Note that @code{LOW_PRIORITY} should normally not be used with @code{MyISAM} -tables as this disables concurrent inserts.@xref{MyISAM}. +@code{INSERT} is delayed until no other clients are reading from the +table. In this case the client has to wait until the insert statement +is completed, which may take a long time if the table is in heavy +use. This is in contrast to @code{INSERT DELAYED}, which lets the client +continue at once. @xref{INSERT DELAYED}. Note that @code{LOW_PRIORITY} +should normally not be used with @code{MyISAM} tables as this disables +concurrent inserts. @xref{MyISAM}. @item If you specify the keyword @code{IGNORE} in an @code{INSERT} with many value @@ -19662,32 +19670,6 @@ with the @code{mysql_insert_id} function. @xref{mysql_insert_id, , @code{mysql_insert_id()}}. @end itemize -With @code{INSERT ... SELECT} statement you can quickly insert many rows -into a table from one or many tables. - -@example -INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID FROM tblTemp1 WHERE -tblTemp1.fldOrder_ID > 100; -@end example - -The following conditions hold for an @code{INSERT ... SELECT} statement: - -@itemize @minus -@item -The query cannot contain an @code{ORDER BY} clause. - -@item -The target table of the @code{INSERT} statement cannot appear in the -@code{FROM} clause of the @code{SELECT} part of the query because it's -forbidden in ANSI SQL to @code{SELECT} from the same table into which you are -inserting. (The problem is that the @code{SELECT} possibly would -find records that were inserted earlier during the same run. When using -sub-select clauses, the situation could easily be very confusing!) - -@item -@code{AUTO_INCREMENT} columns work as usual. -@end itemize - @findex mysql_info() If you use @code{INSERT ... SELECT} or an @code{INSERT ... VALUES} statement with multiple value lists, you can use the C API function @@ -19728,17 +19710,76 @@ Inserting a value into a date or time column that is illegal for the column type. The column is set to the appropriate zero value for the type. @end itemize +@findex REPLACE ... SELECT +@findex INSERT ... SELECT +@menu +* INSERT SELECT:: +* INSERT DELAYED:: +@end menu + +@node INSERT SELECT, INSERT DELAYED, INSERT, INSERT +@subsection INSERT ... SELECT Syntax + +@example +INSERT [LOW_PRIORITY] [IGNORE] [INTO] tbl_name [(column list)] SELECT ... +@end example + +With @code{INSERT ... SELECT} statement you can quickly insert many rows +into a table from one or many tables. + +@example +INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID FROM tblTemp1 WHERE +tblTemp1.fldOrder_ID > 100; +@end example + +The following conditions hold for an @code{INSERT ... SELECT} statement: + +@itemize @minus +@item +The query cannot contain an @code{ORDER BY} clause. + +@item +The target table of the @code{INSERT} statement cannot appear in the +@code{FROM} clause of the @code{SELECT} part of the query because it's +forbidden in ANSI SQL to @code{SELECT} from the same table into which you are +inserting. (The problem is that the @code{SELECT} possibly would +find records that were inserted earlier during the same run. When using +sub-select clauses, the situation could easily be very confusing!) + +@item +@code{AUTO_INCREMENT} columns work as usual. + +@item +You can use the C API function @code{mysql_info()} to get information about +the query. @xref{INSERT}. +@end itemize + +You can of course also use @code{REPLACE} instead of @code{INSERT} to +overwrite old rows. + @findex INSERT DELAYED @findex DELAYED +@cindex INSERT DELAYED +@node INSERT DELAYED, , INSERT SELECT, INSERT +@subsection @code{INSERT DELAYED} syntax -The @code{DELAYED} option -for the -@code{INSERT} statement is a @strong{MySQL}-specific option that is very -useful if you have clients that can't wait for the @code{INSERT} to complete. -This is a common problem when you use @strong{MySQL} for logging and you also -periodically run @code{SELECT} statements that take a long time to complete. -@code{DELAYED} was introduced in @strong{MySQL} Version 3.22.15. It is a -@strong{MySQL} extension to ANSI SQL92. +@example +INSERT DELAYED ... +@end example + +The @code{DELAYED} option for the @code{INSERT} statement is a +@strong{MySQL}-specific option that is very useful if you have clients +that can't wait for the @code{INSERT} to complete. This is a common +problem when you use @strong{MySQL} for logging and you also +periodically run @code{SELECT} and @code{UPDATE} statements that take a +long time to complete. @code{DELAYED} was introduced in @strong{MySQL} +Version 3.22.15. It is a @strong{MySQL} extension to ANSI SQL92. + +@code{INSERT DELAYED} only works with @code{ISAM} and @code{MyISAM} +tables. Note that as @code{MyISAM} tables supports concurrent +@code{SELECT} and @code{INSERT}, if there is no empty blocks in the data +file, you very seldom need to use @code{INSERT DELAYED} with +@code{MyISAM}. When you use @code{INSERT DELAYED}, the client will get an OK at once and the row will be inserted when the table is not in use by any other thread. @@ -23533,10 +23574,10 @@ not trivial). @section GEMINI Tables @menu -* GEMINI overview:: -* GEMINI start:: -* GEMINI features:: -* GEMINI TODO:: +* GEMINI overview:: +* GEMINI start:: +* GEMINI features:: +* GEMINI TODO:: @end menu @node GEMINI overview, GEMINI start, GEMINI, GEMINI @@ -26572,7 +26613,7 @@ tables}. * Replication Options:: Replication Options in my.cnf * Replication SQL:: SQL Commands related to replication * Replication FAQ:: Frequently Asked Questions about replication -* Troubleshooting Replication:: Troubleshooting Replication +* Troubleshooting Replication:: Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication @end menu @node Replication Intro, Replication Implementation, Replication, Replication @@ -42009,6 +42050,9 @@ to the @strong{MySQL} source distribution. @item Updated the documentation about @code{GEMINI} tables. @item +Fixed thread-hang-bug in @code{INSERT DELAYED} when inserting +@code{NULL} into an @code{AUTO_INCREMENT} column. +@item @code{REPLACE} will not replace a row that conflicts with an @code{auto_increment} generated key. @item diff --git a/mysql-test/r/delayed.result b/mysql-test/r/delayed.result index c3281ce5330..d1914341a8d 100644 --- a/mysql-test/r/delayed.result +++ b/mysql-test/r/delayed.result @@ -3,3 +3,8 @@ a tmsp 5 19711006010203 6 19711006010203 8 19711006010203 +a b +1 b +2 c +3 d +4 e diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test index 15a85a09b8d..4bc1afa7612 100644 --- a/mysql-test/t/delayed.test +++ b/mysql-test/t/delayed.test @@ -15,3 +15,17 @@ insert into t1 set a = 8,tmsp=19711006010203; select * from t1 where tmsp=0; select * from t1 where tmsp=19711006010203; drop table t1; + +# +# Test bug when inserting NULL into an auto_increment field with +# INSERT DELAYED +# + +create table t1 (a int not null auto_increment primary key, b char(10)); +insert delayed into t1 values (1,"b"); +insert delayed into t1 values (null,"c"); +insert delayed into t1 values (3,"d"),(null,"e"); +--error 1136 +insert delayed into t1 values (3,"this will give an","error"); +select * from t1; +drop table t1; diff --git a/scripts/mysqldumpslow.sh b/scripts/mysqldumpslow.sh index b0e63dd73c1..02b5d5cd0cd 100644 --- a/scripts/mysqldumpslow.sh +++ b/scripts/mysqldumpslow.sh @@ -1,6 +1,9 @@ #!@PERL@ # mysqldumpslow - parse and summarize the MySQL slow query log +# Original version by Tim Bunce, sometime in 2000. +# Further changes by Tim Bunce, 8th March 2001. + use strict; use Getopt::Long; @@ -8,69 +11,128 @@ use Getopt::Long; # at, al, and ar are the corresponding averages my %opt = ( - s => 'at', - h => '*', + s => 'at', + h => '*', ); GetOptions(\%opt, - 'v+', # verbose - 'd+', # debug - 's=s', # what to sort by (t, at, l, al, r, ar etc) - 'a!', # don't abstract all numbers to N and strings to 'S' - 'g=s', # grep: only consider stmts that include this string - 'h=s', # hostname of db server (can be wildcard) + 'v+', # verbose + 'd+', # debug + 's=s', # what to sort by (t, at, l, al, r, ar etc) + 'r!', # reverse the sort order (largest last instead of first) + 't=i', # just show the top n queries + 'a!', # don't abstract all numbers to N and strings to 'S' + 'n=i', # abstract numbers with at least n digits within names + 'g=s', # grep: only consider stmts that include this string + 'h=s', # hostname of db server for *-slow.log filename (can be wildcard) + 'i=s', # name of server instance (if using mysql.server startup script) + 'l!', # don't subtract lock time from total time ) or die "Bad option"; + +unless (@ARGV) { + my $defaults = `my_print_defaults mysqld`; + my $basedir = ($defaults =~ m/--basedir=(.*)/)[0] + or die "Can't determine basedir from 'my_print_defaults mysqld' output: $defaults"; + warn "basedir=$basedir\n" if $opt{v}; + + my $datadir = ($defaults =~ m/--datadir=(.*)/)[0]; + if (!$datadir or $opt{i}) { + # determine the datadir from the instances section of /etc/my.cnf, if any + my $instances = `my_print_defaults instances`; + die "Can't determine datadir from 'my_print_defaults mysqld' output: $defaults" + unless $instances; + my @instances = ($instances =~ m/^--(\w+)-/mg); + die "No -i 'instance_name' specified to select among known instances: @instances.\n" + unless $opt{i}; + die "Instance '$opt{i}' is unknown (known instances: @instances)\n" + unless grep { $_ eq $opt{i} } @instances; + $datadir = ($instances =~ m/--$opt{i}-datadir=(.*)/)[0] + or die "Can't determine --$opt{i}-datadir from 'my_print_defaults instances' output: $instances"; + warn "datadir=$datadir\n" if $opt{v}; + } + + @ARGV = <$datadir/$opt{h}-slow.log>; + die "Can't find '$datadir/$opt{h}-slow.log'\n" unless @ARGV; +} + +warn "\nReading mysql slow query log from @ARGV\n"; + +my @pending; my %stmt; +$/ = ";\n#"; # read entire statements using paragraph mode +while ( defined($_ = shift @pending) or defined($_ = <>) ) { + warn "[[$_]]\n" if $opt{d}; # show raw paragraph being read -my $datadir = "/var/lib/mysql"; # XXX should fetch dynamically -@ARGV = <$datadir/$opt{h}-slow.log>; + my @chunks = split /^\/.*Version.*started with[\000-\377]*?Time.*Id.*Command.*Argument.*\n/m; + if (@chunks > 1) { + unshift @pending, map { length($_) ? $_ : () } @chunks; + warn "<<".join(">>\n<<",@chunks).">>" if $opt{d}; + next; + } -$/ = "\n#"; # read entire statements using paragraph mode -while (<>) { - print "[$_]\n" if $opt{v}; - s/^#// unless %stmt; + s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//; + my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('',''); - s/\s*Time: (\d+) Lock_time: (\d+) Rows_sent: (\d+).*\n//; - my ($t, $l, $r) = ($1, $2, $3); + s/^# Time: (\d+) Lock_time: (\d+) Rows_sent: (\d+).*\n//; + my ($t, $l, $r) = ($1, $2, $3); + $t -= $l unless $opt{l}; - s/^use \w+;\n//; # not consistently added - s/^SET timestamp=\d+;\n//; + # remove fluff that mysqld writes to log when it (re)starts: + s!^/.*Version.*started with:.*\n!!mg; + s!^Tcp port: \d+ Unix socket: \S+\n!!mg; + s!^Time.*Id.*Command.*Argument.*\n!!mg; - s/^[ ]*\n//mg; # delete blank lines - s/^[ ]*/ /mg; # normalize leading whitespace - s/\s*;\s*(#\s*)?$//; # remove traing semicolon(+newline-hash) + s/^use \w+;\n//; # not consistently added + s/^SET timestamp=\d+;\n//; - next if $opt{g} and !m/$opt{g}/i; + s/^[ ]*\n//mg; # delete blank lines + s/^[ ]*/ /mg; # normalize leading whitespace + s/\s*;\s*(#\s*)?$//; # remove trailing semicolon(+newline-hash) - unless ($opt{a}) { - s/\b\d+\b/N/g; - s/\b0x[0-9A-Fa-f]+\b/N/g; - s/'.*?'/'S'/g; - s/".*?"/"S"/g; - } + next if $opt{g} and !m/$opt{g}/io; - $stmt{$_}->{c} += 1; - $stmt{$_}->{t} += $t; - $stmt{$_}->{l} += $l; - $stmt{$_}->{r} += $r; + unless ($opt{a}) { + s/\b\d+\b/N/g; + s/\b0x[0-9A-Fa-f]+\b/N/g; + s/'.*?'/'S'/g; + s/".*?"/"S"/g; + # -n=8: turn log_20001231 into log_NNNNNNNN + s/([a-z_]+)(\d{$opt{n},})/$1.('N' x length($2))/ieg if $opt{n}; + # abbreviate massive "in (...)" statements and similar + s!(([NS],){100,})!sprintf("$2,{repeated %d times}",length($1)/2)!eg; + } - warn "[$_]" if $opt{d}; + my $s = $stmt{$_} ||= { users=>{}, hosts=>{} }; + $s->{c} += 1; + $s->{t} += $t; + $s->{l} += $l; + $s->{r} += $r; + $s->{users}->{$user}++ if $user; + $s->{hosts}->{$host}++ if $host; + + warn "{{$_}}\n\n" if $opt{d}; # show processed statement string } foreach (keys %stmt) { - my $v = $stmt{$_} || die; - my ($c, $t, $l, $r) = @{ $v }{qw(c t l r)}; - $v->{at} = $t / $c; - $v->{al} = $l / $c; - $v->{ar} = $r / $c; + my $v = $stmt{$_} || die; + my ($c, $t, $l, $r) = @{ $v }{qw(c t l r)}; + $v->{at} = $t / $c; + $v->{al} = $l / $c; + $v->{ar} = $r / $c; } -my @sorted = sort { $stmt{$a}->{$opt{s}} <=> $stmt{$b}->{$opt{s}} } keys %stmt; +my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt; +@sorted = @sorted[0 .. $opt{t}-1] if $opt{t}; +@sorted = reverse @sorted if $opt{r}; foreach (@sorted) { - my $v = $stmt{$_} || die; - my ($c, $t,$at, $l,$al, $r,$ar) = @{ $v }{qw(c t at l al r ar)}; - printf "Count: %d Time: %.2f (%d) Lock_time: %.2f (%d) Rows_sent: %.1f (%d) \n%s\n\n", - $c, $at,$t, $al,$l, $ar,$r, $_; + my $v = $stmt{$_} || die; + my ($c, $t,$at, $l,$al, $r,$ar) = @{ $v }{qw(c t at l al r ar)}; + my @users = keys %{$v->{users}}; + my $user = (@users==1) ? $users[0] : sprintf "%dusers",scalar @users; + my @hosts = keys %{$v->{hosts}}; + my $host = (@hosts==1) ? $hosts[0] : sprintf "%dhosts",scalar @hosts; + printf "Count: %d Time=%.2fs (%ds) Lock=%.2fs (%ds) Rows=%.1f (%d), $user\@$host\n%s\n\n", + $c, $at,$t, $al,$l, $ar,$r, $_; } diff --git a/sql/field_conv.cc b/sql/field_conv.cc index aae9f18e6a0..606edd84c74 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -133,7 +133,8 @@ set_field_to_null(Field *field) return 0; } if (!current_thd->no_errors) - my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0),field->field_name); + my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0), + field->field_name); return 1; } return 0; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 21827d17573..8e8f46b2e1f 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -247,9 +247,12 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List &fields, } if (lock_type == TL_WRITE_DELAYED) { - id=0; // No auto_increment id - info.copied=values_list.elements; - end_delayed_insert(thd); + if (!error) + { + id=0; // No auto_increment id + info.copied=values_list.elements; + end_delayed_insert(thd); + } } else { @@ -486,7 +489,7 @@ public: table(0),tables_in_use(0),stacked_inserts(0), status(0), dead(0), group_count(0) { - thd.user=thd.host=(char*) ""; + thd.user=0; thd.host=(char*) localhost; thd.current_tablenr=0; thd.version=refresh_version; thd.command=COM_DELAYED_INSERT; @@ -676,7 +679,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) TABLE *delayed_insert::get_local_table(THD* client_thd) { my_ptrdiff_t adjust_ptrs; - Field **field,**org_field; + Field **field,**org_field, *found_next_number_field; TABLE *copy; /* First request insert thread to get a lock */ @@ -719,11 +722,14 @@ TABLE *delayed_insert::get_local_table(THD* client_thd) adjust_ptrs=PTR_BYTE_DIFF(copy->record[0],table->record[0]); + found_next_number_field=table->found_next_number_field; for (org_field=table->field ; *org_field ; org_field++,field++) { if (!(*field= (*org_field)->new_field(copy))) return 0; (*field)->move_field(adjust_ptrs); // Point at copy->record[0] + if (*org_field == found_next_number_field) + (*field)->table->found_next_number_field= *field; } *field=0; @@ -806,14 +812,17 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic, static void end_delayed_insert(THD *thd) { + DBUG_ENTER("end_delayed_insert"); delayed_insert *di=thd->di; pthread_mutex_lock(&di->mutex); + DBUG_PRINT("info",("tables in use: %d",di->tables_in_use)); if (!--di->tables_in_use || di->thd.killed) { // Unlock table di->status=1; pthread_cond_signal(&di->cond); } pthread_mutex_unlock(&di->mutex); + DBUG_VOID_RETURN; } @@ -951,6 +960,7 @@ static pthread_handler_decl(handle_delayed_insert,arg) pthread_mutex_unlock(&di->thd.mysys_var->mutex); di->thd.proc_info=0; + DBUG_PRINT("info",("Waiting for someone to insert rows")); for ( ; ;) { int error; From 210440590455a100833c66b7d943756bddd3333e Mon Sep 17 00:00:00 2001 From: "monty@donna.mysql.fi" <> Date: Thu, 8 Mar 2001 22:27:43 +0200 Subject: [PATCH 5/6] Added documentation about mysql-test-run --- Docs/manual.texi | 34 ++++++++++++++++++++++++++++++++++ mysql-test/mysql-test-run.sh | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/Docs/manual.texi b/Docs/manual.texi index bc21efc2cf0..a032c4f8e6d 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -40213,6 +40213,40 @@ attachemnts, you should ftp all the relevant files to: @end itemize +If your @strong{MySQL} version doesn't pass the test suite you should +do the following: + +@itemize @bullet +@item +Don't send a bug report before you have found out as much as possible of +what when wrong! When you do it, please use the @code{mysqlbug} script +so that we can get information about your system and @code{MySQL} +version. @xref{Bug reports}. +@item +If you have compiled @strong{MySQL} yourself, check our manual for how +to compile @strong{MySQL} on your platform or, preferable, use one of +the binaries we have compiled for you at +@uref{http://www.mysql.com/downloads/}. All our standard binaries should +pass the test suite ! + +@item +If you get an error, like @code{Result length mismatch} or @code{Result +content mismatch} it means that the output of the test didn't match +exactly the expected output. This could be a bug in @strong{MySQL} or +that your mysqld version produces slight different results under some +circumstances. In this case you should compare the @code{.test} +and @code{.reject} file in the @code{mysql-test/r} sub directory to +see if this is something to worry about. + +@item +If a test fails totally, you should check the logs file in the +@code{mysql-test/var/log} directory for hints of what went wrong. + +@item +If you have compiled @strong{MySQL} with debugging you can try to debug this +with the @code{--gdb} and @code{--debug} options to @code{mysql-test-run}. +@end itemize + @page @cindex environment variables, list of @node Environment variables, Users, MySQL internals, Top diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 075cfd83933..fb247000be7 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -291,6 +291,11 @@ report_stats () { xwhole=`$EXPR $whole \* 100` deci=`$EXPR $raw - $xwhole` $ECHO "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% successful." + $ECHO "" + $ECHO "The log files in $MYSQL_TEST_DIR/var/log may give you some hint" + $ECHO "of what when wrong." + $ECHO "If you want to report this error, please read first the documentation at" + $ECHO "http://www.mysql.com/doc/M/y/MySQL_test_suite.html" fi } From 267c8760cb33208e2c1d772340c2aaf234806c45 Mon Sep 17 00:00:00 2001 From: "monty@donna.mysql.fi" <> Date: Fri, 9 Mar 2001 03:38:18 +0200 Subject: [PATCH 6/6] Fixed wrong option in mysql_install_db Added delayed_user for delayed_threads Don't use record cache when doing deletes --- Docs/manual.texi | 3 ++- mysql-test/t/delayed.test | 2 ++ scripts/mysql_install_db.sh | 2 +- sql-bench/crash-me.sh | 1 + sql/mysql_priv.h | 2 +- sql/mysqld.cc | 3 ++- sql/sql_class.cc | 3 ++- sql/sql_delete.cc | 2 +- sql/sql_insert.cc | 3 ++- tests/fork3_test.pl | 46 +++++++++++++++++++++++++++++++++---- 10 files changed, 56 insertions(+), 11 deletions(-) diff --git a/Docs/manual.texi b/Docs/manual.texi index a032c4f8e6d..4d9eb645c52 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -6618,6 +6618,7 @@ To install the @strong{MySQL} @code{DBD} module with ActiveState Perl on Windows, you should do the following: @itemize @bullet +@item Get activestate perl from @uref{http://www.activestate.com/Products/ActivePerl/index.html} and install it. @item Open a DOS shell. @item If required, set the HTTP_proxy variable. For example, you might try: @code{set HTTP_proxy=my.proxy.com:3128} @@ -33693,7 +33694,7 @@ If you find out something is wrong, please only send the relevant rows send the whole MyODBC or ODBC log file! If you are unable to find out what's wrong, the last option is to -make an archive (tar or zip) that contains a MyODBC log file, the ODBC +make an archive (tar or zip) that contains a MyODBC trace file, the ODBC log file, and a README file that explains the problem. You can send this to @uref{ftp://support.mysql.com/pub/mysql/secret}. Only we at MySQL AB will have access to the files you upload, and we will be very discrete diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test index 4bc1afa7612..6fbd99e3283 100644 --- a/mysql-test/t/delayed.test +++ b/mysql-test/t/delayed.test @@ -11,6 +11,7 @@ insert delayed into t1 set a = 4; insert delayed into t1 set a = 5, tmsp = 19711006010203; insert delayed into t1 (a, tmsp) values (6, 19711006010203); insert delayed into t1 (a, tmsp) values (7, NULL); +--sleep 1 insert into t1 set a = 8,tmsp=19711006010203; select * from t1 where tmsp=0; select * from t1 where tmsp=19711006010203; @@ -27,5 +28,6 @@ insert delayed into t1 values (null,"c"); insert delayed into t1 values (3,"d"),(null,"e"); --error 1136 insert delayed into t1 values (3,"this will give an","error"); +--sleep 2 select * from t1; drop table t1; diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 98e31cfe1ef..25a429f764a 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -282,7 +282,7 @@ fi echo "Installing all prepared tables" if eval "$execdir/mysqld $defaults --bootstrap --skip-grant-tables \ - --basedir=$basedir --datadir=$ldata --skip-innobase --skip-gemeni --skip-bdb $args" << END_OF_DATA + --basedir=$basedir --datadir=$ldata --skip-innobase --skip-gemini --skip-bdb $args" << END_OF_DATA use mysql; $c_d $i_d diff --git a/sql-bench/crash-me.sh b/sql-bench/crash-me.sh index f5d25a26ffb..014962b1c6d 100644 --- a/sql-bench/crash-me.sh +++ b/sql-bench/crash-me.sh @@ -47,6 +47,7 @@ require "$pwd/server-cfg" || die "Can't read Configuration file: $!\n"; $opt_server="mysql"; $opt_host="localhost"; $opt_database="test"; $opt_dir="limits"; +$opt_user=$opt_password=""; $opt_debug=$opt_help=$opt_Information=$opt_restart=$opt_force=$opt_quick=0; $opt_log_all_queries=$opt_fix_limit_file=$opt_batch_mode=0; $opt_db_start_cmd=""; # the db server start command diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index b9fd954486b..7348563cee6 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -477,7 +477,7 @@ extern uint32 server_id; extern char mysql_data_home[2],server_version[SERVER_VERSION_LENGTH], max_sort_char, mysql_real_data_home[]; extern my_string mysql_unix_port,mysql_tmpdir; -extern const char *first_keyword, *localhost; +extern const char *first_keyword, *localhost, *delayed_user; extern ulong refresh_version,flush_version, thread_id,query_id,opened_tables, created_tmp_tables, created_tmp_disk_tables, aborted_threads,aborted_connects, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 22e44b2b325..a25ac8bdbfb 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -243,6 +243,7 @@ volatile ulong cached_thread_count=0; my_string master_user = (char*) "test", master_password = 0, master_host=0, master_info_file = (char*) "master.info"; const char *localhost=LOCAL_HOST; +const char *delayed_user="DELAYED"; uint master_port = MYSQL_PORT, master_connect_retry = 60; ulong max_tmp_tables,max_heap_table_size; @@ -2364,7 +2365,7 @@ pthread_handler_decl(handle_connections_namedpipes,arg) continue; } /* host name is unknown */ - thd->host = my_strdup("localhost",MYF(0)); /* Host is unknown */ + thd->host = my_strdup(localhost,MYF(0)); /* Host is unknown */ create_new_thread(thd); } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index abe7fad822c..30eeb2e5e2c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -176,7 +176,8 @@ THD::~THD() if (host != localhost) // If not pointer to constant safeFree(host); - safeFree(user); + if (user != delayed_user) + safeFree(user); safeFree(db); safeFree(ip); free_root(&mem_root,MYF(0)); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index e1196341bef..fc150b08a69 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -192,7 +192,7 @@ int mysql_delete(THD *thd,TABLE_LIST *table_list,COND *conds,ha_rows limit, (void) table->file->extra(HA_EXTRA_NO_READCHECK); if (options & OPTION_QUICK) (void) table->file->extra(HA_EXTRA_QUICK); - init_read_record(&info,thd,table,select,1,1); + init_read_record(&info,thd,table,select,0,1); ulong deleted=0L; thd->proc_info="updating"; while (!(error=info.read_record(&info)) && !thd->killed) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 8e8f46b2e1f..e92c5255ef8 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -489,7 +489,8 @@ public: table(0),tables_in_use(0),stacked_inserts(0), status(0), dead(0), group_count(0) { - thd.user=0; thd.host=(char*) localhost; + thd.user=thd.priv_user=(char*) delayed_user; + thd.host=(char*) localhost; thd.current_tablenr=0; thd.version=refresh_version; thd.command=COM_DELAYED_INSERT; diff --git a/tests/fork3_test.pl b/tests/fork3_test.pl index 0ede221a7f4..032f1bf15e9 100755 --- a/tests/fork3_test.pl +++ b/tests/fork3_test.pl @@ -1,9 +1,9 @@ #!/usr/bin/perl -w # -# This is a test with uses 3 processes to insert, delete and select +# This is a test with uses 4 processes to insert, delete , check and select # -$opt_loop_count=100000; # Change this to make test harder/easier +$opt_loop_count=200000; # Change this to make test harder/easier ##################### Standard benchmark inits ############################## @@ -21,8 +21,8 @@ GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in","skip-delete", "verbose","fast-insert","lock-tables","debug","fast","force") || die "Aborted"; $opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these -print "Testing 3 multiple connections to a server with 1 insert, 1 delete\n"; -print "and 1 select connections.\n"; +print "Testing 4 multiple connections to a server with 1 insert, 1 delete\n"; +print "1 select and one repair/check connection.\n"; $firsttable = "bench_f1"; @@ -51,6 +51,7 @@ $|= 1; # Autoflush test_insert() if (($pid=fork()) == 0); $work{$pid}="insert"; test_delete() if (($pid=fork()) == 0); $work{$pid}="delete"; test_select() if (($pid=fork()) == 0); $work{$pid}="select1"; +repair_and_check() if (($pid=fork()) == 0); $work{$pid}="repair/check"; $errors=0; while (($pid=wait()) != -1) @@ -148,3 +149,40 @@ sub test_select print "Test_select: ok\n"; exit(0); } + +sub repair_and_check +{ + my ($dbh,$row,$found1,$last_found1,$i,$type, $table); + $found1=0; $last_found1= -1; + + $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", + $opt_user, $opt_password, + { PrintError => 0}) || die $DBI::errstr; + + for ($i=0; $found1 != $last_found1 ; $i++) + { + $type=($i & 2) ? "repair" : "check"; + $table=$firsttable; + $last_found1=$found1; + $sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $dbh->errstr\n"; + $sth->execute || die $dbh->errstr; + + while (($row=$sth->fetchrow_arrayref)) + { + if ($row->[3] ne "OK") + { + print "Got error " . $row->[3] . " when doing $type on $table\n"; + exit(1); + } + } + $sth=$dbh->prepare("select count(*) from $table") || die "Got error on prepare: $dbh->errstr\n"; + $sth->execute || die $dbh->errstr; + @row = $sth->fetchrow_array(); + $found1= $row[0]; + $sth->finish; + sleep(3); + } + $dbh->disconnect; $dbh=0; + print "check/repair: Did $i repair/checks\n"; + exit(0); +}