【问题标题】:Slow Select query execution on Date column在日期列上执行慢选择查询
【发布时间】:2018-04-12 17:53:17
【问题描述】:

我从 SQL CE 数据库迁移到 SQLite 数据库 (3.18.0),但是当 Select 中有日期时间列时,我的查询速度很慢。

存储日期时间的我的 SQLite 列是 INTEGER 类型。日期以 UNIX 纪元(秒)存储。

在一个有 15 列和 1000 条记录的表上,我的查询大约需要 3 秒。 没有日期(只有名称)的相同查询是即时的。

SELECT Name,
CreatedDate    
FROM [Table] 

门有什么特别之处吗?我必须在 Text 中存储日期吗?

编辑:

从实体框架,生成的查询是:

SELECT 
[Extent1].[VisualizationIndex] AS [VisualizationIndex], 
[Extent1].[Identifier] AS [Identifier], 
[Extent1].[IdentifierParent] AS [IdentifierParent], 
[Extent1].[IdentifierEnvironment] AS [IdentifierEnvironment], 
[Extent1].[IdentifierReference] AS [IdentifierReference], 
[Extent1].[Name] AS [Name], 
[Extent1].[Description] AS [Description], 
[Extent1].[Type] AS [Type], 
[Extent1].[Visibility] AS [Visibility], 
[Extent1].[Layer] AS [Layer], 
[Extent1].[Version] AS [Version], 
[Extent1].[Created] AS [Created], 
[Extent1].[LastModified] AS [LastModified]
FROM [CV_UsersComponents] AS [Extent1]
ORDER BY [Extent1].[Name] ASC

-- Executing at 10/31/2017 4:52:47 PM +01:00
-- Completed in 3433 ms with result: SQLiteDataReader

【问题讨论】:

  • 如果您选择日期列,但实际上并没有在您的代码中读取它,它是否仍然很慢?
  • 我正在使用 ErikEJ 的 SQLite/SQL Server Compact 工具箱在 Visual Studio 中进行选择,所以可能有一些东西放慢了速度。
  • 而且在实体框架 6 中使用 SQLite 也很慢。
  • 显示实际代码。
  • 我的问题已使用生成的查询进行编辑

标签: sqlite system.data.sqlite


【解决方案1】:

我终于找到了性能问题的根源。 在 SQLite 中,列顺序非常重要!

我将“created”和“lastModified”列移到存储一些 XML 数据的 TEXT 类型列之前。

那么我的查询现在是即时的。 更多信息在这里: http://sqlite.1065341.n5.nabble.com/Does-column-order-matter-for-performance-td81880.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-05
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多