archrelease: copy trunk to extra-x86_64
[arch-packages.git] / tracker / trunk / 0001-libtracker-data-Workaround-SQLite-3.35.x-bug.patch
blob6e31c1333b0d9042e71bb6197e4edfaecf69f9e1
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Carlos Garnacho <carlosg@gnome.org>
3 Date: Sun, 21 Mar 2021 17:38:48 +0100
4 Subject: [PATCH] libtracker-data: Workaround SQLite 3.35.x bug
6 The optimization for UNION ALLs inside JOINs had another unexpected
7 victim:
9 SELECT * { GRAPH ?g { ?a ... OPTIONAL { ?a ... } } }
11 Does now break when matching the graph between both sides of the
12 LEFT JOIN caused by OPTIONAL, making all other values coming from
13 the right hand side come back empty. Make it sure this specific case
14 is ineligible for query flattening optimizations by adding a LIMIT
15 clause on the right hand side of the LEFT JOIN. This brings back
16 correct over fast.
18 This workaround should be revisited when a SQLite fix is available.
19 ---
20 src/libtracker-data/tracker-sparql.c | 22 +++++++++++++++++++++-
21 1 file changed, 21 insertions(+), 1 deletion(-)
23 diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
24 index e36d2341e684..60e50c611ab8 100644
25 --- a/src/libtracker-data/tracker-sparql.c
26 +++ b/src/libtracker-data/tracker-sparql.c
27 @@ -3170,8 +3170,28 @@ translate_OptionalGraphPattern (TrackerSparql *sparql,
29 _call_rule (sparql, NAMED_RULE_GroupGraphPattern, error);
31 - if (do_join)
32 + if (do_join) {
33 + /* FIXME: This is a workaround for SQLite 3.35.x, where
34 + * the optimization on UNION ALLs inside JOINs (Point 8c in
35 + * the 3.35.0 release notes) break in this very specific
36 + * case:
37 + *
38 + * SELECT * { GRAPH ?g { ?a ... OPTIONAL { ?a ... } } }
39 + *
40 + * This is a workaround to make this one case ineligible
41 + * for query flattening optimizations, specifically make
42 + * it fall through case 8 in the list at
43 + * https://sqlite.org/optoverview.html#flattening,
44 + * "The subquery does not use LIMIT or the outer query is not
45 + * a join.", we will now meet both here.
46 + *
47 + * This should be evaluated again in future SQLite versions.
48 + */
49 + if (tracker_token_get_variable (&sparql->current_state.graph))
50 + _append_string (sparql, "LIMIT -1 ");
52 _append_string (sparql, ") ");
53 + }
55 return TRUE;