Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – 计算sqlite数据库中的行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我在运行 Linux的ARM嵌入式平台上有一个sqlite数据库,资源有限.存储设备是microSD卡. sqlite版本是3.7.7.1.访问sqlite的应用程序是用C语言编写的. 我想以规则的间隔知道几个表中的行数.我目前正在使用 SELEct count(*) from TABLename; 获取此信息.我遇到了性能问题:当表格大小达到某一点(~200K行)时,每次检查表格大小时都会有很多
@H_489_18@ 我在运行 @L_944_0@的ARM嵌入式平台上有一个sqlite数据库,资源有限.存储设备是microSD卡. sqlite版本是3.7.7.1.访问sqlite的应用程序是用C语言编写的.

我想以规则的间隔知道几个表中的行数.我目前正在使用

SELEct count(*) from TABLename;

获取此信息.我遇到了性能问题:当表格大小达到某一点(~200K行)时,每次检查表格大小时都会有很多系统和iowait加载.

当我写这篇文章时,我然查找表中的行数会很快,因为它可能存储在某个地方.但是现在我怀疑sqlite实际上是查看所有行的,当我通过数据不适合磁盘缓存的点时,我得到了很多io加载.这大致适合数据库大小和可用内存.

任何人都能告诉我sqlite是否以我怀疑的方式行事?

有没有办法获得表行数而不产生这样的负载量?

编辑:plaes询问了表格布局:

create table %s (timestamp INTEGER PRIMARY KEY,offset IntegeR,value NUMERIC);

解决方法

这个表有整数索引吗?如果没有,那么添加一个.否则它必须扫描整个表来计算项目.

这是sqlite代码中的注释的摘录,它实现了COUNT()解析和执行:

/* If isSimpleCount() returns a pointer to a Table structure,then
    ** the sql statement is of the form:
    **
    **   SELECT count(*) FROM <tbl>
    **
    ** where the Table structure returned represents table <tbl>.
    **
    ** This statement is so common that it is optimized specially. The
    ** OP_Count instruction is executed either on thE intkey table that
    ** contains the data for table <tbl> or on one of its indexes. It
    ** is better to execute the op on an index,as indexes are almost
    ** always spread across less pages than their corresponding tables.
    */
    [...]
    /* Search for the index that has the least amount of columns. If
    ** there is such an index,and it has less columns than the table
    ** does,then we can assume that it consumes less space on disk and
    ** will therefore be cheaper to scan to determine the query result.
    ** In this case set iRoot to the root page number of the index b-tree
    ** and pKeyInfo to the KeyInfo structure required to navigate the
    ** index.
    **
    ** (2011-04-15) Do not do a full scan of an unordered index.

此外,您可以使用EXPLAIN QUERY PLAN来查询您的查询.

大佬总结

以上是大佬教程为你收集整理的linux – 计算sqlite数据库中的行全部内容,希望文章能够帮你解决linux – 计算sqlite数据库中的行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。