[evolution-data-server/sqlite-refactor] EBookSqlite: Experimental query formation change
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/sqlite-refactor] EBookSqlite: Experimental query formation change
- Date: Sat, 30 Nov 2013 06:41:24 +0000 (UTC)
commit be0a72546b7137439b07310d8f880efba4a67da3
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Nov 30 15:40:11 2013 +0900
EBookSqlite: Experimental query formation change
addressbook/libedata-book/e-book-sqlite.c | 75 +++++++----------------------
1 files changed, 17 insertions(+), 58 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-sqlite.c b/addressbook/libedata-book/e-book-sqlite.c
index 77f3145..9303ce6 100644
--- a/addressbook/libedata-book/e-book-sqlite.c
+++ b/addressbook/libedata-book/e-book-sqlite.c
@@ -4882,7 +4882,7 @@ query_preflight (PreflightContext *context,
query_preflight_substitute_full_name (context, ebsql);
/* Optimize queries which touch auxiliary columns */
- query_preflight_optimize (context, ebsql);
+ /* query_preflight_optimize (context, ebsql); */
} else {
/* We might use this context to perform a fallback query,
@@ -5354,6 +5354,15 @@ ebsql_generate_constraints (EBookSqlite *ebsql,
sub_query_context_free (ctx);
}
+
+/* SELECT DISTINCT summary.uid, summary.vcard FROM folder_id AS summary */
+/* JOIN folder_id_phone_list AS phone_list */
+/* ON phone_list.uid = summary.uid */
+/* JOIN folder_id_email_list AS email_list */
+/* ON email_list.uid = summary.uid */
+/* WHERE phone_list.value LIKE '%0505' AND email_list.value LIKE 'eddie%'; */
+
+
/* Generates the SELECT portion of the query, this will possibly add some
* of the constraints into nested selects. Constraints that could not be
* nested will have their symbolic table names in context.
@@ -5370,7 +5379,6 @@ ebsql_generate_select (EBookSqlite *ebsql,
{
GSList *l;
EbSqlRowFunc callback = NULL;
- gchar *previous_field = NULL;
g_string_append (string, "SELECT ");
if (context->aux_fields)
@@ -5400,69 +5408,20 @@ ebsql_generate_select (EBookSqlite *ebsql,
break;
}
- g_string_append (string, "FROM ");
+ ebsql_string_append_printf (string, "FROM %Q AS summary", ebsql->priv->folderid);
for (l = context->aux_fields; l; l = l->next) {
PreflightAuxData *aux_data = (PreflightAuxData *)l->data;
SummaryField *field = summary_field_get (ebsql, aux_data->field_id);
- /* For every other query, start with the JOIN */
- if (previous_field)
- g_string_append (string, "LEFT OUTER JOIN ");
-
- if (aux_data->constraints) {
- /* Each nested select must be outer left joined on to
- * the previous one, in this way the collection of joined
- * tables is equal to a logical AND.
- *
- * See query_preflight_optimize() for more details.
- */
- ebsql_string_append_printf (string,
- "( SELECT DISTINCT %s.uid FROM %Q AS %s WHERE ",
- field->aux_table_symbolic,
- field->aux_table,
- field->aux_table_symbolic);
- ebsql_generate_constraints (ebsql, string,
- aux_data->constraints,
- NULL);
- ebsql_string_append_printf (string, " ) AS %s_results ",
- field->aux_table_symbolic);
-
- if (previous_field)
- ebsql_string_append_printf (string, "ON %s_results.uid = %s ",
- field->aux_table_symbolic,
- previous_field);
-
- g_free (previous_field);
- previous_field = g_strconcat (field->aux_table_symbolic,
- "_results.uid", NULL);
- } else {
- /* Join the table in the normal way and leave the constraints for later */
- ebsql_string_append_printf (string, "%Q AS %s ",
- field->aux_table,
- field->aux_table_symbolic);
-
- if (previous_field)
- ebsql_string_append_printf (string, "ON %s.uid = %s ",
- field->aux_table_symbolic,
- previous_field);
-
- g_free (previous_field);
- previous_field = g_strconcat (field->aux_table_symbolic,
- ".uid", NULL);
- }
+ /* Join the table in the normal way and leave the constraints for later */
+ ebsql_string_append_printf (string, " JOIN %Q AS %s ON %s.uid = summary.uid",
+ field->aux_table,
+ field->aux_table_symbolic,
+ field->aux_table_symbolic);
}
- if (previous_field)
- g_string_append (string, "LEFT OUTER JOIN ");
-
- ebsql_string_append_printf (string, "%Q AS summary ", ebsql->priv->folderid);
- if (previous_field)
- ebsql_string_append_printf (string, "ON summary.uid = %s ", previous_field);
-
- g_free (previous_field);
-
return callback;
}
@@ -5495,7 +5454,7 @@ ebsql_do_search_query (EBookSqlite *ebsql,
/*
* Now generate the search expression on the main contacts table
*/
- g_string_append (string, "WHERE ");
+ g_string_append (string, " WHERE ");
ebsql_generate_constraints (ebsql,
string,
context->constraints,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]