【发布时间】: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 也很慢。
-
显示实际代码。
-
我的问题已使用生成的查询进行编辑