我需要runnerId
.
这个查询:
SELECT "runnerId" FROM betlog WHERE "marketId" = '107416794' ;
需要 80 毫秒(1968 个结果行)。
这个:
SELECT min("runnerId") FROM betlog WHERE "marketId" = '107416794' ;
需要 1600 毫秒。
有没有更快的方法来找到最小值,或者我应该在我的 java 程序中计算最小值?
"Result (cost=100.88..100.89 rows=1 width=0)"
" InitPlan 1 (returns $0)"
" -> Limit (cost=0.00..100.88 rows=1 width=9)"
" -> Index Scan using runneridindex on betlog (cost=0.00..410066.33 rows=4065 width=9)"
" Index Cond: ("runnerId" IS NOT NULL)"
" Filter: ("marketId" = 107416794::bigint)"
CREATE INDEX marketidindex
ON betlog
USING btree
("marketId" COLLATE pg_catalog."default");
另一个想法:
SELECT "runnerId" FROM betlog WHERE "marketId" = '107416794' ORDER BY "runnerId" LIMIT 1 >1600ms
SELECT "runnerId" FROM betlog WHERE "marketId" = '107416794' ORDER BY "runnerId" >>100ms
如何LIMIT
减慢查询速度?