1

我将几个表格加入到一个视图中,以便于编码。现在,当我使用该视图加入几个表时,我的性能很差。当我看到更多行时,这些查询的速度显着降低。我使用这个视图写了很多代码,所以我不喜欢重写所有这些查询的解决方案:)。当我将它与其他表连接时,是否有任何优雅的解决方案来加速这个视图?

这是我的查询之一,tickets_parsed视图在哪里:

SELECT detailValue, SUM(total_tickets) AS total_tickets, SUM(money_in) AS money_in, SUM(handling_charges) AS handling_charges
FROM (
    SELECT bsid, COUNT(*) AS total_tickets, SUM(amount_total) AS money_in, SUM(handling_charges) AS handling_charges
    FROM `bingo`.tickets_parsed
    WHERE tickettime BETWEEN '$date' AND '$date2a'
    AND ticketstatus <> 'CLOSED'
    GROUP BY bsid
    ORDER BY NULL
) AS sub
NATURAL JOIN betshop_details
WHERE detailID = 5
GROUP BY detailValue
ORDER BY NULL
4

1 回答 1

0

您查询在子查询中使用视图,这可能会阻止它使用索引。但我不确定子查询是否必要。

你可能会使用这样的东西: -

SELECT a.detailValue, COUNT(*) AS total_tickets, SUM(b.amount_total) AS money_in, SUM(b.handling_charges) AS handling_charges
FROM bingo.tickets_parsed a
INNER JOIN betshop_details b
ON a.bsid = b.bsid
WHERE a.detailID = 5
AND b.tickettime BETWEEN '$date' AND '$date2a'
AND b.ticketstatus <> 'CLOSED'
GROUP BY a.detailValue
ORDER BY NULL
于 2013-11-07T12:02:01.447 回答