# PRIMARY key not working

**URL:** https://forums.percona.com/t/primary-key-not-working/983
**Category:** Other MySQL® Questions
**Created:** [October 29, 2008, 10:59am UTC](https://forums.percona.com/t/primary-key-not-working/983 "2008-10-29T10:59:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jeffStrahl](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jeffStrahl](https://forums.percona.com/u/jeffStrahl)
#### Post date: [October 29, 2008, 10:59am UTC](https://forums.percona.com/t/primary-key-not-working/983/1 "2008-10-29T10:59:55Z")

</div>

Hello,  
I have a query that is joining multiple tables. I have it optimized rather well, except for one table. I can’t for the life of me figure out why that table is not using the pk as the key. It is causing the query to filesort and use a temp table, changing the query time from 0.003s to 23s, obviously too long.

Attached is a file with the database and query details.

Any assistance is greatly appreciated, for I don’t know what it could be.

---

<div class="post-metadata">

### Author: ![xaprb](https://avatars.discourse-cdn.com/v4/letter/x/49beb7/32.png) [@xaprb](https://forums.percona.com/u/xaprb)
#### Post date: [December 25, 2009, 10:36am UTC](https://forums.percona.com/t/primary-key-not-working/983/2 "2009-12-25T10:36:32Z")

</div>

I can’t see what could be causing that, either. Maybe ANALYZE TABLE method\_of\_payment will help.

---

<div class="post-metadata">

### Author: ![gmouse](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@gmouse](https://forums.percona.com/u/gmouse)
#### Post date: [December 27, 2009, 7:12pm UTC](https://forums.percona.com/t/primary-key-not-working/983/3 "2009-12-27T19:12:16Z")

</div>

actually I have encountered that old versions of MySQL (5.0.x, have not tried anything more recent) has a hard job selecting the right index for order by. Eg having a multicolumn indices on (a,b) and on (a,c), if you select from tbl where a=1 order by c it would still pick the index on (a,b). Only using force index solves this issue (or adding an arbitrary where-clause like c\>0).
