0

次のクエリは600秒後にタイムアウトになります。

update placed p
      ,Results r
  set p.position = r.position
  where p.competitor = r.competitor
    AND p.date = r.date 
    AND REPLACE(p.time,":","") = r.time; 

構造は次のとおりです。

'CREATE TABLE `placed` (
  `idplaced` varchar(50) DEFAULT NULL,
  `date` decimal(8,0) DEFAULT NULL,
  `time` varchar(45) DEFAULT NULL,
  `field1` varchar(45) DEFAULT NULL,
  `competitor` varchar(45) DEFAULT NULL,
  `field2` int(2) DEFAULT NULL,
  `field3` varchar(45) DEFAULT NULL,
  `field4` varchar(45) DEFAULT NULL,
  `field5` decimal(6,2) DEFAULT NULL,
  `field6` decimal(10,2) DEFAULT NULL,
  `field7` decimal(6,2) DEFAULT NULL,
  `field8` char(1) DEFAULT NULL,
  `field9` varchar(45) DEFAULT NULL,
  `position` char(4) DEFAULT NULL,
  `field10` decimal(6,2) DEFAULT NULL,
  `field11` char(1) DEFAULT NULL,
  `field12` char(1) DEFAULT NULL,
  `field13` decimal(6,2) DEFAULT NULL,
  `field14` decimal(6,2) DEFAULT NULL,
  `field15` decimal(6,2) DEFAULT NULL,
  `field16` decimal(6,2) DEFAULT NULL,
  `field17` decimal(6,2) DEFAULT NULL,
  `field18` char(1) DEFAULT NULL,
  `field19` char(20) DEFAULT NULL,
  `field20` char(1) DEFAULT NULL,
  `field21` char(5) DEFAULT NULL,
  `field22` char(5) DEFAULT NULL,
  `field23` int(11) DEFAULT NULL
   PRIMARY KEY (`idplaced`),
  UNIQUE KEY `date_time_competitor_field18_combo` (`date`,`time`,`competitor`,`field18`)
) ENGINE=InnoDB AUTO_INCREMENT=100688607 DEFAULT CHARSET=latin1;

CREATE TABLE `results` (
  `idresults` int(11) NOT NULL AUTO_INCREMENT,
  `date` char(8) DEFAULT NULL,
  `time` char(4) DEFAULT NULL,
  `field1` varchar(45) DEFAULT NULL,
  `competitor` varchar(45) DEFAULT NULL,
  `position` char(4) DEFAULT NULL,
  `field2` varchar(45) DEFAULT NULL,
  `field3` decimal(2,0) DEFAULT NULL,
  PRIMARY KEY (`idresults`)
) ENGINE=InnoDB AUTO_INCREMENT=6644 DEFAULT CHARSET=latin1;

PLACEDテーブルには65,000レコードがあり、テーブルRESULTSには9,000レコードがあります。

解決策にはJOIN説明が含まれていると思います。このサイトからいくつかの提案を試しましたが、探している答えが見つかりません。簡単に言えば、これについての提案をいただければ幸いです。必要に応じて、サンプルテーブルを作成したり、テーブルコードを作成したりできます。

4

2 に答える 2

0

まず、テーブルの完全な説明を使用して送信することをお勧めします

show create table

次に、結合構文を使用することをお勧めします。

update placed p
  join Results r on r.competitor = p.competitor
   set p.position = r.position
 where p.date = r.date 
   AND REPLACE(p.time,":","") = r.time;

これがお役に立てば幸いです。

于 2012-08-06T06:48:09.120 に答える
0

操作上、インデックスを効率的に使用して結合を実行することはできませんREPLACE。次のわずかに異なる順序で列を使用してインデックスを作成することをお勧めします。

(date, competitor, time, position)

このインデックスを両方のテーブルに追加すると役立つ場合があります。

time列のデータが両方のテーブルに同じ形式で格納されるように、データベースのデータを変更できればさらに良いでしょう。

于 2012-08-06T08:22:18.410 に答える