mysql - 跨数据库连接花费的时间比预期要长

标签 mysql performance

我在 2 个不同的数据库中有 2 个表,它们都位于同一服务器上。我在 2 上运行联接,需要超过 8 分钟才能获得结果。

CREATE TABLE `ps_product_attribute` (  
    `id_product_attribute` int(10) unsigned NOT NULL AUTO_INCREMENT,  
    `id_product` int(10) unsigned NOT NULL,  
    `reference` varchar(70) DEFAULT NULL,  
    `supplier_reference` varchar(32) DEFAULT NULL,  
    `location` varchar(64) DEFAULT NULL,  
    `ean13` varchar(13) DEFAULT NULL,  
    `upc` varchar(12) DEFAULT NULL,  
    `wholesale_price` decimal(20,6) NOT NULL DEFAULT '0.000000',  
    `price` decimal(20,6) NOT NULL DEFAULT '0.000000',  
    `ecotax` decimal(17,6) NOT NULL DEFAULT '0.000000',  
    `quantity` int(10) NOT NULL DEFAULT '0',  
    `weight` decimal(20,6) NOT NULL DEFAULT '0.000000',  
    `unit_price_impact` decimal(17,2) NOT NULL DEFAULT '0.00',  
    `default_on` tinyint(1) unsigned NOT NULL DEFAULT '0',  
    `minimal_quantity` int(10) unsigned NOT NULL DEFAULT '1',  
    `available_date` date NOT NULL,  
    `attribute_color` varchar(10) DEFAULT '#FFFFFF',  
    `swatch_url` varchar(100) DEFAULT NULL,  
    `a_createddate` datetime DEFAULT NULL,  
    `a_createdby` bigint(20) DEFAULT NULL,  
    `a_modifieddate` datetime DEFAULT NULL,  
    `a_modifiedby` bigint(20) DEFAULT NULL,  
    PRIMARY KEY (`id_product_attribute`),  
    KEY `product_attribute_product` (`id_product`),  
    KEY `reference` (`reference`),  
    KEY `supplier_reference` (`supplier_reference`),  
    KEY `product_default` (`id_product`,`default_on`),  
    KEY `id_product_id_product_attribute` (`id_product_attribute`,`id_product`),  
    KEY `ps_product_attribute_ean13` (`ean13`)
) ENGINE=InnoDB AUTO_INCREMENT=143326 DEFAULT CHARSET=utf8

和另一个数据库中的第二个表。

CREATE TABLE `t_stockreserves` (  
    `a_stockreserveid` bigint(20) NOT NULL AUTO_INCREMENT,  
    `a_ean` varchar(13) DEFAULT NULL,  
    `a_basemarketplacereserve` int(11) DEFAULT NULL,  
    `a_marketplacereserve` int(11) DEFAULT NULL,  
    `a_criticalreserve` int(11) DEFAULT NULL,  
    `a_createddate` datetime DEFAULT NULL,  
    `a_createdby` bigint(20) DEFAULT NULL,  
    `a_modifieddate` datetime DEFAULT NULL,  
    `a_modifiedby` bigint(20) DEFAULT NULL,  
    PRIMARY KEY (`a_stockreserveid`),  
    UNIQUE KEY `t_stockreserves_ean_ind` (`a_ean`)
) ENGINE=InnoDB AUTO_INCREMENT=16855 DEFAULT CHARSET=latin1

我只是运行如下查询

SELECT ps_product_attribute.id_product
 FROM ps_product_attribute 
LEFT JOIN `dropship`.`t_stockreserves` ON `t_stockreserves`.`a_ean` = `ps_product_attribute`.`ean13` 

运行查询需要 8 分钟。这是解释命令输出

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  ps_product_attribute    ALL     NULL    NULL    NULL    NULL    125960  
1   SIMPLE  t_stockreserves     index   NULL    t_stockreserves_ean_ind     16  NULL    17083   Using index

这有什么问题吗?

最佳答案

表的不同 CHARSET 并与 VARCHAR 连接怎么样?

我会使用具有相同字符集的表来测试它。

关于mysql - 跨数据库连接花费的时间比预期要长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24940009/

相关文章:

mysql - 将 VarChar 转换为时间戳

performance - 对称加密:性能问题

performance - ppval的高效替代品

python - 具有已发布的 GIL 和复杂线程的多线程代码在 Python 中速度较慢

php - 将文本从textarea插入到mysql表中

php - 三种 Eloquent 关系

php - 未根据数据库信息设置值

java - executeBatch 在 Prepared Statement 上的效果如何?

c++ - 性能调整推力应用程序

mysql - 如何组合 2 个 SQL 查询以获得 1 个结果