经过调查,我发现所有的php子进程都在等待数据库查询。我最近遇到问题时检查了mariadb上的进程列表,输出如下。知道如何解决这个问题吗?提前谢谢。
MariaDB [(none)]> show processlist; +--------+-------------+-------------------------------+---------+---------+------+------------------------------+---------------------------------------------------------------------- --------------------------------+----------+ | Id | User | Host | db | Command | Time | State | Info | Progress | +--------+-------------+-------------------------------+---------+---------+------+------------------------------+---------------------------------------------------------------------- --------------------------------+----------+ | 1 | system user | | NULL | Daemon | NULL | | NULL | 0.000 | | 2 | system user | | NULL | Daemon | NULL | | NULL | 0.000 | | 4 | system user | | NULL | Daemon | NULL | | NULL | 0.000 | | 3 | system user | | NULL | Daemon | NULL | | NULL | 0.000 | | 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 | | 109822 | catalog | mymagentositexxxxxx.com:56405 | catalog | Query | 985 | update | INSERT INTO `cataloginventory_stock_status` (`product_id`,`website_id `,`stock_id`,`qty`,`stock_statu | 0.000 | | 109850 | catalog | mymagentositexxxxxx.com:56436 | catalog | Query | 985 | update | INSERT INTO `cataloginventory_stock_status` (`product_id`,`website_id `,`stock_id`,`qty`,`stock_statu | 0.000 | | 109859 | catalog | mymagentositexxxxxx.com:56448 | catalog | Query | 985 | update | INSERT INTO `cataloginventory_stock_status` (`product_id`,`website_id `,`stock_id`,`qty`,`stock_statu | 0.000 | | 109931 | catalog | mymagentositexxxxxx.com:56554 | catalog | Query | 986 | Waiting for table level lock | DELETE FROM `catalogsearch_fulltext` WHERE (store_id=1) AND (product_ id IN ('26515')) | 0.000 | | 109966 | catalog | mymagentositexxxxxx.com:56606 | catalog | Query | 984 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 33218 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 109993 | catalog | mymagentositexxxxxx.com:56645 | catalog | Query | 934 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 109997 | catalog | mymagentositexxxxxx.com:56650 | catalog | Query | 987 | Sending data | INSERT INTO `catalogsearch_result` SELECT 33215 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 110040 | catalog | mymagentositexxxxxx.com:56709 | catalog | Query | 983 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 33215 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 110218 | catalog | mymagentositexxxxxx.com:56925 | catalog | Query | 940 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 6656 AS `query_id`, `s`.`pr oduct_id`, 0 AS `relevance` FRO | 0.000 | | 110248 | catalog | mymagentositexxxxxx.com:56956 | catalog | Query | 932 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 33220 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 110380 | catalog | mymagentositexxxxxx.com:57095 | catalog | Query | 906 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 33214 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 110392 | catalog | mymagentositexxxxxx.com:57107 | catalog | Query | 905 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 33215 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 110810 | catalog | mymagentositexxxxxx.com:57554 | catalog | Query | 825 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 6656 AS `query_id`, `s`.`pr oduct_id`, 0 AS `relevance` FRO | 0.000 | | 110865 | catalog | mymagentositexxxxxx.com:57616 | catalog | Query | 808 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 21581 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 110968 | catalog | mymagentositexxxxxx.com:57782 | catalog | Query | 48 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 110969 | catalog | mymagentositexxxxxx.com:57783 | catalog | Query | 48 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 110989 | catalog | mymagentositexxxxxx.com:57803 | catalog | Query | 39 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 110999 | catalog | mymagentositexxxxxx.com:57813 | catalog | Query | 34 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 111012 | catalog | mymagentositexxxxxx.com:57867 | catalog | Query | 32 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 111067 | catalog | mymagentositexxxxxx.com:57959 | catalog | Query | 18 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 111077 | catalog | mymagentositexxxxxx.com:57974 | catalog | Query | 15 | update | INSERT INTO `sales_flat_quote_item` (`quote_id`, `created_at`, `updat ed_at`, `product_id`, `store_id | 0.000 | | 111078 | root | localhost | NULL | Query | 0 | init | show processlist | 0.000 | | 111117 | catalog | mymagentositexxxxxx.com:58015 | catalog | Query | 10 | Waiting for table level lock | INSERT INTO `catalogsearch_result` SELECT 13226 AS `query_id`, `s`.`p roduct_id`, 0 AS `relevance` FR | 0.000 | | 111147 | moodle | mymagentositexxxxxx.com:58046 | moodle | Sleep | 0 | | NULL | 0.000 | +--------+-------------+-------------------------------+---------+---------+------+------------------------------+---------------------------------------------------------------------- --------------------------------+----------+ 29 rows in set (0.00 sec)
#UPDATE2 表等待状态下的“显示创建表输出”如下所示
MariaDB [catalog]> SHOW CREATE TABLE catalogsearch_fulltext; +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | catalogsearch_fulltext | CREATE TABLE `catalogsearch_fulltext` ( `product_id` int(10) unsigned NOT NULL COMMENT 'Product ID', `store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID', `data_index` longtext DEFAULT NULL COMMENT 'Data index', `fulltext_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity ID', PRIMARY KEY (`fulltext_id`), UNIQUE KEY `UNQ_CATALOGSEARCH_FULLTEXT_PRODUCT_ID_STORE_ID` (`product_id`,`store_id`), FULLTEXT KEY `FTI_CATALOGSEARCH_FULLTEXT_DATA_INDEX` (`data_index`) ) ENGINE=MyISAM AUTO_INCREMENT=912741 DEFAULT CHARSET=utf8 COMMENT='Catalog search result table' | +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) MariaDB [catalog]> SHOW CREATE TABLE catalogsearch_result; +----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | catalogsearch_result | CREATE TABLE `catalogsearch_result` ( `query_id` int(10) unsigned NOT NULL COMMENT 'Query ID', `product_id` int(10) unsigned NOT NULL COMMENT 'Product ID', `relevance` decimal(20,4) NOT NULL DEFAULT 0.0000 COMMENT 'Relevance', PRIMARY KEY (`query_id`,`product_id`), KEY `IDX_CATALOGSEARCH_RESULT_QUERY_ID` (`query_id`), KEY `IDX_CATALOGSEARCH_RESULT_PRODUCT_ID` (`product_id`), CONSTRAINT `FK_CATALOGSEARCH_RESULT_QUERY_ID_CATALOGSEARCH_QUERY_QUERY_ID` FOREIGN KEY (`query_id`) REFERENCES `catalogsearch_query` (`query_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_CATSRCH_RESULT_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog search result table' | +----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
答案 0 :(得分:0)
时间最多的过程(#109997)触及MyISAM表?完成SHOW FULL PROCESSLIST
后,我看到了
INSERT
INTO `catalogsearch_result`
SELECT 11474 AS `query_id`, `s`.`product_id`, 0 AS `relevance`
FROM `catalogsearch_fulltext` AS `s`
INNER JOIN `catalog_product_entity` AS `e` ON e.entity_id = s.product_id
WHERE (s.store_id = 1)
AND ((`s`.`data_index` LIKE '%Informaatika%'
OR `s`.`data_index` LIKE '%8.c%')
) ON DUPLICATE KEY
UPDATE `relevance` = VALUES(`relevance`)
这是一个仅在最近才开始的慢SELECT
。由于我们正在谈论MyISAM,并且正在进行写入,因此查询将一次一个地进行(大多数情况下)。
由于OR
测试中的LIKE
和前导通配符,因此速度很慢。你有什么方法可以避免这两个这些问题吗?有了它们,SELECT
必须扫描整个表格,这显然需要几分钟。 (桌子有多大?)
更改超时可能会让您通过一个实例,但只需让您处于永无止境的查询序列中,等待其他查询完成。
最好的解决方案是远离MyISAM。有关该问题的更多提示:http://mysql.rjweb.org/doc.php/myisam2innodb
(即使在转换后,也可能存在其他问题。)