Skip to content

Commit 7d70865

Browse files
authored
Change to operators that will hit GIN index on Naksha feature tags (#577)
* CASL-1799 adjust where query, allow and filter out null Signed-off-by: phmai <phuc.mai@here.com> * CASL-1799 version Signed-off-by: phmai <phuc.mai@here.com> * CASL-1799 escaping Signed-off-by: phmai <phuc.mai@here.com> --------- Signed-off-by: phmai <phuc.mai@here.com>
1 parent 0290ea2 commit 7d70865

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mavenPassword=YourPassword
1616
# here-naksha-lib-psql/src/commonMain/kotlin/naksha/psql/LibPsql.kt (adminVersion property)
1717
# Warning: Only update LibPsql version, if there is a change in SQL functions!
1818
# The reason is, that this version is encoded in the database, and when updated, forced an upgrade!
19-
version=3.0.0-beta.36
19+
version=3.0.0-beta.37
2020

2121
org.gradle.jvmargs=-Xmx12g
2222
kotlin.code.style=official

here-naksha-app-service/src/jvmMain/resources/swagger/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ servers:
1212
info:
1313
title: "Naskha Hub-API"
1414
description: "Naksha Hub-API is a REST API to provide simple access to geo data."
15-
version: "3.0.0-beta.36"
15+
version: "3.0.0-beta.37"
1616

1717
security:
1818
- AccessToken: [ ]

here-naksha-lib-model/src/commonMain/kotlin/naksha/model/NakshaVersion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class NakshaVersion(
8989
* The current version as string to constant usage cases.
9090
* @since 3.0
9191
*/
92-
const val CURRENT = "3.0.0-beta.36"
92+
const val CURRENT = "3.0.0-beta.37"
9393
// WARNING: Do not update this property manually, it is automatically modified when building!
9494
// Edit version only in `gradle.properties` file, which is used as well to create artifacts!
9595

here-naksha-lib-psql/src/commonMain/kotlin/naksha/psql/PgQueryWhereBuilder.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ internal class PgQueryWhereBuilder(private val request: ReadFeatures) {
334334
if(containsOnlyTagExists(tagQuery)){
335335
// for tags without values we can utilize top-level-key based '?|' operand
336336
// https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
337+
val tagNames = tagQuery.filterIsInstance<TagExists>().map { it.name }
337338
resolveTagNamesArrayOperation(
338-
jsonbOperator = "jsonb_exists_any", // equivalent of '?|'
339-
tagNames = (tagQuery as ListProxy<TagExists>).mapNotNull { it?.name }
339+
jsonbOperator = "?|", // 'jsonb_exists_any' is equivalent but will not hit the GIN index
340+
tagNames = tagNames
340341
)
341342
} else {
342343
or(tagQuery.filterNotNull(), this::whereNestedTags)
@@ -346,9 +347,10 @@ internal class PgQueryWhereBuilder(private val request: ReadFeatures) {
346347
if(containsOnlyTagExists(tagQuery)){
347348
// for tags without values we can utilize top-level-key based '?&' operand
348349
// https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
350+
val tagNames = tagQuery.filterIsInstance<TagExists>().map { it.name }
349351
resolveTagNamesArrayOperation(
350-
jsonbOperator = "jsonb_exists_all", // equivalent of '?&'
351-
tagNames = (tagQuery as ListProxy<TagExists>).mapNotNull { it?.name }
352+
jsonbOperator = "?&", // 'jsonb_exists_all' is equivalent but MIGHT not hit the GIN index
353+
tagNames = tagNames
352354
)
353355
} else {
354356
and(tagQuery.filterNotNull(), this::whereNestedTags)
@@ -359,12 +361,12 @@ internal class PgQueryWhereBuilder(private val request: ReadFeatures) {
359361
}
360362

361363
private fun containsOnlyTagExists(container: ListProxy<ITagQuery>): Boolean =
362-
container.all { it is TagExists }
364+
container.all { it == null || it is TagExists }
363365

364366
private fun resolveTagNamesArrayOperation(jsonbOperator: String, tagNames: List<String>) {
365367
val tagKeysArray = tagNames.toTypedArray()
366368
val tagKeysPlaceholder = placeholderForArg(tagKeysArray, PgType.STRING_ARRAY)
367-
where.append("$jsonbOperator($tagsAsJsonb, $tagKeysPlaceholder)")
369+
where.append("$tagsAsJsonb ?$jsonbOperator $tagKeysPlaceholder")
368370
}
369371

370372
private fun resolveSingleTagQuery(tagQuery: TagQuery) {

0 commit comments

Comments
 (0)