[evolution-ews] Index the contacts table on full_name and email_1 (primary email)



commit 1a2ff1aaaa8c792333f62044e6b4816da9ac811c
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Mon Apr 25 16:32:12 2011 +0530

    Index the contacts table on full_name and email_1 (primary email)

 src/addressbook/e-book-backend-sqlitedb.c |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-sqlitedb.c b/src/addressbook/e-book-backend-sqlitedb.c
index 834165f..fcf10e0 100644
--- a/src/addressbook/e-book-backend-sqlitedb.c
+++ b/src/addressbook/e-book-backend-sqlitedb.c
@@ -236,7 +236,7 @@ create_contacts_table	(EBookBackendSqliteDB *ebsdb,
 			 GError **error)
 {
 	gint ret;
-	gchar *stmt;
+	gchar *stmt, *tmp;
 		
 	stmt = sqlite3_mprintf ("CREATE TABLE IF NOT EXISTS %Q	 		\
 			     ( uid  TEXT PRIMARY KEY,				\
@@ -247,13 +247,27 @@ create_contacts_table	(EBookBackendSqliteDB *ebsdb,
 			       vcard TEXT)", folderid);
 
 	WRITER_LOCK (ebsdb);
-	ret = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL , NULL);
-	WRITER_UNLOCK (ebsdb);
-
+	ret = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL , error);
 	sqlite3_free (stmt);
 
-	/* TODO create indexes */
 	
+	/* Create indexes on full_name and email_1 as autocompletion queries would mainly
+	   rely on this. Assuming that the frequency of matching on these would be higher than
+	   on the other fields like email_2, surname etc. email_1 should be the primary email */
+	tmp = g_strdup_printf("FNINDEX-%s", folderid);
+	stmt = sqlite3_mprintf ("CREATE INDEX IF NOT EXISTS %Q ON %Q (full_name)", tmp, folderid);
+	ret = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, error);
+	g_free (tmp);
+	sqlite3_free (stmt);
+
+	tmp = g_strdup_printf("EMINDEX-%s", folderid);
+	stmt = sqlite3_mprintf ("CREATE INDEX IF NOT EXISTS %Q ON %Q (email_1)", tmp, folderid);
+	ret = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, error);
+	g_free (tmp);
+	sqlite3_free (stmt);
+
+	WRITER_UNLOCK (ebsdb);
+
 	return ret;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]