MySQL解释显示主表的索引在生产服务器上没有使用

MySQL解释显示主表的索引在生产服务器上没有使用,mysql,indexing,explain,Mysql,Indexing,Explain,我正在尝试从OsCommerce优化以下修改后的MySQL查询: select distinct p.products_id, pd.products_name, m.manufacturers_name, s.specials_new_products_price from products p inner join products_description pd on p.products_id = pd.products_id inner join products_to_categor

我正在尝试从OsCommerce优化以下修改后的MySQL查询:

select distinct p.products_id, pd.products_name, m.manufacturers_name, s.specials_new_products_price from products p 
inner join products_description pd on p.products_id = pd.products_id
inner join products_to_categories p2c on p.products_id = p2c.products_id 
left join manufacturers m on p.manufacturers_id = m.manufacturers_id 
left join specials s on p.products_id = s.products_id and s.specials_b2bgroup =0 
where p.products_status = '1' and p.products_model not like '%_VIP' and pd.language_id = '4' and p2c.categories_id = '1574' 
order by p.products_ordernum, p.products_model
在生产服务器上运行explain时,似乎没有为联接处的表产品使用索引:

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  p   ALL     PRIMARY     NULL        NULL NULL   6729    Using where; Using temporary; Using filesort
1   SIMPLE  m   eq_ref  PRIMARY     PRIMARY     4   p.manufacturers_id  1    
1   SIMPLE  s   ref     products_id products_id 4   p.products_id   2    
1   SIMPLE  pd  eq_ref  PRIMARY     PRIMARY     8   p.products_id,const     1    
1   SIMPLE  p2c eq_ref  PRIMARY     PRIMARY     8   pd.products_id,const    1   Using where; Using index; Distinct
表产品的架构如下所示:

CREATE TABLE IF NOT EXISTS `products` (
  `products_id` int(11) NOT NULL auto_increment,
  `products_model` varchar(50) default NULL,
  `products_image` varchar(250) default NULL,
  `products_price` decimal(15,4) NOT NULL default '0.0000',
  `products_date_added` datetime NOT NULL default '0000-00-00 00:00:00',
  `products_last_modified` datetime default NULL,
  `products_date_available` datetime default NULL,
  `products_weight` decimal(5,2) NOT NULL default '0.00',
  `products_status` tinyint(1) NOT NULL default '0',
  `products_showprod` tinyint(1) NOT NULL default '0',
  `products_showprice` tinyint(1) NOT NULL default '0',
  `products_ordernum` int(6) NOT NULL default '100',
  `products_tax_class_id` int(11) NOT NULL default '0',
  `manufacturers_id` int(11) default NULL,
  PRIMARY KEY  (`products_id`),
  KEY `idx_products_model` (`products_model`),
) ENGINE=MyISAM  DEFAULT CHARSET=greek AUTO_INCREMENT=1;
我的服务器的MySQL版本是5.0.92。任何关于在哪里寻找解决方案的想法都是非常受欢迎的

products是嵌套循环中最外层的表,因此用于访问该表的索引与联接无关

这种情况:

p.products_model not like '%_VIP'
这是不可取的


如果有足够的选择性,你可以尝试创建一个关于产品状态的索引。Estatus=1的值很少

在products表的查询中只有两个约束,您已将其声明为主表,因为其他所有内容都是连接的:products\u status not indexed和products\u model。但与“%”不同,“%”不是可索引约束,因此进行简单扫描更快


如果%出现在类似模式的中间或结尾,则索引将是有用的。即使如此,NOT仍然可能使线性扫描更快。

我在products\u status和products\u model中添加了索引,但这也无助于几乎所有条目的products\u status=1。在我的情况下,查询性能的实际问题是,products_to_categories有130万个enties产品与多个类别连接,因此,例如,从单个类别中获取20个产品大约需要7秒钟。我想我必须改变数据库体系结构。对此有任何建议都非常欢迎!