2

I'm hoping (and pretty sure that) someone out there is much better at MySQL queries than msyelf.

I have a query which checks a table that contains information on : - a search term - title and price results from various sites using this search term

For the sake of streamlining, I've inserted the data already converted to lowercase with spaces removed and the whole thing trimmed to 11 characters to help reduce the load on the MySQL server.

The query is designed to find the maximum cost and minimum cost of likely equal titles and determine a price difference if it exists.

Having read some similar questions here, I've also prepended EXPLAIN EXTENDED to the query to see if that would help and I'm including the results along with the query.

The query as is :

SELECT
  a.pricesrch11,
  b.pricesrch11,
  a.pricegroup11,
  b.pricegroup11,
  a.priceamt - b.priceamt AS pricediff
FROM      ebssavings a
LEFT JOIN ebssavings b ON ( a.pricesrch11 = b.pricesrch11 ) 
                      AND (a.pricegroup11 = a.pricesrch11)
                      AND (b.pricegroup11 = a.pricesrch11)
WHERE a.priceamt - b.priceamt >0
GROUP BY a.pricesrch11

The results of the EXPLAIN :

    select_type | table | type | possible_keys            | key  | key_len | ref  | rows | Extra
1 | SIMPLE      | a     | ALL  | pricesrch11,pricegroup11 | NULL | NULL    | NULL | 8816 | Using where; Using temporary; Using filesort
1 | SIMPLE      | b     | ALL  | pricesrch11,pricegroup11 | NULL | NULL    | NULL | 6612 | Using where

ADDENDUM :

I just ran this query and got the following result :

Showing rows 0 - 4 ( 5 total, Query took 66.8119 sec)


CREATE TABLE IF NOT EXISTS ebssavings 
( priceid int(44) NOT NULL auto_increment, 
  priceamt decimal(10,2) NOT NULL, 
  pricesrch11 varchar(11) character set utf8 collate utf8_unicode_ci NOT NULL, 
  pricegroup11 varchar(11) character set utf8 collate utf8_unicode_ci NOT NULL, 
  pricedate timestamp NOT NULL default CURRENT_TIMESTAMP, 
  PRIMARY KEY (priceid), 
  KEY priceamt (priceamt), 
  KEY pricesrch11 (pricesrch11), 
  KEY pricegroup11 (pricegroup11) ) 
ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8817 

MORE INFO ON THE NEW INDEXES (removed pricegroup11, and made a composite index called srchandtitle from pricesrch11 and pricegroup11):

Edit     Drop   PRIMARY BTREE   Yes No  priceid 169 A       
Edit     Drop   priceamt    BTREE   No  No  priceamt    56  A       
Edit     Drop   pricesrch11 BTREE   No  No  pricesrch11 12  A       
Edit     Drop   srchandtitle    BTREE   No  No  pricesrch11 12  A       
                                                pricegroup11 169    A   
4

3 回答 3

2

创建两个索引:

  1. 价格Srch11
  2. pricerch11,pricegroup11 上的聚集索引
于 2012-07-03T19:38:09.903 回答
1

删除 pricegroup11 上的键,并在 pricerch11,pricegroup11 上添加复合集群键。

还将表移动到 InnoDB。

于 2012-07-03T19:56:07.633 回答
0

似乎随着对表和索引的更改,事情现在已经加快了。

我已经清空了桌子,又开始了。

谢谢大家的帮助。

-一个

于 2012-07-03T21:43:55.023 回答