Wednesday, August 28, 2013

Role of "innodb_fast_shutdown" (very useful for DBA) in case of MySQL Database Disaster

innodb_fast_shutdown - This is the Innodb shutdown mode and it is a Dynamic variable.

innodb_fast_shutdown=0; (slow shutdown)

If innodb_fast_shutdown is set to 0, the log files are purged when mysqld shuts down - larger files mean a longer shutdown time.

innodb_fast_shutdown=1 (default)
The default for innodb_fast_shutdown is 1, which means that the log files are not purged before a shutdown.

innodb_fast_shutdown=2 (Fast shutdown but may take longer startup)
A value is 2 simulates a crash, and at the next startup InnoDB will do a crash recovery.
This can be useful when testing to see approximately how long InnoDB takes to recover from a crash, to determine if the size of your log files is too large.

One Query: Two output

Using "SQL_CALC_FOUND_ROWS" with SELECT STATEMENT

Example:-

mysql> select * from test;
+---------------------+--------+---------+----------+
| triggerDate         | Medium | Serious | Critical |
+---------------------+--------+---------+----------+
| 2012-12-20 00:00:00 |     10 |      20 |       30 |
| 2012-12-21 00:00:00 |     10 |      20 |       30 |
| 2012-12-22 00:00:00 |     10 |      20 |       30 |
| 2013-01-22 00:00:00 |     10 |      20 |       30 |
| 2013-02-22 00:00:00 |     10 |      20 |       30 |
| 2013-03-22 00:00:00 |     10 |      20 |       30 |
| 2013-03-22 00:00:00 |     10 |      20 |       30 |
| 2013-03-21 00:00:00 |     10 |      20 |       30 |
+---------------------+--------+---------+----------+
8 rows in set (0.00 sec)

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM test limit 3;
+---------------------+--------+---------+----------+
| triggerDate         | Medium | Serious | Critical |
+---------------------+--------+---------+----------+
| 2012-12-20 00:00:00 |     10 |      20 |       30 |
| 2012-12-21 00:00:00 |     10 |      20 |       30 |
| 2012-12-22 00:00:00 |     10 |      20 |       30 |
+---------------------+--------+---------+----------+
3 rows in set (0.00 sec)

mysql> SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
|            8 |
+--------------+
1 row in set (0.00 sec)

**
SQL_CALC_FOUND_ROWS and FOUND_ROWS() can be useful in situations when you want to restrict the number of rows that a query returns, but also determine the number of rows in the full result set without running the query again. An example is a Web script that presents a paged display containing links to the pages that show other sections of a search result. Using FOUND_ROWS() enables you to determine how many other pages are needed for the rest of the result.