我所有人,我有 2 个类似的非常大的表(每个 1M 行)具有相同的布局,我会将它们合并并按一个公共列排序: start 。我也会在“开始”中设置一个条件,即:开始> X。问题是视图不关心开始的索引并且复杂性上升很多,一个简单的查询大约需要 15 秒并且插入一个 LIMIT 并不能解决,因为结果首先被切断。
CREATE VIEW CDR AS
(SELECT start, duration, clid, FROM cdr_md ORDER BY start LIMIT 1000)
UNION ALL
(SELECT start, duration, clid, FROM cdr_1025 ORDER BY start LIMIT 1000)
ORDER BY start ;
查询:
SELECT * FROM CDR WHERE start>10
不返回预期结果导致 LIMIT 关键字事先切断结果。
预期的结果将是这样的查询:
CREATE VIEW CDR AS
(SELECT start, duration, clid, FROM cdr_md WHERE start>X ORDER BY start LIMIT 1000)
UNION ALL
(SELECT start, duration, clid, FROM cdr_1025 WHERE start>X ORDER BY start LIMIT 1000)
ORDER BY start ;
有没有办法避免这个问题?谢谢法布里齐奥