【发布时间】:2017-10-21 13:36:30
【问题描述】:
我正在使用 JAVA + MySQL (maria db) 开发会计软件。我使用以下查询计算查询量,运行查询时查询需要 16 秒。查询持续时间正常吗?我在问题中犯了错误吗?
SELECT products_id as ID,prod_name as 'Product Name',
IFNULL((SELECT sum(piece)
FROM `ktgcari_000_fatura_xref`
WHERE product_id = ktgcari_000_stok.products_id AND
(type = 1 or type = 4)
), 0) -
IFNULL((SELECT sum(piece)
FROM `ktgcari_000_fatura_xref`
WHERE product_id = ktgcari_000_stok.products_id AND
(type = 2 or type = 5)
), 0) +
IFNULL((SELECT sum(piece)
FROM ktgcari_000_ssayim
WHERE urun_id = ktgcari_000_stok.products_id
), 0) as stock
FROM ktgcari_000_stok
LIMIT 0,1000
库存=(进发票总和+进发货总和)-(发货发票总和+发货总和)+(盘点收货总和)
数据库信息: 库存卡数量:39000 发票数量:545 发票内容表数:1800 数指数:942 数据库大小:5 MB
【问题讨论】:
-
您是否为必填字段创建了索引?