Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite adapter: performance issues during insert operations #1581

Open
lehvolk opened this issue Aug 30, 2022 · 5 comments
Open

SQLite adapter: performance issues during insert operations #1581

lehvolk opened this issue Aug 30, 2022 · 5 comments
Assignees
Labels
waiting for reply Additional information required

Comments

@lehvolk
Copy link

lehvolk commented Aug 30, 2022

I have an application that doing large number of inserts during startup. CPU snapshot shows that about 10% of time consumed by creating SQLExcpetions based on missed columns in ResultSet returned by JDBC driver.

Preconditions
Having this as dependencies

    implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.39.2.1'

    api group: 'org.jetbrains.exposed', name: 'exposed-core', version: '0.39.2'
    api group: 'org.jetbrains.exposed', name: 'exposed-dao', version: '0.39.2'
    api group: 'org.jetbrains.exposed', name: 'exposed-jdbc', version: '0.39.2'

Having dummy scheme:

object Locations : IntIdTable() {
    val path = varchar("path", length = 1024)
    val runtime = bool("runtime").default(false)
    val outdated = reference("outdated_id", Locations.id).nullable()
}

and code:

Locations.insertAndGetId {
    it[path] = "smth"
}

This code produces 4 SQLExceptions with message no such column: 'id' and no such column: 'id', no such column: 'path'. no such column: 'runtime' and no such column: 'outdated'

As I can see in debug after insert driver returns result set for query select last_insert_rowid() and Exposed tries to restore entity with it.

@Tapac
Copy link
Contributor

Tapac commented Oct 2, 2022

Do you create tables with Exposed or you use existing table? Can you share CREATE TABLE statement for your Locations db?

@Tapac Tapac added the waiting for reply Additional information required label Oct 4, 2022
@lehvolk
Copy link
Author

lehvolk commented Oct 17, 2022

Do you create tables with Exposed.

Yes. Tables created with SchemaUtils. As a result SQL query is produced by SchemaUtils.

@Tapac
Copy link
Contributor

Tapac commented Nov 12, 2022

Do you have any SQLite specific parameters set to your connection?

@lehvolk
Copy link
Author

lehvolk commented Nov 30, 2022

Do you have any SQLite specific parameters set to your connection?

No. Something like this:

        val config = SQLiteConfig().also {
            it.setSynchronous(SQLiteConfig.SynchronousMode.OFF)
            it.setJournalMode(SQLiteConfig.JournalMode.OFF)
            it.setPageSize(32_768)
            it.setCacheSize(-8_000)
        }
        if (location == null) {
            val url = "jdbc:sqlite:file:jcdb-${UUID.randomUUID()}?mode=memory&cache=shared&rewriteBatchedStatements=true"
            dataSource = SQLiteDataSource(config).also {
                it.url = url
            }
        } else {
           dataSource = SQLiteDataSource(config).also {
                it.url = url
            }
        }

@joc-a
Copy link
Collaborator

joc-a commented Oct 13, 2023

Hey @lehvolk. I tried to reproduce this issue with your setup but couldn't. Could you please verify that it still happens in the latest Exposed version (0.43.0 at the time of writing)?

I have an application that doing large number of inserts during startup.

How large?

@joc-a joc-a self-assigned this Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for reply Additional information required
Projects
None yet
Development

No branches or pull requests

3 participants