Commit 5100cda6 authored by unknown's avatar unknown

Merge tfr@work.mysql.com:/home/bk/mysql-4.0

into sarvik.tfr.cafe.ee:/usr/home/tfr/BK/mysql-4.0


Docs/manual.texi:
  Auto merged
parents bb1be56c 61aaf0f9
...@@ -1079,7 +1079,7 @@ to expand the MySQL business. ...@@ -1079,7 +1079,7 @@ to expand the MySQL business.
@menu @menu
* Business Services Support:: Support * Business Services Support:: Support
* Business Services Training:: Training * Business Services Training:: Training and Certification
* Business Services Consulting:: Consulting * Business Services Consulting:: Consulting
* Business Services Commercial licenses:: Commercial Licenses * Business Services Commercial licenses:: Commercial Licenses
* Business Services Partnering:: Partnering * Business Services Partnering:: Partnering
...@@ -1108,43 +1108,71 @@ Internet, please contact our sales staff at @email{sales@@mysql.com}. ...@@ -1108,43 +1108,71 @@ Internet, please contact our sales staff at @email{sales@@mysql.com}.
@node Business Services Training, Business Services Consulting, Business Services Support, MySQL AB business model and services @node Business Services Training, Business Services Consulting, Business Services Support, MySQL AB business model and services
@subsubsection Training @subsubsection Training and Certification
MySQL AB and its authorized training partners offer MySQL and related MySQL AB delivers MySQL and related training worldwide. We offer both
training on various levels all over the world. Our training material open courses and In-House courses tailored to specific needs of your
uses the same example databases as our documentation and our sample company. MySQL Training is also available through our partners, the
applications, and it is always updated to reflect the latest MySQL Authorized MySQL Training Centers.
version. Our trainers are backed by the development team to guarantee
the quality of the training and the continuous development of the Our training material uses the same example databases as our
course material. Also, this ensures that no questions raised during documentation and our sample applications, and it is always updated
the courses remain unanswered." to reflect the latest MySQL version. Our trainers are backed by the
development team to guarantee the quality of the training and the
If you're interested in our training as a potential participant or continuous development of the course material. This also ensures
that no questions raised during the courses remain unanswered.
Attending our training courses will enable you to achieve your goals
related to your MySQL applications. You will also:
@itemize @bullet
@item
Save time.
@item
Improve the performance of your application(s).
@item
Reduce or eliminate the need for additional hardware, decreasing cost.
@item
Enhance security.
@item
Increase customers and co-workers satisfaction.
@item
Prepare yourself for MySQL Certification.
@end itemize
If you are interested in our training as a potential participant or
training partner, please visit the training section at training partner, please visit the training section at
@uref{http://www.mysql.com/training/}. @uref{http://www.mysql.com/training/}.
If you have restricted access to the Internet, please contact our If you have restricted access to the Internet, please contact our
training staff at @email{training@@mysql.com}. training staff at @email{training@@mysql.com}.
We plan to release the MySQL Certification Program in 2002, for
details see @uref{http://www.mysql.com/training/certification.html}.
If you would like to be kept informed about the MySQL Certification
Program, please e-mail @email{certification@@mysql.com}.
@node Business Services Consulting, Business Services Commercial licenses, Business Services Training, MySQL AB business model and services @node Business Services Consulting, Business Services Commercial licenses, Business Services Training, MySQL AB business model and services
@subsubsection Consulting @subsubsection Consulting
MySQL AB offers consulting services to users of MySQL and to those who MySQL AB and its Authorised Partners offer consulting services to
embed MySQL in their own software, all over the world. Our consultants users of MySQL and to those who embed MySQL in their own software,
can help you design and tune your databases, construct efficient all over the world.
queries, tune your platform for optimal performance, resolve migration
issues, set up replication, build robust transactional applications, Our consultants can help you design and tune your databases, construct
and more. efficient queries, tune your platform for optimal performance, resolve
migration issues, set up replication, build robust transactional
applications, and more.
We also help customers embed MySQL in their products and applications We also help customers embed MySQL in their products and applications
for large-scale deployment. Our consultants work in close collaboration for large-scale deployment.
with our development team which ensures the technical quality of our
professional services. Our consultants work in close collaboration with our development team
which ensures the technical quality of our professional services.
Consulting assignments range from 2-day power start sessions to Consulting assignments range from 2-day power start sessions to
projects that span weeks and months. Our expertise does not only cover projects that span weeks and months. Our expertise does not only cover
MySQL, but extends into programming and scripting languages such as MySQL, but extends into programming and scripting languages such as
PHP, Perl and more. PHP, Perl and more.
If you're interested in our consulting services or want to become a If you are interested in our consulting services or want to become a
consulting partner, please visit the consulting section at consulting partner, please visit the consulting section of our website
@uref{http://www.mysql.com/consulting/}. at @uref{http://www.mysql.com/consulting/}.
If you have restricted access to the Internet, please contact our If you have restricted access to the Internet, please contact our
consulting staff at @email{consulting@@mysql.com}. consulting staff at @email{consulting@@mysql.com}.
...@@ -1217,6 +1245,10 @@ an email to @email{advertising@@mysql.com}. ...@@ -1217,6 +1245,10 @@ an email to @email{advertising@@mysql.com}.
@uref{http://www.mysql.com/, The MySQL website} @uref{http://www.mysql.com/, The MySQL website}
provides the latest information about MySQL and MySQL AB. provides the latest information about MySQL and MySQL AB.
For press service and inquiries not covered in our News releases
(@uref{http://www.mysql.com/news/}), please mail to
@email{press@@mysql.com}.
If you have a valid support contract with MySQL AB; you will get If you have a valid support contract with MySQL AB; you will get
timely, precise answers to your technical questions about MySQL. timely, precise answers to your technical questions about MySQL.
For more information, see @ref{Support}. For more information, see @ref{Support}.
...@@ -1230,6 +1262,12 @@ restricted access to the Internet, please contact the MySQL AB ...@@ -1230,6 +1262,12 @@ restricted access to the Internet, please contact the MySQL AB
training staff at @email{training@@mysql.com}. training staff at @email{training@@mysql.com}.
@xref{Business Services Training}. @xref{Business Services Training}.
For information on the MySQL Certification Program, please see
@uref{http://www.mysql.com/training/certification.html}.
If you would like to be kept informed about the MySQL Certification
Program, please e-mail @email{certification@@mysql.com}.
@xref{Business Services Training}.
If you're interested in consulting, please visit the consulting If you're interested in consulting, please visit the consulting
section at @uref{http://www.mysql.com/consulting/}. If you have section at @uref{http://www.mysql.com/consulting/}. If you have
restricted access to the Internet, please contact the MySQL AB restricted access to the Internet, please contact the MySQL AB
...@@ -3344,15 +3382,14 @@ server. ...@@ -3344,15 +3382,14 @@ server.
@menu @menu
* Standards:: What standards does MySQL follow? * Standards:: What standards does MySQL follow?
* ANSI mode:: Running MySQL in ANSI mode
* Extensions to ANSI:: MySQL extensions to ANSI SQL92 * Extensions to ANSI:: MySQL extensions to ANSI SQL92
* Differences from ANSI:: MySQL differences compared to ANSI SQL92 * Differences from ANSI:: MySQL differences compared to ANSI SQL92
* ANSI mode:: Running MySQL in ANSI mode
* Commit-rollback:: How to cope without @code{COMMIT}-@code{ROLLBACK}
* Bugs:: Known errors and design deficiencies in MySQL * Bugs:: Known errors and design deficiencies in MySQL
@end menu @end menu
@node Standards, Extensions to ANSI, Compatibility, Compatibility @node Standards, ANSI mode, Compatibility, Compatibility
@subsection What Standards Does MySQL Follow? @subsection What Standards Does MySQL Follow?
Entry level SQL92. ODBC levels 0-2. Entry level SQL92. ODBC levels 0-2.
...@@ -3361,7 +3398,40 @@ We are aiming towards supporting the full ANSI SQL99 standard, ...@@ -3361,7 +3398,40 @@ We are aiming towards supporting the full ANSI SQL99 standard,
but without concessions to speed and quality of the code. but without concessions to speed and quality of the code.
@node Extensions to ANSI, Differences from ANSI, Standards, Compatibility @node ANSI mode, Extensions to ANSI, Standards, Compatibility
@subsection Running MySQL in ANSI Mode
@cindex running, ANSI mode
@cindex ANSI mode, running
If you start @code{mysqld} with the @code{--ansi} option, the following
behavior of MySQL changes:
@itemize @bullet
@item
@code{||} is string concatenation instead of @code{OR}.
@item
You can have any number of spaces between a function name and the @samp{(}.
This forces all function names to be treated as reserved words.
@item
@samp{"} will be an identifier quote character (like the MySQL
@samp{`} quote character) and not a string quote character.
@item
@code{REAL} will be a synonym for @code{FLOAT} instead of a synonym of
@code{DOUBLE}.
@item
The default transaction isolation level is @code{SERIALIZABLE}.
@xref{SET TRANSACTION}.
@end itemize
This is the same as using @code{--sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,SERIALIZE,ONLY_FULL_GROUP_BY}.
@node Extensions to ANSI, Differences from ANSI, ANSI mode, Compatibility
@subsection MySQL Extensions to ANSI SQL92 @subsection MySQL Extensions to ANSI SQL92
@cindex hints @cindex hints
...@@ -3608,7 +3678,7 @@ SELECT @@t1:=(@@t2:=1)+@@t3:=4,@@t1,@@t2,@@t3; ...@@ -3608,7 +3678,7 @@ SELECT @@t1:=(@@t2:=1)+@@t3:=4,@@t1,@@t2,@@t3;
@end itemize @end itemize
@node Differences from ANSI, ANSI mode, Extensions to ANSI, Compatibility @node Differences from ANSI, Bugs, Extensions to ANSI, Compatibility
@subsection MySQL Differences Compared to ANSI SQL92 @subsection MySQL Differences Compared to ANSI SQL92
We try to make MySQL follow the ANSI SQL standard and the We try to make MySQL follow the ANSI SQL standard and the
...@@ -3616,10 +3686,6 @@ ODBC SQL standard, but in some cases MySQL does some things ...@@ -3616,10 +3686,6 @@ ODBC SQL standard, but in some cases MySQL does some things
differently: differently:
@itemize @bullet @itemize @bullet
@item
@code{--} is only a comment if followed by a white space. @xref{Missing
comments}.
@item @item
For @code{VARCHAR} columns, trailing spaces are removed when the value is For @code{VARCHAR} columns, trailing spaces are removed when the value is
stored. @xref{Bugs}. stored. @xref{Bugs}.
...@@ -3639,35 +3705,33 @@ This is because we don't think it's good to have to evaluate a lot of ...@@ -3639,35 +3705,33 @@ This is because we don't think it's good to have to evaluate a lot of
extra conditions in this case. extra conditions in this case.
@end itemize @end itemize
The following functionality is missing in the current version of
MySQL. For a prioritized list indicating when new extensions
may be added to MySQL, you should consult
@uref{http://www.mysql.com/documentation/manual.php?section=TODO, the
online MySQL TODO list}. That is the latest version of the TODO
list in this manual. @xref{TODO}.
@menu @menu
* Missing Sub-selects:: Sub-selects * ANSI diff Sub-selects:: Sub-@code{SELECT}s
* Missing SELECT INTO TABLE:: @code{SELECT INTO TABLE} * ANSI diff SELECT INTO TABLE:: @code{SELECT INTO TABLE}
* Missing Transactions:: Transactions * ANSI diff Transactions:: Transactions and Atomic Operations
* Missing Triggers:: Triggers * ANSI diff Triggers:: Stored Procedures and Triggers
* Missing Foreign Keys:: Foreign Keys * ANSI diff Foreign Keys:: Foreign Keys
* Broken Foreign KEY:: Why We Did Not Implement Foreign Keys * ANSI diff Views:: Views
* Missing Views:: Views * ANSI diff comments:: @samp{--} as the Start of a Comment
* Missing comments:: @samp{--} as the start of a comment
@end menu @end menu
For a prioritized list indicating when new extensions will be added to
MySQL, you should consult the online MySQL TODO list at
@uref{http://www.mysql.com/documentation/manual.php?section=TODO}.
That is the latest version of the TODO list in this manual. @xref{TODO}.
@node Missing Sub-selects, Missing SELECT INTO TABLE, Differences from ANSI, Differences from ANSI @node ANSI diff Sub-selects, ANSI diff SELECT INTO TABLE, Differences from ANSI, Differences from ANSI
@subsubsection Sub-selects @subsubsection Sub-@code{SELECT}s
@cindex sub-selects @cindex sub-selects
MySQL currently only supports sub selects of the form @code{INSERT MySQL currently only supports nested queries of the form @code{INSERT
... SELECT ...} and @code{REPLACE ... SELECT ...}. You can however use ... SELECT ...} and @code{REPLACE ... SELECT ...}. You can however use
the function @code{IN()} in other contexts. the function @code{IN()} in other contexts.
Sub-selects are scheduled for implementation in Version 4.x.
In many cases you can rewrite the query without a sub-select: Meanwhile, you can often rewrite the query without a sub-select:
@example @example
SELECT * FROM table1 WHERE id IN (SELECT id FROM table2); SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
...@@ -3727,7 +3791,8 @@ MySQL 4.0 supports multi-table deletes that can be used to efficiently ...@@ -3727,7 +3791,8 @@ MySQL 4.0 supports multi-table deletes that can be used to efficiently
delete rows based on information from one table or even from many tables delete rows based on information from one table or even from many tables
at the same time. at the same time.
@node Missing SELECT INTO TABLE, Missing Transactions, Missing Sub-selects, Differences from ANSI
@node ANSI diff SELECT INTO TABLE, ANSI diff Transactions, ANSI diff Sub-selects, Differences from ANSI
@subsubsection @code{SELECT INTO TABLE} @subsubsection @code{SELECT INTO TABLE}
@findex SELECT INTO TABLE @findex SELECT INTO TABLE
...@@ -3743,126 +3808,203 @@ tblTemp1.fldOrder_ID > 100; ...@@ -3743,126 +3808,203 @@ tblTemp1.fldOrder_ID > 100;
@end example @end example
Alternatively, you can use @code{SELECT INTO OUTFILE...} or @code{CREATE Alternatively, you can use @code{SELECT INTO OUTFILE...} or @code{CREATE
TABLE ... SELECT} to solve your problem. TABLE ... SELECT}.
@node Missing Transactions, Missing Triggers, Missing SELECT INTO TABLE, Differences from ANSI @node ANSI diff Transactions, ANSI diff Triggers, ANSI diff SELECT INTO TABLE, Differences from ANSI
@subsubsection Transactions @subsubsection Transactions and Atomic Operations
@findex COMMIT
@findex ROLLBACK
@cindex transactions, support @cindex transactions, support
@cindex transaction-safe tables
@cindex tables, updating
@cindex updating, tables
@cindex @code{InnoDB} tables
@cindex @code{BDB} tables
As MySQL does nowadays support transactions, the following MySQL supports transactions with the @code{InnoDB} and @code{BDB}
discussion is only valid if you are only using the non-transaction-safe @code{Transactional table handlers}. @xref{Table types}.
table types. @xref{COMMIT}.
However, the non-transactional table types in MySQL such as
The question is often asked, by the curious and the critical, ``Why is @code{MyISAM} follow another paradigm for data integrity called
MySQL not a transactional database?'' or ``Why does MySQL ``@code{Atomic Operations}.'' Atomic operations often offer equal or
not support transactions?'' even better integrity with much better performance.
With MySQL supporting both paradigms, the user is able to decide if
MySQL has made a conscious decision to support another paradigm they need the speed of atomic operations or if they need to use
for data integrity, ``atomic operations.'' It is our thinking and transactional features in their applications. This choice can be made
experience that atomic operations offer equal or even better integrity on a per-table basis.
with much better performance. We, nonetheless, appreciate and understand
the transactional database paradigm and plan, within the next few releases,
to introduce transaction-safe tables on a per table basis. We will be
giving our users the possibility to decide if they need the speed of
atomic operations or if they need to use transactional features in their
applications.
How does one use the features of MySQL to maintain rigorous integrity How does one use the features of MySQL to maintain rigorous integrity
and how do these features compare with the transactional paradigm? and how do these features compare with the transactional paradigm?
First, in the transactional paradigm, if your applications are written @enumerate
in a way that is dependent on the calling of ``rollback'' instead of @item
``commit'' in critical situations, then transactions are more In the transactional paradigm, if your applications are written in a
convenient. Moreover, transactions ensure that unfinished updates or way that is dependent on the calling of @code{ROLLBACK} instead of
@code{COMMIT} in critical situations, then transactions are more
convenient. Transactions also ensure that unfinished updates or
corrupting activities are not committed to the database; the server is corrupting activities are not committed to the database; the server is
given the opportunity to do an automatic rollback and your database is given the opportunity to do an automatic rollback and your database is
saved. saved.
MySQL, in almost all cases, allows you to solve for potential MySQL, in almost all cases, allows you to resolve potential problems
problems by including simple checks before updates and by running simple by including simple checks before updates and by running simple scripts
scripts that check the databases for inconsistencies and automatically that check the databases for inconsistencies and automatically repair
repair or warn if such occurs. Note that just by using the or warn if such an inconsistency occurs. Note that just by using the
MySQL log or even adding one extra log, one can normally fix MySQL log or even adding one extra log, one can normally fix tables
tables perfectly with no data integrity loss. perfectly with no data integrity loss.
Moreover, fatal transactional updates can be rewritten to be @item
atomic. In fact,we will go so far as to say that all integrity problems More often than not, fatal transactional updates can be rewritten to be
that transactions solve can be done with @code{LOCK TABLES} or atomic updates, atomic. Generally speaking, all integrity problems that transactions
ensuring that you never will get an automatic abort from the database, solve can be done with @code{LOCK TABLES} or atomic updates, ensuring
which is a common problem with transactional databases. that you never will get an automatic abort from the database, which is
a common problem with transactional databases.
Not even transactions can prevent all loss if the server goes down. In
such cases even a transactional system can lose data. The difference @item
between different systems lies in just how small the time-lap is where Even a transactional system can lose data if the server goes down.
they could lose data. No system is 100% secure, only ``secure The difference between different systems lies in just how small the
enough.'' Even Oracle, reputed to be the safest of transactional time-lap is where they could lose data. No system is 100% secure, only
databases, is reported to sometimes lose data in such situations. ``secure enough.'' Even Oracle, reputed to be the safest of
transactional databases, is reported to sometimes lose data in such
To be safe with MySQL, you only need to have backups and have situations.
the update logging turned on. With this you can recover from any
situation that you could with any transactional database. It is, of To be safe with MySQL, whether using transactional tables or not, you
course, always good to have backups, independent of which database you only need to have backups and have the update logging turned on. With
use. this you can recover from any situation that you could with any
other transactional database. It is, of course, always good to have
backups, independent of which database you use.
@end enumerate
The transactional paradigm has its benefits and its drawbacks. Many The transactional paradigm has its benefits and its drawbacks. Many
users and application developers depend on the ease with which they can users and application developers depend on the ease with which they
code around problems where an abort appears to be, or is necessary, and they can code around problems where an abort appears to be, or is necessary.
may have to do a little more work with MySQL to either think However, even if you are new to the atomic operations paradigm, or more
differently or write more. If you are new to the atomic operations familiar with transactions, do consider the speed benefit that
paradigm, or more familiar or more comfortable with transactions, do not non-transactional tables can offer, on the order of three to five times
jump to the conclusion that MySQL has not addressed these the speed of the fastest and most optimally tuned transactional tables.
issues. Reliability and integrity are foremost in our minds. Recent
estimates indicate that there are more than 1,000,000 @code{mysqld} servers In situations where integrity is of highest importance, MySQL offers
currently running, many of which are in production environments. We transaction-level or better reliability and integrity even for
hear very, very seldom from our users that they have lost any data, and non-transactional tables.
in almost all of those cases user error is involved. This is, in our If you lock tables with @code{LOCK TABLES}, all updates will stall
opinion, the best proof of MySQL's stability and reliability. until any integrity checks are made. If you only obtain a read lock
(as opposed to a write lock), then reads and inserts are still allowed
Lastly, in situations where integrity is of highest importance, to happen. The new inserted records will not be seen by any of the
MySQL's current features allow for transaction-level or better clients that have a @code{READ} lock until they release their read
reliability and integrity. If you lock tables with @code{LOCK TABLES}, all locks. With @code{INSERT DELAYED} you can queue inserts into a local
updates will stall until any integrity checks are made. If you only obtain queue, until the locks are released, without having the client wait
a read lock (as opposed to a write lock), then reads and inserts are for the insert to complete. @xref{INSERT DELAYED}.
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 ``Atomic,'' in the sense that we mean it, is nothing magical. It only
locks. With @code{INSERT DELAYED} you can queue inserts into a local queue, means that you can be sure that while each specific update is running,
until the locks are released, without having the client wait for the insert no other user can interfere with it, and there will never be an
to complete. @xref{INSERT DELAYED}. automatic rollback (which can happen with transactional tables if you
are not very careful). MySQL also guarantees that there will not be
``Atomic,'' in the sense that we mean it, is nothing magical. It only means any dirty reads.
that you can be sure that while each specific update is running, no other
user can interfere with it, and there will never be an automatic Following are some techniques for working with non-transactional tables:
rollback (which can happen on transaction based systems if you are not
very careful). MySQL also guarantees that there will not be @itemize @bullet
any dirty reads. You can find some example of how to write atomic updates @item
in the commit-rollback section. @xref{Commit-rollback}. Loops that need transactions normally can be coded with the help of
@code{LOCK TABLES}, and you don't need cursors when you can update
We have thought quite a bit about integrity and performance, and we records on the fly.
believe that our atomic operations paradigm allows for both high
reliability and extremely high performance, on the order of three to @item
five times the speed of the fastest and most optimally tuned of To avoid using @code{ROLLBACK}, you can use the following strategy:
transactional databases. We didn't leave out transactions because they
are hard to do. The main reason we went with atomic operations as @enumerate
opposed to transactions is that by doing this we could apply many speed @item
optimizations that would not otherwise have been possible. Use @code{LOCK TABLES ...} to lock all the tables you want to access.
@item
Many of our users who have speed foremost in their minds are not at all Test conditions.
concerned about transactions. For them transactions are not an @item
issue. For those of our users who are concerned with or have wondered Update if everything is okay.
about transactions vis-a-vis MySQL, there is a ``MySQL @item
way'' as we have outlined above. For those where safety is more Use @code{UNLOCK TABLES} to release your locks.
important than speed, we recommend them to use the @code{InnoDB}, @end enumerate
or @code{BDB} tables for all their critical data. @xref{Table types}.
This is usually a much faster method than using transactions with
One final note: We are currently working on a safe replication schema possible @code{ROLLBACK}s, although not always. The only situation
that we believe to be better than any commercial replication system we this solution doesn't handle is when someone kills the threads in the
know of. This system will work most reliably under the atomic middle of an update. In this case, all locks will be released but some
operations, non-transactional, paradigm. Stay tuned. of the updates may not have been executed.
@item
@node Missing Triggers, Missing Foreign Keys, Missing Transactions, Differences from ANSI You can also use functions to update records in a single operation.
You can get a very efficient application by using the following
techniques:
@itemize @bullet
@item Modify fields relative to their current value.
@item Update only those fields that actually have changed.
@end itemize
For example, when we are doing updates to some customer information, we
update only the customer data that has changed and test only that none of
the changed data, or data that depend on the changed data, has changed
compared to the original row. The test for changed data is done with the
@code{WHERE} clause in the @code{UPDATE} statement. If the record wasn't
updated, we give the client a message: "Some of the data you have changed
have been changed by another user". Then we show the old row versus the new
row in a window, so the user can decide which version of the customer record
he should use.
This gives us something that is similar to column locking but is actually
even better, because we only update some of the columns, using values that
are relative to their current values. This means that typical @code{UPDATE}
statements look something like these:
@example
UPDATE tablename SET pay_back=pay_back+'relative change';
UPDATE customer
SET
customer_date='current_date',
address='new address',
phone='new phone',
money_he_owes_us=money_he_owes_us+'new_money'
WHERE
customer_id=id AND address='old address' AND phone='old phone';
@end example
As you can see, this is very efficient and works even if another client
has changed the values in the @code{pay_back} or @code{money_he_owes_us}
columns.
@item
@findex mysql_insert_id()
@findex LAST_INSERT_ID()
In many cases, users have wanted @code{ROLLBACK} and/or @code{LOCK
TABLES} for the purpose of managing unique identifiers for some tables.
This can be handled much more efficiently by using an
@code{AUTO_INCREMENT} column and either the SQL function
@code{LAST_INSERT_ID()} or the C API function @code{mysql_insert_id()}.
@xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@cindex rows, locking
Generally, you can code around row-level locking. Some cases really
need it, but they are very few. For instance, you can use a flag
column in the table and do something like this:
@example
UPDATE tbl_name SET row_flag=1 WHERE id=ID;
@end example
MySQL returns 1 for the number of affected rows if the row was
found and @code{row_flag} wasn't already 1 in the original row.
You can think of it as MySQL changed the above query to:
@example
UPDATE tbl_name SET row_flag=1 WHERE id=ID and row_flag <> 1;
@end example
@end itemize
@node ANSI diff Triggers, ANSI diff Foreign Keys, ANSI diff Transactions, Differences from ANSI
@subsubsection Stored Procedures and Triggers @subsubsection Stored Procedures and Triggers
@cindex stored procedures and triggers, defined @cindex stored procedures and triggers, defined
...@@ -3882,14 +4024,13 @@ each time a record is deleted from a transaction table and that automatically ...@@ -3882,14 +4024,13 @@ each time a record is deleted from a transaction table and that automatically
deletes the corresponding customer from a customer table when all his deletes the corresponding customer from a customer table when all his
transactions are deleted. transactions are deleted.
The planned update language will be able to The planned update language will be able to handle stored procedures, but
handle stored procedures, but without triggers. Triggers usually slow without triggers. Triggers usually slow down everything, even queries for
down everything, even queries for which they are not needed. which they are not needed. To see when MySQL will get stored procedures,
see @ref{TODO}.
To see when MySQL might get stored procedures, see @ref{TODO}.
@node ANSI diff Foreign Keys, ANSI diff Views, ANSI diff Triggers, Differences from ANSI
@node Missing Foreign Keys, Broken Foreign KEY, Missing Triggers, Differences from ANSI
@subsubsection Foreign Keys @subsubsection Foreign Keys
@cindex foreign keys @cindex foreign keys
...@@ -3906,113 +4047,81 @@ SELECT * from table1,table2 where table1.id = table2.id; ...@@ -3906,113 +4047,81 @@ SELECT * from table1,table2 where table1.id = table2.id;
@xref{JOIN, , @code{JOIN}}. @xref{example-Foreign keys}. @xref{JOIN, , @code{JOIN}}. @xref{example-Foreign keys}.
The @code{FOREIGN KEY} syntax in MySQL exists only for compatibility In MySQL 3.23.44 and up, @code{InnoDB} tables supports checking of
with other SQL vendors' @code{CREATE TABLE} commands; it doesn't do foreign key constraints. @xref{InnoDB}. For other table types, MySQL
anything. The @code{FOREIGN KEY} syntax without @code{ON DELETE ...} is does parse the @code{FOREIGN KEY} syntax in @code{CREATE TABLE}
mostly used for documentation purposes. Some ODBC applications may use this commands, but without further action being taken.
The @code{FOREIGN KEY} syntax without @code{ON DELETE ...} is mostly
used for documentation purposes. Some ODBC applications may use this
to produce automatic @code{WHERE} clauses, but this is usually easy to to produce automatic @code{WHERE} clauses, but this is usually easy to
override. @code{FOREIGN KEY} is sometimes used as a constraint check, but override. @code{FOREIGN KEY} is sometimes used as a constraint check,
this check is unnecessary in practice if rows are inserted into the tables in but this check is unnecessary in practice if rows are inserted into the
the right order. MySQL only supports these clauses because some tables in the right order.
applications require them to exist (regardless of whether or not they
work). In MySQL, you can work around the problem of @code{ON DELETE ...} not
being implemented by adding the appropriate @code{DELETE} statement to
In MySQL, you can work around the problem of @code{ON DELETE an application when you delete records from a table that has a foreign
...} not being implemented by adding the appropriate @code{DELETE} statement to key. In practice this is as quick (in some cases quicker) and much more
an application when you delete records from a table that has a foreign key. portable than using foreign keys.
In practice this is as quick (in some cases quicker) and much more portable
than using foreign keys.
In MySQL 4.0 you can use multi-table delete to delete rows from many In MySQL 4.0 you can use multi-table delete to delete rows from many
tables with one command. @xref{DELETE}. tables with one command. @xref{DELETE}.
In the near future we will extend the @code{FOREIGN KEY} implementation so In the near future we will extend the @code{FOREIGN KEY} implementation
that at least the information will be saved in the table specification file so that the information will be saved in the table specification file
and may be retrieved by @code{mysqldump} and ODBC. At a later stage we will and may be retrieved by @code{mysqldump} and ODBC. At a later stage we
implement the foreign key constraints for application that can't easily be will implement the foreign key constraints for applications that can't
coded to avoid them. easily be coded to avoid them.
In MySQL 3.23.44 and up, InnoDB tables supports checking of foreign
key constraints. @xref{InnoDB}.
@menu
* Broken Foreign KEY:: Reasons NOT to use foreign keys constraints
@end menu
@node Broken Foreign KEY, Missing Views, Missing Foreign Keys, Differences from ANSI
@subsubsection Why We Did Not Implement Foreign Keys
@cindex foreign keys, why not implemented
Many database scholars and programmers feel very strongly that
referential integrity should be enforced inside the database server. Indeed,
in many cases, this approach is very helpful. However, in talking with many
database users we have observed that foreign keys are often misused, which
can cause severe problems. Even when used properly, it is not a
magic solution for the referential integrity problem, although it does make
things easier in some cases.
Because of the above observations, we did not assign implementing foreign Do keep in mind that foreign keys are often misused, which can cause
keys a high priority. Our user base consisted of mostly of developers who severe problems. Even when used properly, it is not a magic solution for
did not mind enforcing referential integerity inside the application code, the referential integrity problem, although it does make things easier
and in fact, preferred to do it that way because it gave them more control. in some cases.
However, in the last couple of years, our user base has expanded a great deal
and we now have many users who would like to have the enforced referential
integrity support inside MySQL. So we will implement the foreign keys in
the near future, although at this point we cannot provide a definite
delivery date.
Some advantages of foreign key enforcement: Some advantages of foreign key enforcement:
@itemize @bullet @itemize @bullet
@item @item
Assuming proper design of the relations, foreign key constraints will make it Assuming proper design of the relations, foreign key constraints will
more difficult for a programmer to introduce an inconsistency into the make it more difficult for a programmer to introduce an inconsistency
database into the database.
@item @item
Using cascading updates and deletes can simplify the client code Using cascading updates and deletes can simplify the client code.
@item @item
Properly designed foreign key rules aid in documenting relations between Properly designed foreign key rules aid in documenting relations
tables between tables.
@end itemize @end itemize
Disadvantages: Disadvantages:
@itemize @bullet @itemize @bullet
@item @item
MySQL does not yet support enforced referential integrity, so if your Mistakes, that are easy to make in designing key relations, can cause
application depends on it, you will not be able to use it with MySQL until severe problems, for example, circular rules, or the wrong combination
we implement this feature. of cascading deletes.
@item @item
Mistakes, that are easy to make in designing key relations, can cause severe A properly written application will make sure internally that it is
problems, for example, circular rules, or the wrong combination of cascading not violating referential integrity constraints before proceding with
deletes. a query. Thus, additionaly checks on the database level will only slow
down performance for such application.
@item @item
A properly written application will make sure internally that it is not It is not uncommon for a DBA to make such a complex topology of
violating referential integrity constraints before proceding with a query. relations that it becomes very difficult, and in some cases impossible
Thus, additionaly checks on the database level will only slow down performance to backup or restore individual tables.
for such application.
@item
It is not uncommon for a DBA to make such a complex topology of relations that
it becomes very difficult, and in some cases impossible to backup or restore
individual tables.
@end itemize @end itemize
@node Missing Views, Missing comments, Broken Foreign KEY, Differences from ANSI @node ANSI diff Views, ANSI diff comments, ANSI diff Foreign Keys, Differences from ANSI
@subsubsection Views @subsubsection Views
@cindex views @cindex views
MySQL doesn't yet support views, but we plan to implement these It is planned to implement views in MySQL around Version 4.1.
to about 4.1.
Views are mostly useful for letting users access a set of relations as one Views are mostly useful for letting users access a set of relations as one
table (in read-only mode). Many SQL databases don't allow one to update table (in read-only mode). Many SQL databases don't allow one to update
...@@ -4020,16 +4129,16 @@ any rows in a view, but you have to do the updates in the separate tables. ...@@ -4020,16 +4129,16 @@ any rows in a view, but you have to do the updates in the separate tables.
As MySQL is mostly used in applications and on web system where As MySQL is mostly used in applications and on web system where
the application writer has full control on the database usage, most of the application writer has full control on the database usage, most of
our users haven't regarded views to be very important. (At least no one our users haven't regarded views to be very important.
has been interested enough in this to be prepared to finance the (At least no one has been interested enough in this to be prepared to
implementation of views). finance the implementation of views).
One doesn't need views in MySQL to restrict access to columns One doesn't need views in MySQL to restrict access to columns
as MySQL has a very sophisticated privilege as MySQL has a very sophisticated privilege system.
system. @xref{Privilege system}. @xref{Privilege system}.
@node Missing comments, , Missing Views, Differences from ANSI @node ANSI diff comments, , ANSI diff Views, Differences from ANSI
@subsubsection @samp{--} as the Start of a Comment @subsubsection @samp{--} as the Start of a Comment
@cindex comments, starting @cindex comments, starting
...@@ -4093,175 +4202,7 @@ shell> replace " #" " --" -- text-file-with-funny-comments.sql ...@@ -4093,175 +4202,7 @@ shell> replace " #" " --" -- text-file-with-funny-comments.sql
@end example @end example
@node ANSI mode, Commit-rollback, Differences from ANSI, Compatibility @node Bugs, , Differences from ANSI, Compatibility
@subsection Running MySQL in ANSI Mode
@cindex running, ANSI mode
@cindex ANSI mode, running
If you start @code{mysqld} with the @code{--ansi} option, the following
behavior of MySQL changes:
@itemize @bullet
@item
@code{||} is string concatenation instead of @code{OR}.
@item
You can have any number of spaces between a function name and the @samp{(}.
This forces all function names to be treated as reserved words.
@item
@samp{"} will be an identifier quote character (like the MySQL
@samp{`} quote character) and not a string quote character.
@item
@code{REAL} will be a synonym for @code{FLOAT} instead of a synonym of
@code{DOUBLE}.
@item
The default transaction isolation level is @code{SERIALIZABLE}.
@xref{SET TRANSACTION}.
@end itemize
This is the same as using @code{--sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,SERIALIZE,ONLY_FULL_GROUP_BY}.
@node Commit-rollback, Bugs, ANSI mode, Compatibility
@subsection How to Cope Without @code{COMMIT}/@code{ROLLBACK}
@findex COMMIT
@findex ROLLBACK
@cindex transaction-safe tables
@cindex tables, updating
@cindex updating, tables
@cindex @code{InnoDB} tables
@cindex @code{BDB} tables
The following mostly applies only for @code{ISAM}, @code{MyISAM}, and
@code{HEAP} tables. If you only use transaction-safe tables (@code{InnoDB},
or @code{BDB} tables) in an an update, you can do
@code{COMMIT} and @code{ROLLBACK} also with MySQL.
@xref{COMMIT}.
The problem with handling @code{COMMIT}-@code{ROLLBACK} efficiently with
the above table types would require a completely different table layout
than MySQL uses today. The table type would also need extra
threads that do automatic cleanups on the tables, and the disk usage
would be much higher. This would make these table types about 2-4 times
slower than they are today.
For the moment, we prefer implementing the SQL server language (something
like stored procedures). With this you would very seldom really need
@code{COMMIT}-@code{ROLLBACK.} This would also give much better performance.
Loops that need transactions normally can be coded with the help of
@code{LOCK TABLES}, and you don't need cursors when you can update records
on the fly.
We at TcX had a greater need for a real fast database than a 100%
general database. Whenever we find a way to implement these features without
any speed loss, we will probably do it. For the moment, there are many more
important things to do. Check the TODO for how we prioritize things at
the moment. (Customers with higher levels of support can alter this, so
things may be reprioritized.)
The current problem is actually @code{ROLLBACK}. Without
@code{ROLLBACK}, you can do any kind of @code{COMMIT} action with
@code{LOCK TABLES}. To support @code{ROLLBACK} with the above table
types, MySQL would have to be changed to store all old records
that were updated and revert everything back to the starting point if
@code{ROLLBACK} was issued. For simple cases, this isn't that hard to do
(the current @code{isamlog} could be used for this purpose), but it
would be much more difficult to implement @code{ROLLBACK} for
@code{ALTER/DROP/CREATE TABLE}.
To avoid using @code{ROLLBACK}, you can use the following strategy:
@enumerate
@item
Use @code{LOCK TABLES ...} to lock all the tables you want to access.
@item
Test conditions.
@item
Update if everything is okay.
@item
Use @code{UNLOCK TABLES} to release your locks.
@end enumerate
This is usually a much faster method than using transactions with possible
@code{ROLLBACK}s, although not always. The only situation this solution
doesn't handle is when someone kills the threads in the middle of an
update. In this case, all locks will be released but some of the updates may
not have been executed.
You can also use functions to update records in a single operation.
You can get a very efficient application by using the following techniques:
@itemize @bullet
@item Modify fields relative to their current value.
@item Update only those fields that actually have changed.
@end itemize
For example, when we are doing updates to some customer information, we
update only the customer data that has changed and test only that none of
the changed data, or data that depend on the changed data, has changed
compared to the original row. The test for changed data is done with the
@code{WHERE} clause in the @code{UPDATE} statement. If the record wasn't
updated, we give the client a message: "Some of the data you have changed
have been changed by another user". Then we show the old row versus the new
row in a window, so the user can decide which version of the customer record
he should use.
This gives us something that is similar to column locking but is actually
even better, because we only update some of the columns, using values that
are relative to their current values. This means that typical @code{UPDATE}
statements look something like these:
@example
UPDATE tablename SET pay_back=pay_back+'relative change';
UPDATE customer
SET
customer_date='current_date',
address='new address',
phone='new phone',
money_he_owes_us=money_he_owes_us+'new_money'
WHERE
customer_id=id AND address='old address' AND phone='old phone';
@end example
As you can see, this is very efficient and works even if another client has
changed the values in the @code{pay_back} or @code{money_he_owes_us} columns.
@findex mysql_insert_id()
@findex LAST_INSERT_ID()
In many cases, users have wanted @code{ROLLBACK} and/or @code{LOCK
TABLES} for the purpose of managing unique identifiers for some tables. This
can be handled much more efficiently by using an @code{AUTO_INCREMENT} column
and either the SQL function @code{LAST_INSERT_ID()} or the C API function
@code{mysql_insert_id()}. @xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@cindex rows, locking
At MySQL AB, we have never had any need for row-level locking
because we have always been able to code around it. Some cases really need
row locking, but they are very few. If you want row-level locking, you
can use a flag column in the table and do something like this:
@example
UPDATE tbl_name SET row_flag=1 WHERE id=ID;
@end example
MySQL returns 1 for the number of affected rows if the row was
found and @code{row_flag} wasn't already 1 in the original row.
You can think of it as MySQL changed the above query to:
@example
UPDATE tbl_name SET row_flag=1 WHERE id=ID and row_flag <> 1;
@end example
@node Bugs, , Commit-rollback, Compatibility
@subsection Known errors and design deficiencies in MySQL @subsection Known errors and design deficiencies in MySQL
@cindex bugs, known @cindex bugs, known
...@@ -7500,9 +7441,8 @@ release or the last stable release: ...@@ -7500,9 +7441,8 @@ release or the last stable release:
Normally, if you are beginning to use MySQL for the first time Normally, if you are beginning to use MySQL for the first time
or trying to port it to some system for which there is no binary or trying to port it to some system for which there is no binary
distribution, we recommend going with the stable release (currently distribution, we recommend going with the stable release (currently
Version @value{mysql_version}. Note that all MySQL releases are Version 3.23. Note that all MySQL releases are checked with the
checked with the MySQL benchmarks and an extensive test suite MySQL benchmarks and an extensive test suite before each release.
before each release.
@item @item
Otherwise, if you are running an old system and want to upgrade, but Otherwise, if you are running an old system and want to upgrade, but
...@@ -28988,8 +28928,8 @@ These limitations apply both when you run @code{mysql} interactively ...@@ -28988,8 +28928,8 @@ These limitations apply both when you run @code{mysql} interactively
and when you put commands in a file and tell @code{mysql} to read its and when you put commands in a file and tell @code{mysql} to read its
input from that file with @code{mysql < some-file}. input from that file with @code{mysql < some-file}.
MySQL doesn't support the @samp{--} ANSI SQL comment style. MySQL only supports the @samp{--} ANSI SQL comment style if it is
@xref{Missing comments}. followed by a space. @xref{ANSI diff comments}.
@node Reserved words, , Comments, Language Structure @node Reserved words, , Comments, Language Structure
...@@ -43,7 +43,7 @@ RSC=rc.exe ...@@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /G6 /MT /W3 /O2 /I "." /I "..\include" /D "NDEBUG" /D "DBUG_OFF" /D "_WINDOWS" /D "USE_TLS" /D "USE_OLD_FUNCTIONS" /FD /c # ADD CPP /nologo /G6 /MT /W3 /O2 /I "." /I "..\include" /D "NDEBUG" /D "DBUG_OFF" /D "_WINDOWS" /D "USE_TLS" /FD /c
# SUBTRACT CPP /YX # SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
...@@ -76,7 +76,7 @@ PostBuild_Cmds=copy release\libmysql.lib ..\lib_release ...@@ -76,7 +76,7 @@ PostBuild_Cmds=copy release\libmysql.lib ..\lib_release
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /G6 /MTd /W3 /Gm /ZI /Od /I "." /I "..\include" /D "_DEBUG" /D "_WINDOWS" /D "SAFE_MUTEX" /D "USE_TLS" /D "USE_OLD_FUNCTIONS" /FD /c # ADD CPP /nologo /G6 /MTd /W3 /Gm /ZI /Od /I "." /I "..\include" /D "_DEBUG" /D "_WINDOWS" /D "SAFE_MUTEX" /D "USE_TLS" /FD /c
# SUBTRACT CPP /YX # SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
...@@ -215,10 +215,6 @@ SOURCE=..\strings\longlong2str.c ...@@ -215,10 +215,6 @@ SOURCE=..\strings\longlong2str.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\manager.c
# End Source File
# Begin Source File
SOURCE=..\mysys\mf_casecnv.c SOURCE=..\mysys\mf_casecnv.c
# End Source File # End Source File
# Begin Source File # Begin Source File
......
...@@ -73,12 +73,4 @@ EXPORTS ...@@ -73,12 +73,4 @@ EXPORTS
mysql_odbc_escape_string mysql_odbc_escape_string
myodbc_remove_escape myodbc_remove_escape
mysql_thread_safe mysql_thread_safe
mysql_manager_init
mysql_manager_connect
mysql_manager_close
mysql_manager_command
mysql_manager_fetch_line
mysql_connect
mysql_create_db
mysql_drop_db
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment