-
-
Notifications
You must be signed in to change notification settings - Fork 154
Support for PostgreSQL SKIP LOCKED #238
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
Conversation
As query.forUpdate(skipLocked = true) Generated SQL: select ... for update skip locked It will be great if can also support query.forUpdate(nowait = true) Generate SQL: select ... for update nowait And: query.forUpdate(wait = 3) SQL: select ... for update wait 3 To implement this, we can deprecate the forUpdate property in What do you think? |
(...)
Having parameters in this way does sound better, yes! Up until the last paragraph though, I was thinking of just overloading the forUpdate method in the Postgres-module with extra parameters, but then you wrote that about a structured data class - I'm not entirely sure if I understand what you mean by that in this context? |
I mean it would be better if this PR can implement more public data class SelectExpression(
val columns: List<ColumnDeclaringExpression<*>> = emptyList(),
val from: QuerySourceExpression,
val where: ScalarExpression<Boolean>? = null,
val groupBy: List<ScalarExpression<*>> = emptyList(),
val having: ScalarExpression<Boolean>? = null,
val isDistinct: Boolean = false,
val forUpdate: SelectForUpdateOptions = SelectForUpdateOptions.None,
override val orderBy: List<OrderByExpression> = emptyList(),
override val offset: Int? = null,
override val limit: Int? = null,
override val tableAlias: String? = null,
override val extraProperties: Map<String, Any> = emptyMap()
) : QueryExpression()
public sealed class SelectForUpdateOptions {
public object None : SelectForUpdateOptions()
public object SkipLocked : SelectForUpdateOptions()
public object NoWait : SelectForUpdateOptions()
public data class Wait(val seconds: Int) : SelectForUpdateOptions()
} Don't hesitate to ask me if you have any other questions. |
Okay, I see what you mean. The only thing I don't quite like about that solution is that "skip locked" is postgres specific - it doesn't really seem elegant to put explicit support for it in the main library, as I believe we'd have to do in this case. (Correct me if I'm wrong.) Nowait on the other hand exists in more dialects, oracle at least, but as far as I can see its not universal - SQL Server is missing it, as far as I can see. Although now that I'm trying to find it, I'm not sure SQL Server has any support for "for update" in the first place? (See: https://docs.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql?view=sql-server-ver15 ) If indeed I'm correct in I'll update the PR to reflect these thoughts if you agree. |
Yes, |
You might need two MySQL dialects to support this. Both 5.7 and 8.0 have two locking modes, share and update, but the syntax is different. 5.7 share: 8.0 share: |
Hm. Is there any prior work in Ktorm where there is support for several versions of a DBMS' dialect? |
dataSource.connection.use { connection ->
when (val databaseMajorVersion = connection.metaData.databaseMajorVersion) {
5 -> {
// MySql5Dialect
}
8 -> {
// MySql8Dialect
}
else -> throw UnsupportedMySqlVersion(databaseMajorVersion)
}
} edit: disregard all that. |
I took a stab at it here: Feel free to use/modify that. MySql 5, MySql 8 and Postgres should be fully implemented. Oracle and SqlServer only have the basic "for update" options. SQLite throws edit: tweaked Postgres to follow the docs. Oracle could be done similarly. |
Yes, we already have productVersion in |
Updated my branch to use |
Should I submit a separate PR? |
@efenderbosch Yes, please create another PR. |
I'm sorry about dropping the ball here, life got chaotic. My understanding is that efenderbosch's PR will now solve this ,so I should just close this PR`? |
Close this PR since #247 was merged. |
This code allows for SKIP LOCKED to be used in the postgres dialect.
I had to upgrade some libraries for the gradle build to run green on my machine, these upgrades are also included here.
Please let me know if something here isn't up to your standards, and I'll try to fix it.