MySQL poor select query performance despite indexes2019 Community Moderator ElectionHow to output MySQL query results in CSV format?MySQL - UPDATE query based on SELECT QueryHow do I add indices to MySQL tables?Add Foreign Key to existing tablecreating mysql indexOptimizing MySQL Count query with multiple joinsMySQL Refusing to Use Index for Simple QueryMYSQL Query Performance with Distinct, order by and limit against same tablemysql performs full table scan even though index existsPoor query performance with index compared to without index
Sort array by month and year
Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?
Why does a car's steering wheel get lighter with increasing speed
What is the oldest European royal house?
Mixed Feelings - What am I
Is it appropriate to ask a former professor to order a library book for me through ILL?
Unfamiliar notation in Diabelli's "Duet in D" for piano
Is the differential, dp, exact or not?
Why aren't there more Gauls like Obelix?
Short SF story. Females use stingers to implant eggs in yearfathers
Are small insurances worth it?
Do I need a return ticket to Canada if I'm a Japanese National?
How to distinguish easily different soldier of ww2?
Rationale to prefer local variables over instance variables?
Boss Telling direct supervisor I snitched
How would an energy-based "projectile" blow up a spaceship?
How does learning spells work when leveling a multiclass character?
What is the purpose of a disclaimer like "this is not legal advice"?
Use Mercury as quenching liquid for swords?
Vector-transposing function
Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?
Is it a Cyclops number? "Nobody" knows!
What would be the most expensive material to an intergalactic society?
Averaging over columns while ignoring zero entries
MySQL poor select query performance despite indexes
2019 Community Moderator ElectionHow to output MySQL query results in CSV format?MySQL - UPDATE query based on SELECT QueryHow do I add indices to MySQL tables?Add Foreign Key to existing tablecreating mysql indexOptimizing MySQL Count query with multiple joinsMySQL Refusing to Use Index for Simple QueryMYSQL Query Performance with Distinct, order by and limit against same tablemysql performs full table scan even though index existsPoor query performance with index compared to without index
We have two tables, messages and customercontracts defined as follows:
create table customercontracts (customer_id varchar(20),
contractnumber varchar(20),
role varchar(4));
alter table customercontracts add index contractnumber (contractnumber);
create table messages (customer_id varchar(20),
contractnumber varchar(20),
message varchar(400));
alter table messages add index contractnumber (contractnumber);
alter table messages add index customer_id (customer_id );
And a query like this:
select * from messages m, customercontracts c
where m.customer_id = '12345'
and c.contractnumber = m.contractnumber;
There are approximately 4,000 messages rows and 3,000,000 customercontracts rows. The above query takes approximately 4 seconds to execute despite there being indexes on both customer_id and contractnumber. 'Explain' (in MySQL Workbench) shows a full table scan on customercontracts and a query cost of 628,000.
Questions:
1) Why is there a full table scan on customercontracts when I have indexes on these tables? What is the cause of the poor performance?
2) How can I rewrite this query to be performant?
mysql
add a comment |
We have two tables, messages and customercontracts defined as follows:
create table customercontracts (customer_id varchar(20),
contractnumber varchar(20),
role varchar(4));
alter table customercontracts add index contractnumber (contractnumber);
create table messages (customer_id varchar(20),
contractnumber varchar(20),
message varchar(400));
alter table messages add index contractnumber (contractnumber);
alter table messages add index customer_id (customer_id );
And a query like this:
select * from messages m, customercontracts c
where m.customer_id = '12345'
and c.contractnumber = m.contractnumber;
There are approximately 4,000 messages rows and 3,000,000 customercontracts rows. The above query takes approximately 4 seconds to execute despite there being indexes on both customer_id and contractnumber. 'Explain' (in MySQL Workbench) shows a full table scan on customercontracts and a query cost of 628,000.
Questions:
1) Why is there a full table scan on customercontracts when I have indexes on these tables? What is the cause of the poor performance?
2) How can I rewrite this query to be performant?
mysql
can you pls verify MySQL take the index if you exec:**SELECT * from customercontracts c WHERE c.contractnumber = VALIDNUMBER**
– Bernd Buffen
2 days ago
The PRIMARY KEY is unclear. Please clarify.
– Strawberry
2 days ago
@Strawberry - Apologies, the table definitions are simplified. The primary key is another column (not included). contract number and customer_id are separate non-unique keys (using BTREE). The data is highly unique on both tables.
– Chris Knight
2 days ago
@BerndBuffen - Yes, index is used for that statement
– Chris Knight
2 days ago
add a comment |
We have two tables, messages and customercontracts defined as follows:
create table customercontracts (customer_id varchar(20),
contractnumber varchar(20),
role varchar(4));
alter table customercontracts add index contractnumber (contractnumber);
create table messages (customer_id varchar(20),
contractnumber varchar(20),
message varchar(400));
alter table messages add index contractnumber (contractnumber);
alter table messages add index customer_id (customer_id );
And a query like this:
select * from messages m, customercontracts c
where m.customer_id = '12345'
and c.contractnumber = m.contractnumber;
There are approximately 4,000 messages rows and 3,000,000 customercontracts rows. The above query takes approximately 4 seconds to execute despite there being indexes on both customer_id and contractnumber. 'Explain' (in MySQL Workbench) shows a full table scan on customercontracts and a query cost of 628,000.
Questions:
1) Why is there a full table scan on customercontracts when I have indexes on these tables? What is the cause of the poor performance?
2) How can I rewrite this query to be performant?
mysql
We have two tables, messages and customercontracts defined as follows:
create table customercontracts (customer_id varchar(20),
contractnumber varchar(20),
role varchar(4));
alter table customercontracts add index contractnumber (contractnumber);
create table messages (customer_id varchar(20),
contractnumber varchar(20),
message varchar(400));
alter table messages add index contractnumber (contractnumber);
alter table messages add index customer_id (customer_id );
And a query like this:
select * from messages m, customercontracts c
where m.customer_id = '12345'
and c.contractnumber = m.contractnumber;
There are approximately 4,000 messages rows and 3,000,000 customercontracts rows. The above query takes approximately 4 seconds to execute despite there being indexes on both customer_id and contractnumber. 'Explain' (in MySQL Workbench) shows a full table scan on customercontracts and a query cost of 628,000.
Questions:
1) Why is there a full table scan on customercontracts when I have indexes on these tables? What is the cause of the poor performance?
2) How can I rewrite this query to be performant?
mysql
mysql
asked 2 days ago
Chris KnightChris Knight
154
154
can you pls verify MySQL take the index if you exec:**SELECT * from customercontracts c WHERE c.contractnumber = VALIDNUMBER**
– Bernd Buffen
2 days ago
The PRIMARY KEY is unclear. Please clarify.
– Strawberry
2 days ago
@Strawberry - Apologies, the table definitions are simplified. The primary key is another column (not included). contract number and customer_id are separate non-unique keys (using BTREE). The data is highly unique on both tables.
– Chris Knight
2 days ago
@BerndBuffen - Yes, index is used for that statement
– Chris Knight
2 days ago
add a comment |
can you pls verify MySQL take the index if you exec:**SELECT * from customercontracts c WHERE c.contractnumber = VALIDNUMBER**
– Bernd Buffen
2 days ago
The PRIMARY KEY is unclear. Please clarify.
– Strawberry
2 days ago
@Strawberry - Apologies, the table definitions are simplified. The primary key is another column (not included). contract number and customer_id are separate non-unique keys (using BTREE). The data is highly unique on both tables.
– Chris Knight
2 days ago
@BerndBuffen - Yes, index is used for that statement
– Chris Knight
2 days ago
can you pls verify MySQL take the index if you exec:**SELECT * from customercontracts c WHERE c.contractnumber = VALIDNUMBER**
– Bernd Buffen
2 days ago
can you pls verify MySQL take the index if you exec:**SELECT * from customercontracts c WHERE c.contractnumber = VALIDNUMBER**
– Bernd Buffen
2 days ago
The PRIMARY KEY is unclear. Please clarify.
– Strawberry
2 days ago
The PRIMARY KEY is unclear. Please clarify.
– Strawberry
2 days ago
@Strawberry - Apologies, the table definitions are simplified. The primary key is another column (not included). contract number and customer_id are separate non-unique keys (using BTREE). The data is highly unique on both tables.
– Chris Knight
2 days ago
@Strawberry - Apologies, the table definitions are simplified. The primary key is another column (not included). contract number and customer_id are separate non-unique keys (using BTREE). The data is highly unique on both tables.
– Chris Knight
2 days ago
@BerndBuffen - Yes, index is used for that statement
– Chris Knight
2 days ago
@BerndBuffen - Yes, index is used for that statement
– Chris Knight
2 days ago
add a comment |
4 Answers
4
active
oldest
votes
IS NOT THE ANSWER:
I have test it with ca. 1.000.000 rows in each table and they use the Index
MariaDB []> EXPLAIN SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| 1 | SIMPLE | m | ref | contractnumber,customer_id | customer_id | 63 | const | 1 | Using index condition; Using where |
| 1 | SIMPLE | c | ref | contractnumber | contractnumber | 63 | test2.m.contractnumber | 1 | |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
2 rows in set (0.002 sec)
MariaDB []> SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+-------------+----------------+---------+-------------+----------------+------+
| customer_id | contractnumber | message | customer_id | contractnumber | role |
+-------------+----------------+---------+-------------+----------------+------+
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
+-------------+----------------+---------+-------------+----------------+------+
4 rows in set (0.009 sec)
MariaDB []>
add a comment |
I would suggest try composite index on message Table customer_id,contractnumber and check performance, try to avoid using * in select .
add a comment |
I think I've finally found the answer to this. My sample table creation code above did not show the character encoding (a learn for me, don't shortcut sample code!). As it turns out, the customercontacts table is encoded in utf8 while the messages table is encoded in utf8mb4.
When columns of different character encoding are joined, indexes cannot be used.
This answers the 'why is this happening'. To fix this, we modified the utf8m4 table to downgrade the encoding of the indexed column to utf8 (while keeping the encoding of the rest of the table as utf8mb4). This has fixed performance for us.
add a comment |
I'd consider adding an INTEGER "id" field as the primary key for customercontracts and then reference through customercontracts_id instead of contractnumber in the messages table. You should see an improvement in performance already.
Alternatively, you can try adding FULLTEXT indexes on both contractnumber columns, but I'd advise for the first option.
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023481%2fmysql-poor-select-query-performance-despite-indexes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
IS NOT THE ANSWER:
I have test it with ca. 1.000.000 rows in each table and they use the Index
MariaDB []> EXPLAIN SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| 1 | SIMPLE | m | ref | contractnumber,customer_id | customer_id | 63 | const | 1 | Using index condition; Using where |
| 1 | SIMPLE | c | ref | contractnumber | contractnumber | 63 | test2.m.contractnumber | 1 | |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
2 rows in set (0.002 sec)
MariaDB []> SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+-------------+----------------+---------+-------------+----------------+------+
| customer_id | contractnumber | message | customer_id | contractnumber | role |
+-------------+----------------+---------+-------------+----------------+------+
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
+-------------+----------------+---------+-------------+----------------+------+
4 rows in set (0.009 sec)
MariaDB []>
add a comment |
IS NOT THE ANSWER:
I have test it with ca. 1.000.000 rows in each table and they use the Index
MariaDB []> EXPLAIN SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| 1 | SIMPLE | m | ref | contractnumber,customer_id | customer_id | 63 | const | 1 | Using index condition; Using where |
| 1 | SIMPLE | c | ref | contractnumber | contractnumber | 63 | test2.m.contractnumber | 1 | |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
2 rows in set (0.002 sec)
MariaDB []> SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+-------------+----------------+---------+-------------+----------------+------+
| customer_id | contractnumber | message | customer_id | contractnumber | role |
+-------------+----------------+---------+-------------+----------------+------+
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
+-------------+----------------+---------+-------------+----------------+------+
4 rows in set (0.009 sec)
MariaDB []>
add a comment |
IS NOT THE ANSWER:
I have test it with ca. 1.000.000 rows in each table and they use the Index
MariaDB []> EXPLAIN SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| 1 | SIMPLE | m | ref | contractnumber,customer_id | customer_id | 63 | const | 1 | Using index condition; Using where |
| 1 | SIMPLE | c | ref | contractnumber | contractnumber | 63 | test2.m.contractnumber | 1 | |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
2 rows in set (0.002 sec)
MariaDB []> SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+-------------+----------------+---------+-------------+----------------+------+
| customer_id | contractnumber | message | customer_id | contractnumber | role |
+-------------+----------------+---------+-------------+----------------+------+
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
+-------------+----------------+---------+-------------+----------------+------+
4 rows in set (0.009 sec)
MariaDB []>
IS NOT THE ANSWER:
I have test it with ca. 1.000.000 rows in each table and they use the Index
MariaDB []> EXPLAIN SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
| 1 | SIMPLE | m | ref | contractnumber,customer_id | customer_id | 63 | const | 1 | Using index condition; Using where |
| 1 | SIMPLE | c | ref | contractnumber | contractnumber | 63 | test2.m.contractnumber | 1 | |
+------+-------------+-------+------+----------------------------+----------------+---------+------------------------+------+------------------------------------+
2 rows in set (0.002 sec)
MariaDB []> SELECT * FROM messages m, customercontracts c
-> WHERE m.customer_id = 'CUST_22345'
-> AND c.contractnumber = m.contractnumber;
+-------------+----------------+---------+-------------+----------------+------+
| customer_id | contractnumber | message | customer_id | contractnumber | role |
+-------------+----------------+---------+-------------+----------------+------+
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
| CUST_22345 | 22345 | NULL | CUST_22345 | 22345 | NULL |
+-------------+----------------+---------+-------------+----------------+------+
4 rows in set (0.009 sec)
MariaDB []>
answered 2 days ago
Bernd BuffenBernd Buffen
10.1k21024
10.1k21024
add a comment |
add a comment |
I would suggest try composite index on message Table customer_id,contractnumber and check performance, try to avoid using * in select .
add a comment |
I would suggest try composite index on message Table customer_id,contractnumber and check performance, try to avoid using * in select .
add a comment |
I would suggest try composite index on message Table customer_id,contractnumber and check performance, try to avoid using * in select .
I would suggest try composite index on message Table customer_id,contractnumber and check performance, try to avoid using * in select .
answered 2 days ago
vishalvishal
268
268
add a comment |
add a comment |
I think I've finally found the answer to this. My sample table creation code above did not show the character encoding (a learn for me, don't shortcut sample code!). As it turns out, the customercontacts table is encoded in utf8 while the messages table is encoded in utf8mb4.
When columns of different character encoding are joined, indexes cannot be used.
This answers the 'why is this happening'. To fix this, we modified the utf8m4 table to downgrade the encoding of the indexed column to utf8 (while keeping the encoding of the rest of the table as utf8mb4). This has fixed performance for us.
add a comment |
I think I've finally found the answer to this. My sample table creation code above did not show the character encoding (a learn for me, don't shortcut sample code!). As it turns out, the customercontacts table is encoded in utf8 while the messages table is encoded in utf8mb4.
When columns of different character encoding are joined, indexes cannot be used.
This answers the 'why is this happening'. To fix this, we modified the utf8m4 table to downgrade the encoding of the indexed column to utf8 (while keeping the encoding of the rest of the table as utf8mb4). This has fixed performance for us.
add a comment |
I think I've finally found the answer to this. My sample table creation code above did not show the character encoding (a learn for me, don't shortcut sample code!). As it turns out, the customercontacts table is encoded in utf8 while the messages table is encoded in utf8mb4.
When columns of different character encoding are joined, indexes cannot be used.
This answers the 'why is this happening'. To fix this, we modified the utf8m4 table to downgrade the encoding of the indexed column to utf8 (while keeping the encoding of the rest of the table as utf8mb4). This has fixed performance for us.
I think I've finally found the answer to this. My sample table creation code above did not show the character encoding (a learn for me, don't shortcut sample code!). As it turns out, the customercontacts table is encoded in utf8 while the messages table is encoded in utf8mb4.
When columns of different character encoding are joined, indexes cannot be used.
This answers the 'why is this happening'. To fix this, we modified the utf8m4 table to downgrade the encoding of the indexed column to utf8 (while keeping the encoding of the rest of the table as utf8mb4). This has fixed performance for us.
edited 20 hours ago
answered yesterday
Chris KnightChris Knight
154
154
add a comment |
add a comment |
I'd consider adding an INTEGER "id" field as the primary key for customercontracts and then reference through customercontracts_id instead of contractnumber in the messages table. You should see an improvement in performance already.
Alternatively, you can try adding FULLTEXT indexes on both contractnumber columns, but I'd advise for the first option.
New contributor
add a comment |
I'd consider adding an INTEGER "id" field as the primary key for customercontracts and then reference through customercontracts_id instead of contractnumber in the messages table. You should see an improvement in performance already.
Alternatively, you can try adding FULLTEXT indexes on both contractnumber columns, but I'd advise for the first option.
New contributor
add a comment |
I'd consider adding an INTEGER "id" field as the primary key for customercontracts and then reference through customercontracts_id instead of contractnumber in the messages table. You should see an improvement in performance already.
Alternatively, you can try adding FULLTEXT indexes on both contractnumber columns, but I'd advise for the first option.
New contributor
I'd consider adding an INTEGER "id" field as the primary key for customercontracts and then reference through customercontracts_id instead of contractnumber in the messages table. You should see an improvement in performance already.
Alternatively, you can try adding FULLTEXT indexes on both contractnumber columns, but I'd advise for the first option.
New contributor
New contributor
answered 2 days ago
T. WayneT. Wayne
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023481%2fmysql-poor-select-query-performance-despite-indexes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can you pls verify MySQL take the index if you exec:**SELECT * from customercontracts c WHERE c.contractnumber = VALIDNUMBER**
– Bernd Buffen
2 days ago
The PRIMARY KEY is unclear. Please clarify.
– Strawberry
2 days ago
@Strawberry - Apologies, the table definitions are simplified. The primary key is another column (not included). contract number and customer_id are separate non-unique keys (using BTREE). The data is highly unique on both tables.
– Chris Knight
2 days ago
@BerndBuffen - Yes, index is used for that statement
– Chris Knight
2 days ago