简体   繁体   English

大数据库中的大数据如何选择导出到excel-SQL

[英]How to select and export the large data in big database to excel - SQL

**My task is selecting and exporting a large monitoring data from database ** **我的任务是从数据库中选择和导出大量监控数据**
My database have two big tables to store monitoring data.我的数据库有两个大表来存储监控数据。
- Table MonitoringDataInfo (~60M rows): have some fields id (pk), stationId, createdAt and one group index ( stationId asc, createdAt desc) - 表MonitoringDataInfo (~60M 行):有一些字段id(pk)、stationId、createdAt和一组索引( stationId asc、 createdAt desc)
- Table MonitoringData (~300M rows): have some fields id (pk), dataId, indicator, value, unit and one group index ( dataId asc, indicator asc) - 表监控数据(~300M 行):有一些字段id (pk)、dataId、indicator、value、unit和一组索引( dataId asc、 indicator asc)
( id of MonitoringDataInfo is foreign key of dataId of MonitoringData ) (MonitoringDataInfoIDMonitoringData数据ID的外键)
I do a query below:我在下面做一个查询:

SELECT
  [Info].[id], [Info].[sentAt], [Data].[id] AS [Data.id], [Data].[indicator] AS [Data.indicator], [Data].[value] AS [Data.value]
FROM
  [monitoring_data_info] AS [Info]
LEFT OUTER JOIN
  [monitoring_data] AS [Data]
    ON [Info].[id] = [Data].[dataId]
WHERE
      [Info].[stationId] = N'EKTjhVrZibUE7h55b6tu'
  AND [Info].[createdAt] BETWEEN N'2021-10-07 07:14:51.000 +00:00' AND N'2021-10-14 07:14:51.000 +00:00'
ORDER BY
  [Info].[createdAt] ASC;

==> This query return 69253 rows after more than 10 minutes. ==> 此查询在超过10分钟后返回69253行。

My Questions are:我的问题是:
- How should I do to optimize the execution time as well as database? - 我应该如何优化执行时间以及数据库?

Thanks in advand!先谢谢了!

Create an index on either of below columns在以下任一列上创建索引

    id, stationId, createdAt, sentAt column of 
    monitoring_data_info table

   and  dataId column of monitoring_data table 

depending upon the data you can have your indexes made especially on joined columns and where clause columns根据数据,您可以创建索引,特别是在连接列和 where 子句列上

Also, Dont overload the indexes too as i could see you have grouped index though it includes the necessary column but additional column in the group index may have cause to resort the data likewise would recommend to have index on just joined columns and sentAt as per your recent edit另外,不要使索引超载,因为我可以看到您已经对索引进行了分组,尽管它包含必要的列,但组索引中的其他列可能会导致重新使用数据,同样建议在刚刚加入的列上建立索引并根据您的发送最近编辑

Is that query in Excel?该查询是在 Excel 中吗?

It might be faster to export the two sheets into database tables with minimal conversion or querying.以最少的转换或查询将这两个工作表导出到数据库表中可能会更快。 Then do the Joining/Grouping in the database engine, which is more optimized for such.然后在数据库引擎中进行Joining/Grouping,针对此类进行了更优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM