简体   繁体   English

试图加快SQLITE UNION QUERY的速度

[英]Trying to speed up a SQLITE UNION QUERY

I have the below SQLITE code 我有下面的SQLITE代码

SELECT x.t,
CASE WHEN S.Status='A' AND M.Nomorebets=0 THEN S.PriceText ELSE '-' END AS Show_Price
FROM sb_Market M
LEFT OUTER JOIN
(select 2010 t union
select 2020 t union
select 2030 t union
select 2040 t union
select 2050 t union
select 2060 t union
select 2070 t
) as x
LEFT OUTER JOIN sb_Selection S ON
S.MeetingId=M.MeetingId AND
S.EventId=M.EventId AND
S.MarketId=M.MarketId AND
x.t=S.team
WHERE M.meetingid=8051 AND M.eventid=3 AND M.Name='Correct Score'

With the current interface restrictions, I have to use the above code to ensure that if one selection is missing, that a '-' appears. 在当前的接口限制下,我必须使用上面的代码来确保如果缺少一个选择,则会出现“-”。

Some feed would be something like the following 一些提要类似于以下内容

SelectionId Name Team Status PriceText
===================================
1 Barney 2010 A 10
2 Jim 2020 A 5
3 Matt 2030 A 6
4 John 2040 A 8
5 Paul 2050 A 15/2
6 Frank 2060 S 10/11
7 Tom 2070 A 15

Is using the above SQL code the quickest & efficient?? 使用上面的SQL代码最快,最有效吗?

Please advise of anything that could help. 请告知任何可能有所帮助的内容。 Messages with updates would be preferable. 带有更新的消息将是更可取的。

Some things you could do: 您可以做的一些事情:

  1. Ensure there is an index on sb_Selection(MeetingId, EventId, MarketId) 确保在sb_Selection(MeetingId,EventId,MarketId)上有一个索引
  2. Ensure there is an index on sb_Market(MeetingId, EventId, MarketId) 确保sb_Market(MeetingId,EventId,MarketId)上有索引
  3. Consider covering indexes if you need better performance (Eg. you could cover S.team, S.Status, S.PriceText) 如果需要更好的性能,请考虑覆盖索引(例如,可以覆盖S.team,S.Status和S.PriceText)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM