56,677
社区成员
发帖
与我相关
我的任务
分享
Table [t_tension]
Fields: 3
[id]: INTEGER
[value]: real
[c_time]: text
Foreign Keys: 0
Indexes: 1
[cool]
[c_time]
Triggers: 0
Unique constraints: 0
Check constraints: 0
这是我的表结构,索引为cool,c_time字段,可下面这句查询还是很慢,似乎索引没有起来到作用
select id,value,c_time from t_tension where datetime(c_time)>='2015-10-10 02:02:02' and datetime(c_time)<= '2015-10-10 02:10:00' limit 100;
表结构:
Table [t_tension]
Fields: 3
[id]: INTEGER
[value]: real
[c_time]: text
Foreign Keys: 0
Indexes: 1
[cool]
[c_time]
Triggers: 0
Unique constraints: 0
Check constraints: 0
表的数据:
id value c_time
1 41 2014-12-04 08:59:30
1 467 2014-12-04 08:59:31
1 334 2014-12-04 08:59:32
1 500 2014-12-04 08:59:33
1 169 2014-12-04 08:59:34
1 724 2014-12-04 08:59:35
1 478 2014-12-04 08:59:36
1 358 2014-12-04 08:59:37
1 962 2014-12-04 08:59:38
1 464 2014-12-04 08:59:39
1 705 2014-12-04 08:59:40
1 145 2014-12-04 08:59:41
1 281 2014-12-04 08:59:42
1 827 2014-12-04 08:59:43
1 961 2014-12-04 08:59:44
1 491 2014-12-04 08:59:45
1 995 2014-12-04 08:59:46
.........
查询代码:
select id,value,c_time from t_tension where datetime(c_time)>='2015-10-10 02:02:02' and datetime(c_time)<= '2015-10-10 02:10:00' limit 100;
我反复测试发现,感觉sqlite对text排序太慢,虽然加了索引。结果把c_time 转成real类型,就是把时间转double存,再搜索,加索引与不加索引的差距就出来了。我不知道mysql数据库怎么样,若查询快的话我在考虑要不要换数据库