trace_processor: fix up sqlstats table (and time reported in shell)

Make the new iterator API work with the sqlstats table by splitting
the time_ended column into a "first next" column (which reports the
time to the first Next call on the iterator) and the actual end column
when the iterator is destroyed.

Also fix a subtle issue in trace processor interactive mode reporting
negative execution time.

Bug: 131627868
Change-Id: I24edb5576d9603bf004d61a83307022dfe16f43a
diff --git a/src/trace_processor/trace_storage.h b/src/trace_processor/trace_storage.h
index 47366e1..f6f687a 100644
--- a/src/trace_processor/trace_storage.h
+++ b/src/trace_processor/trace_storage.h
@@ -443,20 +443,27 @@
   class SqlStats {
    public:
     static constexpr size_t kMaxLogEntries = 100;
-    void RecordQueryBegin(const std::string& query,
-                          int64_t time_queued,
-                          int64_t time_started);
-    void RecordQueryEnd(int64_t time_ended);
+    uint32_t RecordQueryBegin(const std::string& query,
+                              int64_t time_queued,
+                              int64_t time_started);
+    void RecordQueryFirstNext(uint32_t row, int64_t time_first_next);
+    void RecordQueryEnd(uint32_t row, int64_t time_end);
     size_t size() const { return queries_.size(); }
     const std::deque<std::string>& queries() const { return queries_; }
     const std::deque<int64_t>& times_queued() const { return times_queued_; }
     const std::deque<int64_t>& times_started() const { return times_started_; }
+    const std::deque<int64_t>& times_first_next() const {
+      return times_first_next_;
+    }
     const std::deque<int64_t>& times_ended() const { return times_ended_; }
 
    private:
+    uint32_t popped_queries_ = 0;
+
     std::deque<std::string> queries_;
     std::deque<int64_t> times_queued_;
     std::deque<int64_t> times_started_;
+    std::deque<int64_t> times_first_next_;
     std::deque<int64_t> times_ended_;
   };