From 5e263c0e0f704c0e5d51bb71d367e742d842d34c Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Mon, 25 Jul 2016 22:14:06 +1000 Subject: [PATCH] Use "COALESCE(x, 0)" instead of "x = 0 OR x IS NULL" This is a more concise syntax to say the same thing, and avoids an OR clause in the where - which is often the cause of slowness in many queries. Not sure if it was problematic in these cases, however this COALESCE syntax is still more consise. --- app/src/main/java/org/fdroid/fdroid/data/AppProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java b/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java index a0c312e2e..4432094e8 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java +++ b/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java @@ -648,7 +648,7 @@ public class AppProvider extends FDroidProvider { // being no apks for the app in the result set. In that case, we can't tell if it is from // a swap repo or not. final String isSwap = RepoTable.NAME + "." + RepoTable.Cols.IS_SWAP; - final String selection = isSwap + " = 0 OR " + isSwap + " IS NULL"; + final String selection = "COALESCE(" + isSwap + ", 0) = 0"; return new AppQuerySelection(selection); } @@ -930,7 +930,7 @@ public class AppProvider extends FDroidProvider { " WHERE " + app + "." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID + " AND " + " ( " + app + "." + Cols.IS_COMPATIBLE + " = 0 OR " + apk + "." + ApkTable.Cols.IS_COMPATIBLE + " = 1 ) ) " + - " WHERE " + Cols.UPSTREAM_VERSION_CODE + " = 0 OR " + Cols.UPSTREAM_VERSION_CODE + " IS NULL OR " + Cols.SUGGESTED_VERSION_CODE + " IS NULL "; + " WHERE COALESCE(" + Cols.UPSTREAM_VERSION_CODE + ", 0) = 0 OR " + Cols.SUGGESTED_VERSION_CODE + " IS NULL "; db().execSQL(updateSql); }