TDengine icon indicating copy to clipboard operation
TDengine copied to clipboard

UNION ALL clause query 41 tables

Open caiqiqqq opened this issue 2 years ago • 3 comments

Problem Description 使用UNION ALL 子句查询41 张子表,480条数据,查询耗时2845 毫秒,超级表不同

To Reproduce sql语句:SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610967024932' as TableName FROM s_1647497419629_1610967024932 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611382367705' as TableName FROM s_1647485259391_1611382367705 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610967267272' as TableName FROM s_1647497419629_1610967267272 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610967638096' as TableName FROM s_1647497419629_1610967638096 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611382872373' as TableName FROM s_1647485259391_1611382872373 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610967923363' as TableName FROM s_1647497419629_1610967923363 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610965289490' as TableName FROM s_1648602716281_1610965289490 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610965126877' as TableName FROM s_1648602716281_1610965126877 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610964979809' as TableName FROM s_1648602716281_1610964979809 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610964013250' as TableName FROM s_1648602716281_1610964013250 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610965186107' as TableName FROM s_1648602716281_1610965186107 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610969578396' as TableName FROM s_1647497419629_1610969578396 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610969647147' as TableName FROM s_1647497419629_1610969647147 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610966304387' as TableName FROM s_1648602716281_1610966304387 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610966144060' as TableName FROM s_1648602716281_1610966144060 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610965981709' as TableName FROM s_1648602716281_1610965981709 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610966362266' as TableName FROM s_1648602716281_1610966362266 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610966444739' as TableName FROM s_1648602716281_1610966444739 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610969062988' as TableName FROM s_1647497419629_1610969062988 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610969166562' as TableName FROM s_1647497419629_1610969166562 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610969499779' as TableName FROM s_1647497419629_1610969499779 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610969399326' as TableName FROM s_1647497419629_1610969399326 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610963791897' as TableName FROM s_1648602716281_1610963791897 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610961730810' as TableName FROM s_1648602716281_1610961730810 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610962959593' as TableName FROM s_1648602716281_1610962959593 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610962992601' as TableName FROM s_1648602716281_1610962992601 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610963025745' as TableName FROM s_1648602716281_1610963025745 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610963774281' as TableName FROM s_1648602716281_1610963774281 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610963596955' as TableName FROM s_1648602716281_1610963596955 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610963744069' as TableName FROM s_1648602716281_1610963744069 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610968708388' as TableName FROM s_1647497419629_1610968708388 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610968928125' as TableName FROM s_1647497419629_1610968928125 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610968106860' as TableName FROM s_1647497419629_1610968106860 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610967393070' as TableName FROM s_1647497419629_1610967393070 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1610968352155' as TableName FROM s_1647497419629_1610968352155 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611386556833' as TableName FROM s_1647485259391_1611386556833 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611386249575' as TableName FROM s_1647485259391_1611386249575 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611386066868' as TableName FROM s_1647485259391_1611386066868 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611386399016' as TableName FROM s_1647485259391_1611386399016 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611043961080' as TableName FROM s_1643108568883_1611043961080 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d) union ALL SELECT first(ep) as first,last(ep) as last,first(pt) as firstpt ,last(pt) as lastpt,'1611043196371' as TableName FROM s_1643108568883_1611043196371 WHERE ts > '1656847603000' and ts <= '1658143603000'and ep > 0 interval(1d)

服务端版本:2.4 java 使用的是 springboot+mybits
链接池。 druid

caiqiqqq avatar Jul 18 '22 11:07 caiqiqqq

查询速度过慢,有什么办法提供查询速度吗?

caiqiqqq avatar Jul 18 '22 11:07 caiqiqqq

480条数据是这个查询结果集的还是全部表所有的?

fenghuazzm avatar Jul 19 '22 02:07 fenghuazzm

480条数据是这个查询结果集的还是全部表所有的?

结果集

caiqiqqq avatar Jul 19 '22 03:07 caiqiqqq