← Back to team overview

zeitgeist team mailing list archive

[Branch ~zeitgeist/zeitgeist/bluebird] Rev 357: Add a define to explain query plans

 

Merge authors:
  Siegfried Gevatter (rainct)
------------------------------------------------------------
revno: 357 [merge]
committer: Michal Hruby <michal.mhr@xxxxxxxxx>
branch nick: bluebird
timestamp: Sat 2011-12-31 18:37:10 +0100
message:
  Add a define to explain query plans
modified:
  src/Makefile.am
  src/engine.vala
  src/sql.vala


--
lp:zeitgeist
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird

Your team Zeitgeist Framework Team is subscribed to branch lp:zeitgeist.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'src/Makefile.am'
--- src/Makefile.am	2011-12-31 13:30:23 +0000
+++ src/Makefile.am	2011-12-31 17:37:10 +0000
@@ -8,7 +8,7 @@
 	-w \
 	$(NULL)
 
-VALAFLAGS = \
+AM_VALAFLAGS = \
 	--target-glib=2.26 \
 	-D BUILTIN_EXTENSIONS \
 	--pkg gio-2.0 \
@@ -63,12 +63,12 @@
 BUILT_SOURCES = zeitgeist-engine_vala.stamp extensions_vala.stamp
 
 zeitgeist-engine_vala.stamp: $(zeitgeist_daemon_VALASOURCES)
-	$(VALA_V)$(VALAC) $(VALAFLAGS) -C -H zeitgeist-engine.h --library zeitgeist-engine $^
+	$(VALA_V)$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS) -C -H zeitgeist-engine.h --library zeitgeist-engine $^
 	@touch "$@"
 
 extensions_vala.stamp: zeitgeist-engine_vala.stamp $(extensions_VALASOURCES)
 	$(AM_V_GEN)$(foreach ext_src,$(filter %.vala,$^),\
-		$(VALAC) $(VALAFLAGS) $(EXT_FLAGS) -C zeitgeist-engine.vapi $(ext_src) || exit 1;)
+		$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS) $(EXT_FLAGS) -C zeitgeist-engine.vapi $(ext_src) || exit 1;)
 	@touch "$@"
 
 # FIXME: can we make this depend on $(ontology_trig_DATA)?

=== modified file 'src/engine.vala'
--- src/engine.vala	2011-12-29 13:59:16 +0000
+++ src/engine.vala	2011-12-31 17:37:10 +0000
@@ -334,6 +334,10 @@
         for (int i = 0; i < arguments.length; ++i)
             stmt.bind_text (i + 1, arguments[i]);
 
+#if EXPLAIN_QUERIES
+        database.explain_query (stmt);
+#endif
+
         uint32[] event_ids = {};
 
         while ((rc = stmt.step()) == Sqlite.ROW)

=== modified file 'src/sql.vala'
--- src/sql.vala	2011-12-28 23:36:27 +0000
+++ src/sql.vala	2011-12-31 17:37:10 +0000
@@ -189,6 +189,30 @@
             database = null;
         }
 
+#if EXPLAIN_QUERIES
+        public void explain_query (Sqlite.Statement prepared_stmt)
+            throws EngineError
+        {
+            int rc;
+            Sqlite.Statement stmt;
+
+            var explain_sql = "EXPLAIN QUERY PLAN %s".printf (prepared_stmt.sql ());
+
+            rc = prepared_stmt.db_handle ().prepare_v2 (explain_sql, -1, out stmt);
+            assert_query_success(rc, "SQL error");
+
+            while ((rc = stmt.step()) == Sqlite.ROW)
+            {
+                int select_id = stmt.column_int (0);
+                int order = stmt.column_int (1);
+                int from = stmt.column_int (2);
+                unowned string detail = stmt.column_text (3);
+
+                print ("%d %d %d %s\n", select_id, order, from, detail);
+            }
+        }
+#endif
+
         /**
          * Ensure `rc' is SQLITE_OK. If it isn't, print an error message
          * and throw an error.