Fix prefix search on sqlite backend (many file triggers not running)

This commit is contained in:
Panu Matilainen 2020-06-10 10:40:39 +03:00
parent b9a32bc4b3
commit f7ecc585d0
2 changed files with 119 additions and 1 deletions

View File

@ -0,0 +1,114 @@
From cc897d03255e2a5aa672c40c043ca3fde88b8480 Mon Sep 17 00:00:00 2001
Message-Id: <cc897d03255e2a5aa672c40c043ca3fde88b8480.1591774714.git.pmatilai@redhat.com>
From: Panu Matilainen <pmatilai@redhat.com>
Date: Wed, 10 Jun 2020 10:33:06 +0300
Subject: [PATCH] Fix completely broken prefix search on sqlite backend
The prefix search was so wrong it's a small miracle it ever did anything
at all. What have I been thinking? Well, I do remember thinking this
prefix stuff looks kinda fishy but then it seems to work so...
The prefix search belongs to the keyed iterator fetch case of course,
not the case where we're otherwise iterating over all keys.
Fixes: #1260
---
lib/backend/sqlite.c | 51 +++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/lib/backend/sqlite.c b/lib/backend/sqlite.c
index 8520838df..ee9c62706 100644
--- a/lib/backend/sqlite.c
+++ b/lib/backend/sqlite.c
@@ -548,13 +548,24 @@ static unsigned int sqlite_pkgdbKey(dbiIndex dbi, dbiCursor dbc)
return sqlite3_column_int(dbc->stmt, 0);
}
-static rpmRC sqlite_idxdbByKey(dbiIndex dbi, dbiCursor dbc, const char *keyp, size_t keylen, dbiIndexSet *set)
+static rpmRC sqlite_idxdbByKey(dbiIndex dbi, dbiCursor dbc,
+ const char *keyp, size_t keylen, int searchType,
+ dbiIndexSet *set)
{
- int rc = dbiCursorPrep(dbc, "SELECT hnum, idx FROM '%q' WHERE key=?",
+ int rc = RPMRC_NOTFOUND;
+
+ if (searchType == DBC_PREFIX_SEARCH) {
+ rc = dbiCursorPrep(dbc, "SELECT hnum, idx FROM '%q' "
+ "WHERE MATCH(key,'%q',%d) "
+ "ORDER BY key",
+ dbi->dbi_file, keyp, keylen);
+ } else {
+ rc = dbiCursorPrep(dbc, "SELECT hnum, idx FROM '%q' WHERE key=?",
dbi->dbi_file);
+ if (!rc)
+ rc = dbiCursorBindIdx(dbc, keyp, keylen, NULL);
+ }
- if (!rc)
- rc = dbiCursorBindIdx(dbc, keyp, keylen, NULL);
if (!rc) {
while ((rc = sqlite3_step(dbc->stmt)) == SQLITE_ROW) {
@@ -576,21 +587,13 @@ static rpmRC sqlite_idxdbByKey(dbiIndex dbi, dbiCursor dbc, const char *keyp, si
return rc;
}
-static rpmRC sqlite_idxdbIter(dbiIndex dbi, dbiCursor dbc, const char *keyp, size_t keylen, dbiIndexSet *set, int searchType)
+static rpmRC sqlite_idxdbIter(dbiIndex dbi, dbiCursor dbc, dbiIndexSet *set)
{
int rc = RPMRC_OK;
if (dbc->stmt == NULL) {
- if (searchType == DBC_PREFIX_SEARCH) {
- rc = dbiCursorPrep(dbc, "SELECT DISTINCT key FROM '%q' "
- "WHERE MATCH(key,'%q',%d) "
- "ORDER BY key",
- dbi->dbi_file, keyp, keylen);
- } else {
- rc = dbiCursorPrep(dbc, "SELECT DISTINCT key FROM '%q' "
- "ORDER BY key",
+ rc = dbiCursorPrep(dbc, "SELECT DISTINCT key FROM '%q' ORDER BY key",
dbi->dbi_file);
- }
if (set)
dbc->subc = dbiCursorInit(dbi, 0);
}
@@ -605,14 +608,14 @@ static rpmRC sqlite_idxdbIter(dbiIndex dbi, dbiCursor dbc, const char *keyp, siz
dbc->key = sqlite3_column_blob(dbc->stmt, 0);
}
dbc->keylen = sqlite3_column_bytes(dbc->stmt, 0);
- if (set)
- rc = sqlite_idxdbByKey(dbi, dbc->subc, dbc->key, dbc->keylen, set);
- rc = RPMRC_OK;
- } else if (rc == SQLITE_DONE) {
- if (searchType == DBC_PREFIX_SEARCH && (*set))
+ if (dbc->subc) {
+ rc = sqlite_idxdbByKey(dbi, dbc->subc, dbc->key, dbc->keylen,
+ DBC_NORMAL_SEARCH, set);
+ } else {
rc = RPMRC_OK;
- else
- rc = RPMRC_NOTFOUND;
+ }
+ } else if (rc == SQLITE_DONE) {
+ rc = RPMRC_NOTFOUND;
} else {
rc = dbiCursorResult(dbc);
}
@@ -623,10 +626,10 @@ static rpmRC sqlite_idxdbIter(dbiIndex dbi, dbiCursor dbc, const char *keyp, siz
static rpmRC sqlite_idxdbGet(dbiIndex dbi, dbiCursor dbc, const char *keyp, size_t keylen, dbiIndexSet *set, int searchType)
{
int rc;
- if (keyp && searchType != DBC_PREFIX_SEARCH) {
- rc = sqlite_idxdbByKey(dbi, dbc, keyp, keylen, set);
+ if (keyp) {
+ rc = sqlite_idxdbByKey(dbi, dbc, keyp, keylen, searchType, set);
} else {
- rc = sqlite_idxdbIter(dbi, dbc, keyp, keylen, set, searchType);
+ rc = sqlite_idxdbIter(dbi, dbc, set);
}
return rc;
--
2.26.2

View File

@ -25,7 +25,7 @@
%global rpmver 4.16.0
%global snapver beta1
%global rel 3
%global rel 4
%global srcver %{rpmver}%{?snapver:-%{snapver}}
%global srcdir %{?snapver:testing}%{!?snapver:rpm-%(echo %{rpmver} | cut -d'.' -f1-2).x}
@ -61,6 +61,7 @@ Patch6: 0001-find-debuginfo.sh-decompress-DWARF-compressed-ELF-se.patch
# Patches already upstream:
Patch100: 0001-Don-t-auto-enable-IO-flushing-on-non-rotational-disk.patch
Patch101: 0001-metainfo.attr-Fix-execution-of-the-generator.patch
Patch102: 0001-Fix-completely-broken-prefix-search-on-sqlite-backen.patch
# These are not yet upstream
Patch906: rpm-4.7.1-geode-i686.patch
@ -554,6 +555,9 @@ fi
%doc doc/librpm/html/*
%changelog
* Wed Jun 10 2020 Panu Matilainen <pmatilai@redhat.com> - 4.16.0-0.beta1.4
- Fix prefix search on sqlite backend (many file triggers not running)
* Mon Jun 8 2020 Panu Matilainen <pmatilai@redhat.com> - 4.16.0-0.beta1.3
- Unbreak metainfo() provide generation