From 0bce26158d3a17023f50b7df653a726fdf0d16f6 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 8 Oct 2023 05:41:30 -0400 Subject: [PATCH] fix agg hash calc --- Cargo.lock | 6 ++++-- Cargo.toml | 2 +- martin-mbtiles/src/mbtiles.rs | 26 ++++++++++---------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e79a8df5..39b7611a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3042,11 +3042,13 @@ dependencies = [ [[package]] name = "sqlite-hashes" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd203121770e67b5f689ebf9592c88d3529193743f35630413f419be8ef1e835" +checksum = "6d63457e88dae0e28722a486739557b36d90c26839915708dda29effd8369853" dependencies = [ "digest", + "hex", + "log", "md-5", "rusqlite", "sha1", diff --git a/Cargo.toml b/Cargo.toml index 1459eaa9d..d4f380e60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" serde_yaml = "0.9" spreet = { version = "0.8", default-features = false } -sqlite-hashes = "0.3" +sqlite-hashes = "0.4" sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio"] } subst = { version = "0.3", features = ["yaml"] } thiserror = "1" diff --git a/martin-mbtiles/src/mbtiles.rs b/martin-mbtiles/src/mbtiles.rs index d152b3c5d..4a088686e 100644 --- a/martin-mbtiles/src/mbtiles.rs +++ b/martin-mbtiles/src/mbtiles.rs @@ -640,27 +640,21 @@ where // Note that ORDER BY controls the output ordering, which is important for the hash value, // and having it at the top level would not order values properly. // See https://sqlite.org/forum/forumpost/228bb96e12a746ce - // Sadly, this is still not a guaranteed solution as it is possible, in the future, for the optimizer to change. - "SELECT - hex( - coalesce( - md5_concat( + " +SELECT coalesce( + (SELECT md5_concat_hex( cast(zoom_level AS text), cast(tile_column AS text), cast(tile_row AS text), tile_data - ), - md5('') ) - ) - FROM ( - SELECT zoom_level, - tile_column, - tile_row, - tile_data - FROM tiles - ORDER BY zoom_level, tile_column, tile_row - );", + OVER (ORDER BY zoom_level, tile_column, tile_row ROWS + BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) + FROM tiles + LIMIT 1), + md5_hex('') +); +", ); Ok(query.fetch_one(conn).await?.get::(0)) }