我很困惑为什么服务器在执行以下查询时花费了太多时间:
SELECT tbl1.Column1 FROM Table1 AS tbl1
INNER JOIN Table2 AS tbl2 ON tbl2.Column4 = tbl1.Column1
返回结果大约需要20分钟。 MySQL config(my.ini)文件如下所示:
[mysql]
# CLIENT #
port = 3306
socket = X:\wamp\bin\mysql\mysql5.5.8\data\mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = X:\wamp\bin\mysql\mysql5.5.8\data\mysql.sock
pid-file = X:\wamp\bin\mysql\mysql5.5.8\data\mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = X:\wamp\bin\mysql\mysql5.5.8\data\
# BINARY LOGGING #
log-bin = X:\wamp\bin\mysql\mysql5.5.8\data\mysql-bin
expire-logs-days = 14
sync-binlog = 1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 4096
# INNODB #
innodb-log-files-in-group = 2
innodb-log-file-size = 128M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 2G
# LOGGING #
log-error = X:\wamp\bin\mysql\mysql5.5.8\data\mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = X:\wamp\bin\mysql\mysql5.5.8\data\mysql-slow.log
两个表都有主键。
此致
F。艾哈迈德
=============== UPDATE:
在使用上述查询运行Explain后,我得到了以下结果。
ID SelectType Table Type Key key_len rows extra
1 SIMPLE tbl2 index item_record_id 261 95361 Using index
1 SIMPLE tbl1 index record_id 261 88474 Using where; Using index; Using join buffer
答案 0 :(得分:0)
尝试这两个进行简单检查。
varchar
加入INT
,则会花费太多时间返回结果。答案 1 :(得分:0)
这将有助于查看读取和索引的行数以及更多可以查看重新分配的内容。
答案 2 :(得分:0)
如果您检查的2列的类型不同,则可能是一个问题。另一个问题是服务器..如果你有数百万行,那么处理得不好。