MySqlTalk.com  

Go Back   MySqlTalk.com > MySQL > Documentation
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread
Old 06-08-2004, 03:01 AM   #1
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8 MySQL Standards Compliance

From http://dev.mysql.com/doc/mysql/en/Compatibility.html

1.8 MySQL Standards Compliance



This section describes how MySQL relates to the ANSI/ISO SQL standards. MySQL Server has many extensions to the SQL standard, and here you will find out what they are and how to use them. You will also find information about functionality missing from MySQL Server, and how to work around some differences.

The SQL standard has been evolving since 1986 and several versions exist. In this manual, ``SQL-92'' refers to the standard released in 1992, ``SQL:1999'' refers to the standard released in 1999, and ``SQL:2003'' refers to the current version of the standard. We use the phrase ``the SQL standard'' to mean the current version of the SQL Standard at any time.

Our goal is to not restrict MySQL Server usability for any usage without a very good reason for doing so. Even if we don't have the resources to perform development for every possible use, we are always willing to help and offer suggestions to people who are trying to use MySQL Server in new territories.

One of our main goals with the product is to continue to work toward compliance with the SQL standard, but without sacrificing speed or reliability. We are not afraid to add extensions to SQL or support for non-SQL features if this greatly increases the usability of MySQL Server for a large segment of our user base. The HANDLER interface in MySQL Server 4.0 is an example of this strategy. See section 14.1.3 HANDLER Syntax.

We will continue to support transactional and non-transactional databases to satisfy both mission-critical 24/7 usage and heavy Web or logging usage.

MySQL Server was originally designed to work with medium size databases (10-100 million rows, or about 100MB per table) on small computer systems. Today MySQL Server handles terabyte-size databases, but the code can also be compiled in a reduced version suitable for hand-held and embedded devices. The compact design of the MySQL server makes development in both directions possible without any conflicts in the source tree.

Currently, we are not targeting realtime support, although MySQL replication capabilities already offer significant functionality.

Database cluster support is planned through integration of our acquired NDB Cluster technology into a new storage engine, available early 2004.

We are also looking at providing XML support in the database server.


DISCUSS:
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:01 AM   #2
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.1 What Standards MySQL Follows

From http://dev.mysql.com/doc/mysql/en/Standards.html


1.8.1 What Standards MySQL Follows

We are aiming toward supporting the full ANSI/ISO SQL standard, but without making concessions to speed and quality of the code.

ODBC levels 0-3.51.
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:02 AM   #3
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.2 Selecting SQL Modes

From http://dev.mysql.com/doc/mysql/en/SQL_mode.html

1.8.2 Selecting SQL Modes

The MySQL server can operate in different SQL modes, and can apply these modes differentially for different clients. This allows applications to tailor server operation to their own requirements.

Modes define what SQL syntax MySQL should support and what kind of validation checks it should perform on the data. This makes it easier to use MySQL in a lot of different environments and to use MySQL together with other database servers.

You can set the default SQL mode by starting mysqld with the --sql-mode="modes" option. Beginning with MySQL 4.1, you can also change the mode after startup time by setting the sql_mode variable with a SET [SESSION|GLOBAL] sql_mode='modes' statement.

For more information on setting the server mode, see section 5.2.2 The Server SQL Mode.
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:03 AM   #4
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.3 Running MySQL in ANSI Mode

From http://dev.mysql.com/doc/mysql/en/ANSI_mode.html

1.8.3 Running MySQL in ANSI Mode



You can tell mysqld to use the ANSI mode with the --ansi startup option. See section 5.2.1 mysqld Command-Line Options.

Running the server in ANSI mode is the same as starting it with these options (specify the --sql_mode value on a single line):

--transaction-isolation=SERIALIZABLE--sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGN ORE_SPACE,ONLY_FULL_GROUP_BYIn MySQL 4.1, you can achieve the same effect with these two statements (specify the sql_mode value on a single line):

SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;SET GLOBAL sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_ SPACE,ONLY_FULL_GROUP_BY';See section 1.8.2 Selecting SQL Modes.

In MySQL 4.1.1, the sql_mode options shown can be also be set with this statement:

SET GLOBAL sql_mode='ansi';In this case, the value of the sql_mode variable will be set to all options that are relevant for ANSI mode. You can check the result like this:

mysql> SET GLOBAL sql_mode='ansi';mysql> SELECT @@global.sql_mode;
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:03 AM   #5
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.4 MySQL Extensions to Standard SQL

From http://dev.mysql.com/doc/mysql/en/Ex...s_to_ANSI.html

1.8.4 MySQL Extensions to Standard SQL

MySQL Server includes some extensions that you probably will not find in other SQL databases. Be warned that if you use them, your code will not be portable to other SQL servers. In some cases, you can write code that includes MySQL extensions, but is still portable, by using comments of the form /*! ... */. In this case, MySQL Server will parse and execute the code within the comment as it would any other MySQL statement, but other SQL servers will ignore the extensions. For example:

SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...If you add a version number after the `!' character, the syntax within the comment will be executed only if the MySQL version is equal to or newer than the specified version number:

CREATE /*!32302 TEMPORARY */ TABLE t (a INT);This means that if you have Version 3.23.02 or newer, MySQL Server will use the TEMPORARY keyword.

The following descriptions list MySQL extensions, organized by category.

Organization of data on disk MySQL Server maps each database to a directory under the MySQL data directory, and tables within a database to filenames in the database directory. This has a few implications:
  • Database names and table names are case sensitive in MySQL Server on operating systems that have case-sensitive filenames (such as most Unix systems). See section 10.2.2 Identifier Case Sensitivity.
  • You can use standard system commands to back up, rename, move, delete, and copy tables that are managed by the MyISAM or ISAM storage engines. For example, to rename a MyISAM table, rename the `.MYD', `.MYI', and `.frm' files to which the table corresponds.
Database, table, index, column, or alias names may begin with a digit (but may not consist solely of digits). General language syntax
  • Strings may be enclosed by either `"' or `'', not just by `''.
  • Use of `\' as an escape character in strings.
  • In SQL statements, you can access tables from different databases with the db_name.tbl_name syntax. Some SQL servers provide the same functionality but call this User space. MySQL Server doesn't support tablespaces such as used in statements like this: CREATE TABLE ralph.my_table...IN my_tablespace.
SQL statement syntax
  • The ANALYZE TABLE, CHECK TABLE, OPTIMIZE TABLE, and REPAIR TABLE statements.
  • The CREATE DATABASE and DROP DATABASE statements. See section 14.2.3 CREATE DATABASE Syntax.
  • The DO statement.
  • EXPLAIN SELECT to get a description of how tables are joined.
  • The FLUSH and RESET statements.
  • The SET statement. See section 14.5.3.1 SET Syntax.
  • The SHOW statement. See section 14.5.3 SET and SHOW Syntax.
  • Use of LOAD DATA INFILE. In many cases, this syntax is compatible with Oracle's LOAD DATA INFILE. See section 14.1.5 LOAD DATA INFILE Syntax.
  • Use of RENAME TABLE. See section 14.2.9 RENAME TABLE Syntax.
  • Use of REPLACE instead of DELETE + INSERT. See section 14.1.6 REPLACE Syntax.
  • Use of CHANGE col_name, DROP col_name, or DROP INDEX, IGNORE or RENAME in an ALTER TABLE statement. Use of multiple ADD, ALTER, DROP, or CHANGE clauses in an ALTER TABLE statement. See section 14.2.2 ALTER TABLE Syntax.
  • Use of index names, indexes on a prefix of a field, and use of INDEX or KEY in a CREATE TABLE statement. See section 14.2.5 CREATE TABLE Syntax.
  • Use of TEMPORARY or IF NOT EXISTS with CREATE TABLE.
  • Use of IF EXISTS with DROP TABLE.
  • You can drop multiple tables with a single DROP TABLE statement.
  • The ORDER BY and LIMIT clauses of the UPDATE and DELETE statements.
  • INSERT INTO ... SET col_name = ... syntax.
  • The DELAYED clause of the INSERT and REPLACE statements.
  • The LOW_PRIORITY clause of the INSERT, REPLACE, DELETE, and UPDATE statements.
  • Use of INTO OUTFILE and STRAIGHT_JOIN in a SELECT statement. See section 14.1.7 SELECT Syntax.
  • The SQL_SMALL_RESULT option in a SELECT statement.
  • You don't need to name all selected columns in the GROUP BY part. This gives better performance for some very specific, but quite normal queries. See section 13.9 Functions and Modifiers for Use with GROUP BY Clauses.
  • You can specify ASC and DESC with GROUP BY.
  • The ability to set variables in a statement with the := assignment operator: mysql> SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg -> FROM test_table;mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
Column types
  • The column types MEDIUMINT, SET, ENUM, and the different BLOB and TEXT types.
  • The column attributes AUTO_INCREMENT, BINARY, NULL, UNSIGNED, and ZEROFILL.
Functions and operators
  • To make it easier for users who come from other SQL environments, MySQL Server supports aliases for many functions. For example, all string functions support both standard SQL syntax and ODBC syntax.
  • MySQL Server understands the || and && operators to mean logical OR and AND, as in the C programming language. In MySQL Server, || and OR are synonyms, as are && and AND. Because of this nice syntax, MySQL Server doesn't support the standard SQL || operator for string concatenation; use CONCAT() instead. Because CONCAT() takes any number of arguments, it's easy to convert use of the || operator to MySQL Server.
  • Use of COUNT(DISTINCT list) where list has more than one element.
  • All string comparisons are case-insensitive by default, with sort ordering determined by the current character set (ISO-8859-1 Latin1 by default). If you don't like this, you should declare your columns with the BINARY attribute or use the BINARY cast, which causes comparisons to be done using the underlying character code values rather then a lexical ordering.
  • The % operator is a synonym for MOD(). That is, N % M is equivalent to MOD(N,M). % is supported for C programmers and for compatibility with PostgreSQL.
  • The =, <>, <= ,<, >=,>, <<, >>, <=>, AND, OR, or LIKE operators may be used in column comparisons to the left of the FROM in SELECT statements. For example: mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  • The LAST_INSERT_ID() function that returns the most recent AUTO_INCREMENT value. See section 13.8.3 Information Functions.
  • LIKE is allowed on numeric columns.
  • The REGEXP and NOT REGEXP extended regular expression operators.
  • CONCAT() or CHAR() with one argument or more than two arguments. (In MySQL Server, these functions can take any number of arguments.)
  • The BIT_COUNT(), CASE, ELT(), FROM_DAYS(), FORMAT(), IF(), PASSWORD(), ENCRYPT(), MD5(), ENCODE(), DECODE(), PERIOD_ADD(), PERIOD_DIFF(), TO_DAYS(), and WEEKDAY() functions.
  • Use of TRIM() to trim substrings. Standard SQL supports removal of single characters only.
  • The GROUP BY functions STD(), BIT_OR(), BIT_AND(), BIT_XOR(), and GROUP_CONCAT(). See section 13.9 Functions and Modifiers for Use with GROUP BY Clauses.
For a prioritized list indicating when new extensions will be added to MySQL Server, you should consult the online MySQL TODO list at http://dev.mysql.com/doc/mysql/en/TODO.html. That is the latest version of the TODO list in this manual. See section 1.6 MySQL and the Future (the TODO).
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:04 AM   #6
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.5 MySQL Differences from Standard SQL

From http://dev.mysql.com/doc/mysql/en/Di...from_ANSI.html

1.8.5 MySQL Differences from Standard SQL

We try to make MySQL Server follow the ANSI SQL standard and the ODBC SQL standard, but MySQL Server performs operations differently in some cases:
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:05 AM   #7
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.5.1 Subqueries

From http://dev.mysql.com/doc/mysql/en/AN...ubqueries.html

1.8.5.1 Subqueries

MySQL 4.1 supports subqueries and derived tables. A ``subquery'' is a SELECT statement nested within another statement. A ``derived table'' (an unnamed view) is a subquery in the FROM clause of another statement. See section 14.1.8 Subquery Syntax.

For MySQL versions older than 4.1, most subqueries can be rewritten using joins or other methods. See section 14.1.8.11 Rewriting Subqueries as Joins for Earlier MySQL Versions for examples that show how to do this.
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:05 AM   #8
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.5.2 Select Into Table

From http://dev.mysql.com/doc/mysql/en/AN...NTO_TABLE.html

1.8.5.2 SELECT INTO TABLE



MySQL Server doesn't support the Sybase SQL extension: SELECT ... INTO TABLE .... Instead, MySQL Server supports the standard SQL syntax INSERT INTO ... SELECT ..., which is basically the same thing. See section 14.1.4.1 INSERT ... SELECT Syntax.

INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;Alternatively, you can use SELECT INTO OUTFILE ... or CREATE TABLE ... SELECT.

From version 5.0, MySQL supports SELECT ... INTO with user variables. The same syntax may also be used inside stored procedures using cursors and local variables. See section 20.1.6.3 SELECT ... INTO Statement.

Last edited by Administrator : 06-08-2004 at 03:11 AM.
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:06 AM   #9
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.5.3 Transactions and Atomic Operations

From http://dev.mysql.com/doc/mysql/en/AN...nsactions.html

1.8.5.3 Transactions and Atomic Operations



MySQL Server (version 3.23-max and all versions 4.0 and above) supports transactions with the InnoDB and BDB transactional storage engines. InnoDB provides full ACID compliance. See section 15 MySQL Storage Engines and Table Types.

The other non-transactional storage engines in MySQL Server (such as MyISAM) follow a different paradigm for data integrity called ``atomic operations.'' In transactional terms, MyISAM tables effectively always operate in AUTOCOMMIT=1 mode. Atomic operations often offer comparable integrity with higher performance.

With MySQL Server supporting both paradigms, you can decide whether your applications are best served by the speed of atomic operations or the use of transactional features. This choice can be made on a per-table basis.

As noted, the trade-off for transactional versus non-transactional table types lies mostly in performance. Transactional tables have significantly higher memory and diskspace requirements, and more CPU overhead. On the other hand, transactional table types such as InnoDB also offer many significant features. MySQL Server's modular design allows the concurrent use of different storage engines to suit different requirements and deliver optimum performance in all situations.

But how do you use the features of MySQL Server to maintain rigorous integrity even with the non-transactional MyISAM tables, and how do these features compare with the transactional table types?
  1. If your applications are written in a way that is dependent on being able to call ROLLBACK rather than COMMIT in critical situations, transactions are more convenient. Transactions also ensure that unfinished updates or corrupting activities are not committed to the database; the server is given the opportunity to do an automatic rollback and your database is saved. If you use non-transactional tables, MySQL Server in almost all cases allows you to resolve potential problems by including simple checks before updates and by running simple scripts that check the databases for inconsistencies and automatically repair or warn if such an inconsistency occurs. Note that just by using the MySQL log or even adding one extra log, you can normally fix tables perfectly with no data integrity loss.
  2. More often than not, critical transactional updates can be rewritten to be atomic. Generally speaking, all integrity problems that transactions solve can be done with LOCK TABLES or atomic updates, ensuring that you never will get an automatic abort from the server, which is a common problem with transactional database systems.
  3. Even a transactional system can lose data if the server goes down. The difference between different systems lies in just how small the time-lag is where they could lose data. No system is 100% secure, only ``secure enough.'' Even Oracle, reputed to be the safest of transactional database systems, is reported to sometimes lose data in such situations. To be safe with MySQL Server, whether or not using transactional tables, you only need to have backups and have binary logging turned on. With this you can recover from any situation that you could with any other transactional database system. It is always good to have backups, regardless of which database system you use.
The transactional paradigm has its benefits and its drawbacks. Many users and application developers depend on the ease with which they can code around problems where an abort appears to be, or is necessary. However, even if you are new to the atomic operations paradigm, or more familiar with transactions, do consider the speed benefit that non-transactional tables can offer on the order of three to five times the speed of the fastest and most optimally tuned transactional tables.

In situations where integrity is of highest importance, MySQL Server offers transaction-level reliability and integrity even for non-transactional tables. If you lock tables with LOCK TABLES, all updates will stall until any integrity checks are made. If you obtain a READ LOCAL lock (as opposed to a write lock) for a table that allows concurrent inserts at the end of the table, reads are allowed, as are inserts by other clients. The new inserted records will not be seen by the client that has the read lock until it releases the lock. With 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. See section 14.1.4.2 INSERT DELAYED Syntax.

``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 user can interfere with it, and there will never be an automatic rollback (which can happen with transactional tables if you are not very careful). MySQL Server also guarantees that there will not be any dirty reads.

Following are some techniques for working with non-transactional tables:
  • Loops that need transactions normally can be coded with the help of LOCK TABLES, and you don't need cursors to update records on the fly.
  • To avoid using ROLLBACK, you can use the following strategy:
    1. Use LOCK TABLES to lock all the tables you want to access.
    2. Test the conditions that must be true before performing the update.
    3. Update if everything is okay.
    4. Use UNLOCK TABLES to release your locks.
    This is usually a much faster method than using transactions with possible rollbacks, 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:
    • Modify columns relative to their current value.
    • Update only those columns that actually have changed.
    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 depends on the changed data, has changed compared to the original row. The test for changed data is done with the WHERE clause in the UPDATE statement. If the record wasn't updated, we give the client a message: ``Some of the data you have changed has been changed by another user.'' Then we show the old row versus the new row in a window so that the user can decide which version of the customer record to 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 UPDATE statements look something like these: UPDATE tablename SET pay_back=pay_back+125;UPDATE customer SET customer_date='current_date', address='new address', phone='new phone', money_owed_to_us=money_owed_to_us-125 WHERE customer_id=id AND address='old address' AND phone='old phone';This is very efficient and works even if another client has changed the values in the pay_back or money_owed_to_us columns.
  • In many cases, users have wanted LOCK TABLES and/or ROLLBACK for the purpose of managing unique identifiers. This can be handled much more efficiently without locking or rolling back by using an AUTO_INCREMENT column and either the LAST_INSERT_ID() SQL function or the mysql_insert_id() C API function. See section 13.8.3 Information Functions. See section 21.2.3.32 mysql_insert_id(). You can generally code around the need for row-level locking. Some situations really do need it, and InnoDB tables support row-level locking. With MyISAM tables, you can use a flag column in the table and do something like the following: UPDATE tbl_name SET row_flag=1 WHERE id=ID;MySQL returns 1 for the number of affected rows if the row was found and row_flag wasn't already 1 in the original row. You can think of it as though MySQL Server changed the preceding query to: UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;

Last edited by Administrator : 06-08-2004 at 03:11 AM.
Administrator is offline   Fork this post Reply With Quote
Old 06-08-2004, 03:06 AM   #10
Administrator
Administrator
 
Join Date: Jun 2004
Posts: 383 Administrator is on a distinguished road
1.8.5.4 Stored Procedures and Triggers

From http://dev.mysql.com/doc/mysql/en/AN..._Triggers.html

1.8.5.4 Stored Procedures and Triggers



Stored procedures are implemented in MySQL version 5.0. See section 20 Stored Procedures and Functions.

Triggers are scheduled for implementation in MySQL version 5.1. A ``trigger'' is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you could set up a stored procedure that is triggered each time a record is deleted from a transactional table, and that stored procedure automatically deletes the corresponding customer from a customer table when all their transactions are deleted.
Administrator is offline   Fork this post Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Access, Excel and data of other formats to MySQL by Navicat NavicatGuy Articles 0 08-17-2004 01:08 AM
3.2 Entering Queries Administrator Documentation 0 06-09-2004 02:58 AM
1.4.3.2 Using the MySQL Software for Free Under GPL Administrator Documentation 0 06-08-2004 02:20 AM
1.2.2 The Main Features of MySQL Administrator Documentation 0 06-08-2004 01:55 AM
1.2 Overview of the MySQL Database Management System Administrator Documentation 0 06-07-2004 10:11 PM



All times are GMT -4. The time now is 06:29 AM.



Powered by: vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Google
  Web http://www.mysqltalk.com
DISCLAIMERS:
1. We have no commercial interest in this site.
Banner Ads and Subscriptions will only be used to help pay for hosting and maintenance costs.
2. MySQLTalk.com is NOT affiliated with MySQL AB in any way.
3. MySQLTalk.com is NOT endorsed by MySQL AB in any way.
4. Please do not post any content that is harmful to MySQL or MySQL AB, meaning no misleading or obsolete information will be tolerated.
Well-founded constructive criticism meant to help the community is permitted.
5. This website is founded with the goal of improving the MySQL community.
We not only tolerate newbies, we encourage them.
Please do not ask newbies to "read the manual".