Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Minor
-
Resolution: Incomplete
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Environment:Linux , Maria DB 5.5.29 , Innodb Table, latin1 character Set
Description
I am experiencing weird behaviour from my MySQL/MariaDB InnoDB/XtraDB. Recently switched to MariaDB 5.5.29 recently The switch made the server to perform lot better but I still have this problem.
One particular tables index seems to break every now and then. And after a while, it fixes it self or I have to run optimize table by myself. I am not able to figure out the exact reason why it happens and really tried of each bit I could to do a root cause analysis to fix the problem.
The table schema is as below.
Record counts : 51088827
CREATE TABLE `commprices` (
`brand_name` varchar(78) NOT NULL,
`product_code` char(20) NOT NULL,
`market_name` varchar(40) NOT NULL,
`source_name` varchar(12) NOT NULL,
`date` datetime NOT NULL,
`frequency` varchar(2) NOT NULL,
`average_price` decimal(20,4) DEFAULT NULL,
`arrivals` decimal(20,4) DEFAULT NULL,
`org_price` decimal(20,4) DEFAULT NULL,
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
PRIMARY KEY (`brand_name`,`product_code`,`market_name`,`source_name`,`date`,`frequency`),
KEY `icommprices_pcode_dt_freq` (`product_code`,`source_name`,`date`,`frequency`),
KEY `icommprices_pcode_dt_bname` (`brand_name`,`product_code`,`source_name`,`date`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Actual Problem :
=============
We have a SQL query which I can share if needed. The database server at times ignores the indexes and does for a full table scan randomly. The no. of rows fetched should be 599 when using the index. 52798095 records are fetched while doing a table scan. The order of index also differs in both these cases. I have attached the explain of the query when it uses the indexes and when it goes for a full table scan.
I am not able to generate this behavior at will thats why not able to find a solution for that. For time being we have addressed this issue by truncating the 80% of records. Kindly review this issue and let me know whats causing this strange behavior and what could be a possible solution for this.
Thanks,
Santhinesh
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Hi,
Execution plan depends on statistics that the server currently has for tables. In case of InnoDB, statistics can be re-collected in several cases, e.g. if the table data gets updated considerably, or if you run ANALYZE/OPTIMIZE, or on SHOW TABLE STATUS.
Since you are saying that the plan breaks and sometimes gets fixed on its own, most likely it is caused by the automatic statistics update.
To make sure of that, and to exclude this factor, please run
As a result, statistics should only be updated when ANALYZE TABLE (or OPTIMIZE TABLE) is ran or during first open of the tables, so you should have more control over the execution plan.
Please note that it might happen that without statistics auto update, you might observe a reverse problem with this or other queries: existing query plans can become non-optimal with time, since the optimizer will try to use outdated statistics. In this case you will need to run ANALYZE TABLE manually.
Please let us know if it helps. If it does not and you keep having the problem, please also provide the query itself, and output of SHOW KEYS IN <tablename> when the plan is bad, and when it's good again after you ran ANALYZE.