【问题标题】:How to select only a few fields using kotlin exposed?如何使用暴露的 kotlin 只选择几个字段?
【发布时间】:2022-12-14 06:39:40
【问题描述】:

我有一个包含 2,600,000 条记录的大数据库,我想通过遍历所有记录对其进行一些高级搜索。但是,使用selectAll() 运行脚本需要很长时间才能加载。

作为一种解决方法,我使用以下代码将 100,000 条记录循环 26 次:

for (i in 1..26) {
    transaction {
        for (app in AppsTable.selectAll().limit(n = 100000, offset = i * 100000L)) {

            //..analysis
        }
    }
}

我怎样才能加快这个查询,或者如果可能的话,我怎样才能减少查询集的查询只是我需要使用的列?例如,我可以做这样的事情吗 -

AppsTable.selectAll(AppsTable.name, AppsTable.downloadCount, AppsTable.developerId)

【问题讨论】:

    标签: sql kotlin kotlin-exposed


    【解决方案1】:

    只需在 selectAll() 之前使用 slice() 方法,如下所示: AppsTable.slice(AppsTable.name, AppsTable.downloadCount, AppsTable.developerId).selectAll().limit(n = 100000, offset = i * 100000L)

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多