Browse Source

Improve SQL

jaguililla 7 months ago
parent
commit
34125b7402

+ 4 - 4
frameworks/Kotlin/hexagon/store_pgclient/src/main/kotlin/BenchmarkPgClientStore.kt

@@ -19,9 +19,10 @@ class BenchmarkPgClientStore(
 ) : BenchmarkStore(settings) {
 ) : BenchmarkStore(settings) {
 
 
     companion object {
     companion object {
-        private const val SELECT_WORLD: String = "select * from world where id = $1"
+        private const val LOAD_WORLDS: String = "select id, randomNumber from world"
+        private const val SELECT_WORLD: String = "select id, randomNumber from world where id = $1"
         private const val UPDATE_WORLD: String = "update world set randomNumber = $1 where id = $2"
         private const val UPDATE_WORLD: String = "update world set randomNumber = $1 where id = $2"
-        private const val SELECT_ALL_FORTUNES: String = "select * from fortune"
+        private const val SELECT_ALL_FORTUNES: String = "select id, message from fortune"
     }
     }
 
 
     private val connectOptions: PgConnectOptions by lazy {
     private val connectOptions: PgConnectOptions by lazy {
@@ -81,13 +82,12 @@ class BenchmarkPgClientStore(
                 .toCompletionStage()
                 .toCompletionStage()
                 .toCompletableFuture()
                 .toCompletableFuture()
                 .get()
                 .get()
-
         }
         }
     }
     }
 
 
     override fun initWorldsCache(cache: Cache<Int, CachedWorld>) {
     override fun initWorldsCache(cache: Cache<Int, CachedWorld>) {
         dataSource
         dataSource
-            .preparedQuery("select * from world")
+            .preparedQuery(LOAD_WORLDS)
             .execute()
             .execute()
             .map { rowSet ->
             .map { rowSet ->
                 rowSet.map { row ->
                 rowSet.map { row ->

+ 4 - 3
frameworks/Kotlin/hexagon/store_sql/src/main/kotlin/BenchmarkSqlStore.kt

@@ -16,9 +16,10 @@ class BenchmarkSqlStore(
 ) : BenchmarkStore(settings) {
 ) : BenchmarkStore(settings) {
 
 
     companion object {
     companion object {
-        private const val SELECT_WORLD: String = "select * from world where id = ?"
+        private const val LOAD_WORLDS: String = "select id, randomNumber from world"
+        private const val SELECT_WORLD: String = "select id, randomNumber from world where id = ?"
         private const val UPDATE_WORLD: String = "update world set randomNumber = ? where id = ?"
         private const val UPDATE_WORLD: String = "update world set randomNumber = ? where id = ?"
-        private const val SELECT_ALL_FORTUNES: String = "select * from fortune"
+        private const val SELECT_ALL_FORTUNES: String = "select id, message from fortune"
     }
     }
 
 
     private val dataSource: HikariDataSource by lazy {
     private val dataSource: HikariDataSource by lazy {
@@ -87,7 +88,7 @@ class BenchmarkSqlStore(
 
 
     override fun initWorldsCache(cache: Cache<Int, CachedWorld>) {
     override fun initWorldsCache(cache: Cache<Int, CachedWorld>) {
         dataSource.connection.use { con: Connection ->
         dataSource.connection.use { con: Connection ->
-            val stmtSelect = con.prepareStatement("select * from world")
+            val stmtSelect = con.prepareStatement(LOAD_WORLDS)
             val rs = stmtSelect.executeQuery()
             val rs = stmtSelect.executeQuery()
 
 
             while (rs.next()) {
             while (rs.next()) {