The query

SELECT f.name, f.type, v.value FROM profile_fields f INNER JOIN profile_values v ON f.fid = v.fid WHERE uid = %d;

doesn't use the indices on D6.

This is the tablel structure on D6:

CREATE TABLE `profile_values` (
  `fid` int(10) unsigned NOT NULL default '0',
  `uid` int(10) unsigned NOT NULL default '0',
  `value` text,
  PRIMARY KEY  (`uid`,`fid`),
  KEY `fid` (`fid`)
)

and this on D5:

CREATE TABLE `profile_values` (
  `fid` int(11) unsigned default '0',
  `uid` int(11) unsigned default '0',
  `value` text,
  KEY `uid` (`uid`),
  KEY `fid` (`fid`)
) 

The mixed primary index does apparently not work:

mysql> explain SELECT f.name, f.type, v.value FROM profile_fields f INNER JOIN profile_values v ON f.fid = v.fid WHERE v.uid = 12345;
+----+-------------+-------+--------+---------------+---------+---------+---------------------+------+-------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref                 | rows | Extra       |
+----+-------------+-------+--------+---------------+---------+---------+---------------------+------+-------------+
|  1 | SIMPLE      | f     | ALL    | PRIMARY       | NULL    | NULL    | NULL                |   28 |             | 
|  1 | SIMPLE      | v     | eq_ref | PRIMARY,fid   | PRIMARY | 8       | const,drupal6.f.fid |    1 | Using where | 
+----+-------------+-------+--------+---------------+---------+---------+---------------------+------+-------------+

Comments

gábor hojtsy’s picture

Title: Not working index » Mixed primary key on profile_values does not work
david strauss’s picture

Status: Active » Closed (won't fix)

You are incorrect. Your example explicitly shows MySQL using the new primary key:
| 1 | SIMPLE | v | eq_ref | PRIMARY,fid | PRIMARY | 8 | const,drupal6.f.fid | 1 | Using where |

For table "v" (profile_values), it's using key PRIMARY. It's not using a key on the profile_fields table. While MySQL could use PRIMARY for profile_fields (and says as much), it's joining on practically the whole table, so it's correctly deciding to not use the key.

david strauss’s picture

Issue summary: View changes

added code tags