为什么从SQL加载数据比excel慢得多?

时间:2019-03-25 14:22:41

标签: ssas ssas-tabular

我在SSDT中创建了一个简单的表格模型,已将其部署到本地SSAS实例(兼容性模型= Azure Analysis Services / SQL Server 2017(1400)

在我的两个测试源下面,一个来自本地SQL 2017服务器,另一个来自本地Excel文件。这两个源只有一个表,每个表有4行。

"dataSources": [
      {
        "type": "structured",
        "name": "SQL/localhost;MyDB",
        "connectionDetails": {
          "protocol": "tds",
          "address": {
            "server": "localhost",
            "database": "MyDB"
          },
          "authentication": null,
          "query": null
        },
        "credential": {
          "AuthenticationKind": "UsernamePassword",
          "kind": "SQL",
          "path": "localhost;MyDB",
          "Username": "MyUserName",
          "EncryptConnection": false
        }
      },
      {
        "type": "structured",
        "name": "FileExcel",
        "connectionDetails": {
          "protocol": "file",
          "address": {
            "path": "C:\\testExcelForSSAS.xlsx"
          },
          "authentication": null,
          "query": null
        },
        "credential": {
          "AuthenticationKind": "Windows",
          "kind": "File",
          "path": "c:\\testexcelforssas.xlsx",
          "Username": "MyUserName"
        },
        "contextExpression": [
          "let",
          "    #\"0001\" = Excel.Workbook(..., null, true)",
          "in",
          "    #\"0001\""
        ]
      }
    ],

问题:(完全)处理excel表源需要不到1秒的时间, (完整)处理SQL表最多需要20秒。

我执行了SQL跟踪,此查询(在ExecuteSQL EventSubClass中)花费20秒:

let __AS_Query__ =  let
    Source = #"SQL/localhost;MyDB",
    dbo_formulas = Source{[Schema="dbo",Item="formulas"]}[Data],
    #"Added Custom" = Table.AddColumn(dbo_formulas, "NameWithID", each [NameEU] & " (" & Number.ToText([ID])) in
    #"Added Custom" , __AS_Table__ = Table.FromValue(__AS_Query__) in Table.RemoveColumns(__AS_Table__, Table.ColumnsOfType(__AS_Table__, { type table, type record, type list }))

作为参考,这是对Excel数据的调用

let __AS_Query__ = 
let
    Source = #"FileExcel",
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data]
in
    Table1_Table
, __AS_Table__ = Table.FromValue(__AS_Query__)
in
Table.RemoveColumns(__AS_Table__, Table.ColumnsOfType(__AS_Table__, { type table, type record, type list }))

为什么简单的查询从SQL提取4行需要20秒,而从Excel提取相同数量的数据却不到一秒钟?

编辑: 我在结果下方的SQL Server上进行了跟踪。真正的SQL查询(突出显示)几乎不需要时间,但是在此之前的其他一些查询则需要很长时间。这是由于与该SQL Server的SSAS连接的某些配置有关吗?

SQL Server Trace

谢谢

0 个答案:

没有答案