July 4, 2008

Recovering Innodb table Corruption

Posted by peter

Assume you’re running MySQL with Innodb tables and you’ve got crappy hardware, driver bug, kernel bug, unlucky power failure or some rare MySQL bug and some pages in Innodb tablespace got corrupted. In such cases Innodb will typically print something like this:

InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 7.
InnoDB: You may have to recover from a backup.
080703 23:46:16 InnoDB: Page dump in ascii and hex (16384 bytes):
… A LOT OF HEX AND BINARY DATA…
080703 23:46:16 InnoDB: Page checksum 587461377, prior-to-4.0.14-form checksum 772331632
InnoDB: stored checksum 2287785129, prior-to-4.0.14-form stored checksum 772331632
InnoDB: Page lsn 24 1487506025, low 4 bytes of lsn at page end 1487506025
InnoDB: Page number (if stored to page already) 7,
InnoDB: space id (if created with >= MySQL-4.1.1 and stored already) 6353
InnoDB: Page may be an index page where index id is 0 25556
InnoDB: (index “PRIMARY” of table “test”.”test”)
InnoDB: Database page corruption on disk or a failed

and crash with assertion failure.
So what can you do to recover such a table ?
[read more...]

July 3, 2008

How to load large files safely into InnoDB with LOAD DATA INFILE

Posted by Baron Schwartz

Recently I had a customer ask me about loading two huge files into InnoDB with LOAD DATA INFILE. The goal was to load this data on many servers without putting it into the binary log. While this is generally a fast way to load data (especially if you disable unique key checks and foreign key checks), I recommended against this. There are several problems with the very large transaction caused by the single statement. We didn’t want to split the file into pieces for the load for various reasons. However, I found a way to load the single file in chunks as though it were many small files, which avoided splitting the file and let us load with many transactions instead of one huge transaction.

[read more...]

May 24, 2008

INFORMATION_SCHEMA tables in the InnoDB pluggable storage engine

Posted by Baron Schwartz

Much has been written about the new InnoDB pluggable storage engine, which Innobase released at the MySQL conference last month. We've written posts ourselves about its fast index creation capabilities and the compressed row format, and how that affects performance. One of the nice things they added in this InnoDB release is INFORMATION_SCHEMA tables that show some status information about InnoDB. Here are the tables:

SQL:
  1. mysql> SHOW TABLES FROM INFORMATION_SCHEMA LIKE 'INNODB%';
  2. +----------------------------------------+
  3. | Tables_in_INFORMATION_SCHEMA (INNODB%) |
  4. +----------------------------------------+
  5. | INNODB_CMP                             |
  6. | INNODB_CMP_RESET                       |
  7. | INNODB_CMPMEM                          |
  8. | INNODB_CMPMEM_RESET                    |
  9. | INNODB_LOCK_WAITS                      |
  10. | INNODB_LOCKS                           |
  11. | INNODB_TRX                             |
  12. +----------------------------------------+

The _CMP tables show statistics about compression; they contain a lot of useful information about compression, decompression, memory management, fragmentation etc. Beware that selecting from the tables whose names contain RESET has a side effect: it resets the statistics back to 0.

There are also locks and transactions tables. A while ago, the InnoDB developers contacted me to ask my opinion about what would be useful to put in the INFORMATION_SCHEMA. I told them the single biggest thing I could not get from InnoDB at the time was visibility into which transactions are blocking others when there are lock waits. It appears that they agreed this was important to add. (I subsequently discovered that it is possible to find out more information on InnoDB locks even in the older versions of InnoDB, but it's not really easy.)

These tables are fully documented in the InnoDB plugin manual, along with extensive examples of how to use them to find out what is blocking what and so on. Note that the InnoDB plugin manual is being maintained on www.innodb.com, not as part of the regular MySQL manual.

May 1, 2008

Quickly preloading Innodb tables in the buffer pool

Posted by peter

In the previous post I mentioned a way I use to preload Clustered Index (data) for Innodb tables. Though I thought this topic would benefit from a bit more information.

But lest first start with feature request for Innodb Team: All ways I mention here are hacks and they can't be as efficient as native support. It would be great if Innodb would implement command to preload table to Innodb buffer pool, which would simply go through .ibd file sequentially and inject pages in the buffer pool. This would make preload done using sequential file scan even if indexed suffered a lot of page splits.

Now lets continue to the hacks :)
[read more...]

Learning about MySQL Table Fragmentation

Posted by peter

Recently I was working with the customer who need quick warmup - to get Innodb table fetched in memory as fast as possible to get good in memory access performance.

To do it I run the query: "SELECT count(*) FROM tbl WHERE non_idx_col=0" I use this particular form of query because it will do full table scan - running count(*) without where clause may pick to scan some small index instead.

If your table is not fragmented one of two things should happen - either you should be reading at your hard drive sequential read rate or you would see MySQL becoming CPU bound if IO subsystem is too fast.
[read more...]

April 26, 2008

How multiple disks can benefit for single client workload ?

Posted by peter

Let us talk few more about disks. You might have read my previous post and Matt's Reply and it looks like there are few more things to clarify and explain.

Before I get to main topic of the article lets comment on IO vs Disk question. If you look at Disk Based databases all data accesses are treated as IOs - it can be "logical" if they are cached or "phyiscal" if they require actual IO done but in the general sense all data accesses are IOs. If you use this terminology when most of the problems would come down to IO - making queries to touch fewer rows (or row portions) or having these "touches" resolved as logical IO rather than physical. There is still locking ,networking etc to deal with but it is minor story.

This is not however as Most of the people understand IO and as not as I typically use these terms. For me IO is IO bound workload - disks are moving and CPU sits idle. With such terminology there is instantly much smaller amount of cases are about IO because we would call cases when too much of logical IO is happening CPU bound. The beauty of this terminlogy (and so why I use it) - it is very easy to see if system is IO bound or CPU bound, while to understand if MySQL goes through more rows than it needs to requires look at the queries and schema.

Ok Let us new get to back to main point of the article.
[read more...]

April 23, 2008

Efficient Boolean value storage for Innodb Tables

Posted by peter

Sometimes you have the task of storing multiple of boolean values (yes/now or something similar) in the table and if you get many columns and many rows you may want to store them as efficient way as possible.
For MyISAM tables you could use BIT(1) fields which get combined together for efficient storage:

SQL:
  1. CREATE TABLE `bbool` (
  2.   `b1` bit(1) NOT NULL,
  3.   `b2` bit(1) NOT NULL,
  4.   `b3` bit(1) NOT NULL,
  5.   `b4` bit(1) NOT NULL,
  6.   `b5` bit(1) NOT NULL,
  7.   `b6` bit(1) NOT NULL,
  8.   `b7` bit(1) NOT NULL,
  9.   `b8` bit(1) NOT NULL,
  10.   `b9` bit(1) NOT NULL,
  11.   `b10` bit(1) NOT NULL
  12. ) ENGINE=MyISAM
  13.  
  14. mysql> SHOW TABLE STATUS LIKE 'bbool' \G
  15. *************************** 1. row ***************************
  16.            Name: bbool
  17.          Engine: MyISAM
  18.         Version: 10
  19.      Row_format: Fixed
  20.            Rows: 10
  21.  Avg_row_length: 7
  22.     Data_length: 70
  23. Max_data_length: 1970324836974591
  24.    Index_length: 1024
  25.       Data_free: 0
  26.  AUTO_INCREMENT: NULL
  27.     Create_time: 2008-04-24 00:41:01
  28.     Update_time: 2008-04-24 00:45:40
  29.      Check_time: NULL
  30.       Collation: latin1_swedish_ci
  31.        Checksum: NULL
  32.  Create_options:
  33.         Comment:
  34. 1 row IN SET (0.00 sec)

[read more...]

Real-Life Use Case for “Barracuda” InnoDB File Format

Posted by Alexey Kovyrin

