title: Room - Slow Query in Background
body: <p>I'm currently implementing Room to replace my old SQL code, but I'm running into an issue where my query is very slow when running in the background.</p>
  
  <p>For example, I have two identical queries, one that runs on the UI thread, and another that returns a <code>Single</code>. I'm using <code>allowMainThreadQueries()</code> to test this case.</p>
  
  <pre><code>    @Query("SELECT * FROM event ORDER BY `begin` ASC LIMIT $LIMIT")
      fun getUIThreadSchedule(): List&lt;Event&gt;
  
  
      @Query("SELECT * FROM event ORDER BY `begin` ASC LIMIT $LIMIT")
      fun getSchedule(): Single&lt;List&lt;Event&gt;&gt;
  </code></pre>
  
  <p>Now, when I run both of these and compare the time to give me a result, they are very different.</p>
  
  <p>This will take ~6ms to complete.</p>
  
  <pre><code>    val events = database.getUIThreadSchedule()
  </code></pre>
  
  <p>And this will take ~360ms to complete.</p>
  
  <pre><code>    database.getSchedule()
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe({
                     // elements are now here
                  }, {
                      // show an error view
                  })
  </code></pre>
  
  <p>I tried using other options, such as <code>Flowable</code>, but the result is the same.</p>
  
  <p>Does anyone know what I could be doing wrong?</p>
  
  <p>Thanks.</p>