gpt4 book ai didi

php - 表更新慢

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:46 25 4
gpt4 key购买 nike

我在 OpenCart 中有一个 product 表,共有 57,000 条记录。看起来像:

 Field  Type    Null    Key     Default     Extra   
product_id int(11) NO PRI NULL auto_increment
model char(64) NO NULL
sku char(100) NO UNI NULL
upc char(1) NO NULL
ean char(1) NO NULL
jan char(1) NO NULL
isbn char(1) NO NULL
mpn char(1) NO NULL
location char(1) NO NULL
quantity int(4) NO 0
stock_status_id int(11) NO NULL
image char(255) YES NULL
manufacturer_id int(11) NO MUL NULL
shipping tinyint(1) NO 1
pret_brut decimal(15,2) NO 0.00
price decimal(15,2) NO 0.00
points int(8) NO 0
tax_class_id int(11) NO NULL
date_available date NO NULL
weight decimal(15,8) NO 0.00000000
weight_class_id int(11) NO 0
length decimal(15,8) NO 0.00000000
width decimal(15,8) NO 0.00000000
height decimal(15,8) NO 0.00000000
length_class_id int(11) NO 0
subtract tinyint(1) NO 1
minimum int(11) NO 1
sort_order int(11) NO 0
status tinyint(1) NO MUL 0
date_added datetime NO 0000-00-00 00:00:00
date_modified datetime NO 0000-00-00 00:00:00
viewed int(5) NO 0

使用的索引:

PRIMARY BTREE   Yes No  product_id  56399   A   No <br/>
sku BTREE Yes No sku 56399 A No<br/>
manufacturer_id BTREE No No manufacturer_id 386 A No<br/>
+status BTREE No No status 1 A No<br/>
+date_available 440 A No<br/>

...最后一个(带有“+”)是多个字段的索引(我不知道它的技术名称)。

问题是,当我在该表上运行类似“UPDATE product SET stock_status_id=5, quantity=0, status=0”的查询时,我在 0.8 - 1.5 秒之间的某处通过了 PHP 的 microtime() 函数。也许我有点偏执,但似乎太多了。有什么办法可以改善更新时间吗?

语言:

我想停用该表中的所有产品,然后仅更新激活的产品。我不知道这是否是最好的方法,但我认为最好检查每一个。还有其他更快的方法吗?

最佳答案

为什么不使用 WHERE 对记录进行分块,使用 WHERE 子句将缩短更新时间

这样试试

UPDATE product SET stock_status_id=5, quantity=0, status=0 
WHERE
status!=0;

关于php - 表更新慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27667341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com