从包含的连接中创建临时 table + 6500 万条记录 Mysql
create temp table from join contained + 65 milion of records Mysql
我正在使用 Mysql 我有两个 tables,我在 proc 运行 期间对其进行了多次选择,每个都超过 1 亿条记录,以加快速度proc 我想做这个 join ones have it as temp table (contains 65+ milion of records), later use this table in procedure .创建它。我在用 。下一个 。
create temporary table T_join (INDEX(tm_id))
SELECT
t1.id,
t2.tm_id,
t1.code,
t1.bincode,
t1.AU,
t1.TA,
t2.fin_amount,
t2.m_id
FROM
pm_customers t1
INNER JOIN
client_transactions_final t2 ON t1.id = t2.id
所有直截了当的唯一问题是创建这个临时文件 table proc 花费了 20 多分钟,如何加速它?
对于此查询:
SELECT c.id, ct.tm_id, c.code, t1.bincode, c.AU, c.TA,
ct.fin_amount, ct.m_id
FROM pm_customers c INNER JOIN
client_transactions_final ct
ON c.id = ct.id;
您可能需要 client_transactions_final(id, tm_id, fin_amount, m_id)
上的索引。这是查询的覆盖索引,因此应该会提高性能。
我不相信您真的需要创建这个临时表。使用正确的索引,连接通常非常快。当您有聚合和更复杂的查询时,临时表更有意义。我并不是说它行不通,只是它不是第一个想到的解决方案。
我正在使用 Mysql 我有两个 tables,我在 proc 运行 期间对其进行了多次选择,每个都超过 1 亿条记录,以加快速度proc 我想做这个 join ones have it as temp table (contains 65+ milion of records), later use this table in procedure .创建它。我在用 。下一个 。
create temporary table T_join (INDEX(tm_id))
SELECT
t1.id,
t2.tm_id,
t1.code,
t1.bincode,
t1.AU,
t1.TA,
t2.fin_amount,
t2.m_id
FROM
pm_customers t1
INNER JOIN
client_transactions_final t2 ON t1.id = t2.id
所有直截了当的唯一问题是创建这个临时文件 table proc 花费了 20 多分钟,如何加速它?
对于此查询:
SELECT c.id, ct.tm_id, c.code, t1.bincode, c.AU, c.TA,
ct.fin_amount, ct.m_id
FROM pm_customers c INNER JOIN
client_transactions_final ct
ON c.id = ct.id;
您可能需要 client_transactions_final(id, tm_id, fin_amount, m_id)
上的索引。这是查询的覆盖索引,因此应该会提高性能。
我不相信您真的需要创建这个临时表。使用正确的索引,连接通常非常快。当您有聚合和更复杂的查询时,临时表更有意义。我并不是说它行不通,只是它不是第一个想到的解决方案。