Bug #88704 | Compound index (pkey) not used when it should be | ||
---|---|---|---|
Submitted: | 29 Nov 2017 23:24 | Modified: | 5 Dec 2017 13:32 |
Reporter: | Dan Parker | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 5.7.18-ndb-7.6.3-cluster-gpl | OS: | Red Hat |
Assigned to: | CPU Architecture: | Any |
[29 Nov 2017 23:24]
Dan Parker
[30 Nov 2017 19:06]
Dan Parker
As a convenience, I'm adding the following procedure definition that I've been using to populate 'MyTable' with test data in order to reproduce this issue: [code] DELIMITER // CREATE PROCEDURE PopMyTable( IN RowCount BIGINT UNSIGNED ) BEGIN DECLARE DateTimeColVal DATETIME(0); DECLARE CharColVal CHAR(20); DECLARE TempCharColVal CHAR(20); DECLARE CharColIntVal BIGINT UNSIGNED; DECLARE InsertRowCount BIGINT UNSIGNED; DECLARE TotalRowCount BIGINT UNSIGNED; SET autocommit = 1; SET @TotalRowCount = 0; SET @DateTimeColVal = SUBTIME( '2017-11-30 00:00:00', SEC_TO_TIME( RowCount ) ); SET @CharColIntVal = 2; SET @CharColVal = "00000000000000000001"; PREPARE InsertRow FROM 'INSERT INTO MyTable VALUES (?, ?, 0, 0)'; ArcLoop: REPEAT EXECUTE InsertRow USING @DateTimeColVal, @CharColVal; SELECT ROW_COUNT() INTO @InsertRowCount; IF @InsertRowCount < 1 THEN LEAVE ArcLoop; END IF; SET @TotalRowCount = (@TotalRowCount + 1); SET @DateTimeColVal = ADDTIME( @DateTimeColVal, SEC_TO_TIME( 1 ) ); SET @TempCharColVal = CAST( @CharColIntVal AS CHAR); SET @CharColVal = CONCAT( SUBSTRING( "00000000000000000000", 1, 20 - CHAR_LENGTH( @TempCharColVal ) ), @TempCharColVal ); SET @CharColIntVal = (@CharColIntVal + 1); UNTIL @TotalRowCount >= RowCount END REPEAT ArcLoop; DEALLOCATE PREPARE InsertRow; END// DELIMITER ; [/code]
[5 Dec 2017 13:32]
MySQL Verification Team
Hi! Thank you for your report. However, it is not a bug. If you read carefully the EXPLAIN output, you will see that it specified "use index" in the "Extra" column. That means that the index is not only used for range searching, but also, for optimising ORDER BY, so that filesort is not used. This has the negative effect that speed of execution will depend on the location of the tuples that satisfy the WHERE clause. Optimiser can not know that when it is making a plan. However, you can switch off the scanning of the index for the ORDER BY optimisation, by using the optimiser hints, as described in the chapter 8.9.2 or our Reference Manual. Pay especially the attention to the hing dealing with "IGNORE INDEX FOR ORDER BY". Not a bug.