diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2021-03-21 17:38:48 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2021-03-21 18:39:04 +0100 |
commit | 4c024b53e6f64213284dc8cf7bb94df51859bd21 (patch) | |
tree | b444826ee512023c2fed8902629917e694bf4b05 | |
parent | 0f1e7056fc3b3b223a23dc182c0b97706ec3b764 (diff) | |
download | tracker-4c024b53e6f64213284dc8cf7bb94df51859bd21.tar.gz |
libtracker-data: Workaround SQLite 3.35.x bug
The optimization for UNION ALLs inside JOINs had another unexpected
victim:
SELECT * { GRAPH ?g { ?a ... OPTIONAL { ?a ... } } }
Does now break when matching the graph between both sides of the
LEFT JOIN caused by OPTIONAL, making all other values coming from
the right hand side come back empty. Make it sure this specific case
is ineligible for query flattening optimizations by adding a LIMIT
clause on the right hand side of the LEFT JOIN. This brings back
correct over fast.
This workaround should be revisited when a SQLite fix is available.
-rw-r--r-- | src/libtracker-data/tracker-sparql.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c index c4aaaaaa9..28c73bf6c 100644 --- a/src/libtracker-data/tracker-sparql.c +++ b/src/libtracker-data/tracker-sparql.c @@ -5085,8 +5085,28 @@ translate_OptionalGraphPattern (TrackerSparql *sparql, _call_rule (sparql, NAMED_RULE_GroupGraphPattern, error); - if (do_join) + if (do_join) { + /* FIXME: This is a workaround for SQLite 3.35.x, where + * the optimization on UNION ALLs inside JOINs (Point 8c in + * the 3.35.0 release notes) break in this very specific + * case: + * + * SELECT * { GRAPH ?g { ?a ... OPTIONAL { ?a ... } } } + * + * This is a workaround to make this one case ineligible + * for query flattening optimizations, specifically make + * it fall through case 8 in the list at + * https://sqlite.org/optoverview.html#flattening, + * "The subquery does not use LIMIT or the outer query is not + * a join.", we will now meet both here. + * + * This should be evaluated again in future SQLite versions. + */ + if (tracker_token_get_variable (&sparql->current_state->graph)) + _append_string (sparql, "LIMIT -1 "); + _append_string (sparql, ") "); + } return TRUE; } |