Will there be a difference in speed in querying using the QueryBuilder and with N1QL strings for Android?

Will it be a significant difference in speed or performance?

N1QL is parsed to JSON, so there is an additional step to parse. Since most N1QL is small, which means additional parsing is insignificant.

Hello, I got a significant differrence between QueryBuilder :

QueryBuilder.select(SelectResult.expression(Function.count(Expression.property("id"))))
      .from(DataSource.database(database))
      .where(
          Expression.property("objectType").equalTo(Expression.string("obj"))
              .and(
                  Expression.property("meta.status").equalTo(Expression.string("state1"))
              )
      )

and N1QL :

SELECT COUNT(id) FROM objectDatabase WHERE objectType = 'obj' AND meta.status = 'state1'

The query with N1QL is in average 3 time slower.

The result of the “explain” function for the two query are identical except for the “FROM” part of the query :

QueryBuilder =

SELECT fl_result(count(fl_value(objectDatabase.body, 'id'))) FROM kv_default AS objectDatabase WHERE (fl_value(objectDatabase.body, 'objectType') = 'obj' AND fl_value(objectDatabase.body, 'meta.status') = 'state1') AND (objectDatabase.flags & 1 = 0)

4|0|0| SEARCH TABLE kv_default AS objectDatabase USING INDEX ObjectTypeIndex (<expr>=? AND <expr>=?)

{"FROM":[{"AS":"objectDatabase"}],"WHAT":[["COUNT()",[".id"]]],"WHERE":["AND",["=",[".objectType"],"DePartement"],["=",[".meta.status"],"publish"]]}

N1QL =

SELECT fl_result(count(fl_value(objectDatabase.body, 'id'))) FROM kv_default AS objectDatabase WHERE (fl_value(objectDatabase.body, 'objectType') = 'obj' AND fl_value(objectDatabase.body, 'meta.status') = 'state1') AND (objectDatabase.flags & 1 = 0)

4|0|0| SEARCH TABLE kv_default AS objectDatabase USING INDEX ObjectTypeIndex (<expr>=? AND <expr>=?)

{"FROM":[{"COLLECTION":"objectDatabase"}],"WHAT":[["COUNT()",[".id"]]],"WHERE":["AND",["=",[".objectType"],"DePartement"],["=",[".meta.status"],"publish"]]}

Where did that difference come from ? The parsing of the query ?

As the query plans are the same and assuming that the data are the same, it could be that parsing the query is slow. Can you share the numbers (e.g. num docs and query times) from the test that you run?

If you want to separate the query parsing time for the N1QL, you can measure the times of creating the query object and the time when executing the query.