In one of his recent posts Vadim already gave some information about possible benefits from using new InnoDB file format but in this post I'd like to share some real-life example how compression in InnoDB plugin could be useful for large warehousing tasks.

[read more...]

Testing InnoDB “Barracuda” format with compression

Posted by Vadim

New features of InnoDB - compression format and fast index creation sound so promising so I spent some time to research time and sizes on data we have on our production. The schema of one of shards is

SQL:
  1. CREATE TABLE `article87` (
  2.   `id` bigint(20) UNSIGNED NOT NULL,
  3.   `ext_key` varchar(32) NOT NULL,
  4.   `site_id` int(10) UNSIGNED NOT NULL,
  5.   `forum_id` int(10) UNSIGNED NOT NULL,
  6.   `thread_id` varchar(255) CHARACTER SET latin1 NOT NULL,
  7.   `published` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  8.   `crawled` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  9.   `subject` varchar(255) NOT NULL,
  10.   `title` varchar(255) NOT NULL,
  11.   `url` varchar(255) NOT NULL,
  12.   `num_links` smallint(6) NOT NULL,
  13.   `links_in` int(10) UNSIGNED NOT NULL,
  14.   `cache_author` varchar(255) NOT NULL,
  15.   `cache_site` varchar(255) DEFAULT NULL,
  16.   `anchor` varchar(255) NOT NULL,
  17.   `isthread` tinyint(3) UNSIGNED NOT NULL,
  18.   `author_id` int(10) UNSIGNED NOT NULL,
  19.   `inserted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  20.   `fromfile` varchar(255) NOT NULL,
  21.   `language_id` tinyint(3) UNSIGNED NOT NULL,
  22.   `encoding` varchar(255) NOT NULL,
  23.   `warning` mediumtext NOT NULL,
  24.   `is_thread_start` tinyint(3) UNSIGNED NOT NULL,
  25.   `source` mediumint(8) UNSIGNED NOT NULL,
  26.   `hash` char(32) NOT NULL,
  27.   `mod_is` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  28.   `is_adult` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  29.   `bodyuc` mediumtext NOT NULL,
  30.   PRIMARY KEY (`id`),
  31.  KEY `ext_key` (`ext_key`),
  32.  KEY `forum_id` (`forum_id`,`thread_id`,`published`),
  33.  KEY `site_id` (`site_id`,`published`),
  34.  KEY `hash` (`hash`),
  35.  KEY `forum_id_2` (`forum_id`,`is_thread_start`,`published`),
  36.  KEY `published` (`published`),
  37.  KEY `inserted` (`inserted`),
  38.  KEY `forum_id_3` (`forum_id`,`thread_id`,`is_thread_start`),
  39.  KEY `site_id_2` (`site_id`,`author_id`)
  40. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

[read more...]

April 20, 2008

MySQL and plugin binaries

Posted by Vadim

It seems there is interesting problem with compatibility of MySQL binaries and binaries of third-party plugins.

I personally found and there is confirmation from InnoDB team that current InnoDB-plugin binaries do not work with lastest 5.1.24-rc binaries. It was very charming move from MySQL side to release new incompatible binary on the second day after the announce of InnoDB plugin. I do not think it was intentional, but still looks funny and shows broken communication between teams.

The more interesting becomes from Sergei Golubchik presentation on MySQL Conference, where Sergei says that in current API "versioning binds a plugin binary to specific server release". That simply means that InnoDB has to release binary for each binary of MySQL. I suppose it should be changed, otherwise there will be total madness with versions - InnoDB 1.0.0 binary for MySQL 5.1.23, 5.1.24, ..., InnoDB 1.0.1 binary for MySQL 5.1.23, 5.1.24, 5.1.25... etc.

Even when that is fixed I am looking forward to have good mess with double versioning and problems like "
MySQL version 5.X.Y does not work with InnoDB version 1.N.M, you need to upgrade InnoDB to version 1.N1.M1 or MySQL to version 5.X1.Y1".


This page was found by: mysql performance bl... innodb plugin 1.0.1 ... mysql 5.1 bit effici... innodb mysql 5.1.25 innodb