我正在使用tpch
database,并希望使用更快的运行时优化一个查询。
我尝试向查询添加索引和视图,但它们没有提高性能。有人能提供建议吗?谢谢。
- 连接:**
conn = mysql.connect(host = 'relational.fit.cvut.cz', port = int(3306), user = 'guest', passwd = 'relational', db = 'tpch')
- 查询:**
WITH customer_lifetime_value AS (
SELECT
c_custkey,
c_name,
c_address,
c_nationkey,
c_phone,
c_acctbal,
c_mktsegment,
c_comment,
SUM(o_totalprice) AS ltv
FROM customer
JOIN orders
ON o_custkey = c_custkey
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8
)
SELECT
r_name,
MAX(ltv) AS best_customer_value
FROM region
JOIN nation
ON n_regionkey = r_regionkey
JOIN customer_lifetime_value clv
ON clv.c_nationkey = n_nationkey
GROUP BY 1;
1条答案
按热度按时间db2dz4w81#
你能试试这个吗?它应该读更少的数据,并给予你相同的输出:
如果正确,则可以创建简单索引: