The MySQL Query Cache
705
The query cache works for
SELECT SQL_CALC_FOUND_ROWS ...
queries and stores a value that
is returned by a following
SELECT FOUND_ROWS()
query.
FOUND_ROWS()
[960]
returns the correct
value even if the preceding query was fetched from the cache because the number of found rows is
also stored in the cache. The
SELECT FOUND_ROWS()
query itself cannot be cached.
A query cannot be cached if it contains any of the functions shown in the following table.
BENCHMARK()
[957]
CONNECTION_ID()
[959]
CONVERT_TZ()
[918]
CURDATE()
[918]
CURRENT_DATE()
[918]
CURRENT_TIME()
[918]
CURRENT_TIMESTAMP()
[918]
CURTIME()
[918]
DATABASE()
[960]
ENCRYPT()
[955]
with one
parameter
FOUND_ROWS()
[960]
GET_LOCK()
[965]
LAST_INSERT_ID()
[961]
LOAD_FILE()
[890]
MASTER_POS_WAIT()
[966]
NOW()
[926]
RAND()
[912]
RELEASE_LOCK()
[967]
SLEEP()
[967]
SYSDATE()
[928]
UNIX_TIMESTAMP()
[931]
with no parameters
USER()
[964]
UUID()
[967]
A query also is not cached under these conditions:
• It refers to user-defined functions (UDFs) or stored functions.
• It refers to user variables or local stored program variables.
• It refers to tables in the
mysql
or
INFORMATION_SCHEMA
system database.
• It is of any of the following forms:
SELECT ... LOCK IN SHARE MODE
SELECT ... FOR UPDATE
SELECT ... INTO OUTFILE ...
SELECT ... INTO DUMPFILE ...
SELECT * FROM ... WHERE autoincrement_col IS NULL
The last form is not cached because it is used as the ODBC workaround for obtaining the last insert
ID value. See the Connector/ODBC section of
Chapter 20, Connectors and APIs
.
Statements within transactions that use
SERIALIZABLE
[1121]
isolation level also cannot be
cached because they use
LOCK IN SHARE MODE
locking.
• It was issued as a prepared statement, even if no placeholders were employed. For example, the
query used here is not cached:
char *my_sql_stmt = "SELECT a, b FROM table_c";
/* ... */
mysql_stmt_prepare(stmt, my_sql_stmt, strlen(my_sql_stmt));
See
Section 20.6.7, “C API Prepared Statements”
.
• It uses
TEMPORARY
tables.
• It does not use any tables.
• It generates warnings.
• The user has a column-level privilege for any of the involved tables.
8.6.3.2. Query Cache
SELECT
Options
Two query cache-related options may be specified in
SELECT
statements:
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...