Activity log for bug #1214538

Date Who What changed Old value New value Message
2013-08-20 19:05:15 Victor Choueiri bug added bug
2013-08-20 19:19:40 Giulio Collura bug added subscriber Giulio Collura
2013-08-20 20:18:02 Victor Choueiri description It seems that query's only return results of documents, where all the document's fields are indexed [regardless of whether or not those fields are being queried]. I've included a number of examples below, I hope they clarify the situation: Examples: Database definition: U1db.Database { id: theDB path: "indextest.db" } Two sample documents: the first has only a "title" field, the second has both "title" and "num" fields: U1db.Document { database: theDB create: true docId: "vic" defaults: {"title": "vic"} } U1db.Document { database: theDB create: true docId: "xqwzts" defaults: { "title": "xqwzts", "num": "123" } } Index only the title field since it is what I care about querying: U1db.Index { database: theDB id: theIndex expression: ["title"] } An empty query which should match all documents in the index: U1db.Query { id: theQuery index: theIndex } Expected result: both documents should be returned Action result: only the first document is returned Detailed output: JSON.stringify(theDB.listDocs()) {"0":"vic","1":"xqwzts"} JSON.stringify(theIndex) {"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title"}} JSON.stringify(theQuery) {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title"}},"objectName":"","results":[{"title":"vic"}],"documents":{"0":"vic"}} Specifying the query to search for title = "*" makes no difference: U1db.Query { id: theQuery index: theIndex query: [{"title": "*"}] } JSON.stringify(theQuery) {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title"}},"objectName":"","results":[{"title":"vic"}],"documents":{"0":"vic"},"query":[{"title":"*"}]} It seems the second document simply isn't in the index, so no query will return it. To add the second document to the index we must add all fields of the document to the index expression: U1db.Index { database: theDB id: theIndex expression: ["title", "num"] } And remove the query clause to have the query return all documents in the index: U1db.Query { id: theQuery index: theIndex } So now the output becomes: JSON.stringify(theIndex) {"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}} JSON.stringify(theQuery) {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}},"objectName":"","results":[{"title":"vic"},{"num":"123"}],"documents":{"0":"vic","1":"xqwzts"}} But now in order to add a query clause all the fields in the index which are also in the document have to be included. U1db.Query { id: theQuery index: theIndex query: [{"title": "*"}] } JSON.stringify(theQuery) {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}},"objectName":"","results":[{"title":"vic"}],"documents":{"0":"vic"},"query":[{"title":"*"}]} In order to actually return all the documents with title=* we have to also specify that num=* U1db.Query { id: theQuery index: theIndex query: [{"title": "*"}, {"num": "*"}] } JSON.stringify(theQuery) {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}},"objectName":"","results":[{"title":"vic"},{"num":"123"}],"documents":{"0":"vic","1":"xqwzts"},"query":[{"title":"*"},{"num":"*"}]} Conclusion: - In order to be included in the index, ALL fields in a document must be included in the index's expression clause. - In order to be returned by a query, ALL fields in a document [which are also in the index] must be included in the query's query clause. This is pretty problematic with large/complicated documents where including every single field in the expression/query clause is not really feasible. It seems that queries only return results of documents, where all the document's fields are indexed [regardless of whether or not those fields are being queried]. I've included a number of examples below, I hope they clarify the situation: Examples: Database definition:     U1db.Database {         id: theDB         path: "indextest.db"     } Two sample documents: the first has only a "title" field, the second has both "title" and "num" fields:     U1db.Document {         database: theDB         create: true         docId: "vic"         defaults: {"title": "vic"}     }     U1db.Document {         database: theDB         create: true         docId: "xqwzts"         defaults: {             "title": "xqwzts",             "num": "123"         }     } Index only the title field since it is what I care about querying:     U1db.Index {         database: theDB         id: theIndex         expression: ["title"]     } An empty query which should match all documents in the index:     U1db.Query {         id: theQuery         index: theIndex     } Expected result: both documents should be returned Action result: only the first document is returned Detailed output: JSON.stringify(theDB.listDocs())     {"0":"vic","1":"xqwzts"} JSON.stringify(theIndex)     {"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title"}} JSON.stringify(theQuery)     {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title"}},"objectName":"","results":[{"title":"vic"}],"documents":{"0":"vic"}} Specifying the query to search for title = "*" makes no difference:     U1db.Query {         id: theQuery         index: theIndex         query: [{"title": "*"}]     } JSON.stringify(theQuery)     {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title"}},"objectName":"","results":[{"title":"vic"}],"documents":{"0":"vic"},"query":[{"title":"*"}]} It seems the second document simply isn't in the index, so no query will return it. To add the second document to the index we must add all fields of the document to the index expression:     U1db.Index {         database: theDB         id: theIndex         expression: ["title", "num"]     } And remove the query clause to have the query return all documents in the index:    U1db.Query {         id: theQuery         index: theIndex     } So now the output becomes: JSON.stringify(theIndex)     {"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}} JSON.stringify(theQuery)     {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}},"objectName":"","results":[{"title":"vic"},{"num":"123"}],"documents":{"0":"vic","1":"xqwzts"}} But now in order to add a query clause all the fields in the index which are also in the document have to be included.     U1db.Query {         id: theQuery         index: theIndex         query: [{"title": "*"}]     } JSON.stringify(theQuery)     {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}},"objectName":"","results":[{"title":"vic"}],"documents":{"0":"vic"},"query":[{"title":"*"}]} In order to actually return all the documents with title=* we have to also specify that num=*     U1db.Query {         id: theQuery         index: theIndex         query: [{"title": "*"}, {"num": "*"}]     } JSON.stringify(theQuery)     {"index":{"database":{"error":"","objectName":"","path":"indextest.db"},"name":"","objectName":"","expression":{"0":"title","1":"num"}},"objectName":"","results":[{"title":"vic"},{"num":"123"}],"documents":{"0":"vic","1":"xqwzts"},"query":[{"title":"*"},{"num":"*"}]} Conclusion: - In order to be included in the index, ALL fields in a document must be included in the index's expression clause. - In order to be returned by a query, ALL fields in a document [which are also in the index] must be included in the query's query clause. This is pretty problematic with large/complicated documents where including every single field in the expression/query clause is not really feasible.
2013-08-22 09:49:55 Joshua Gleitze bug added subscriber Joshua Gleitze
2013-08-22 12:16:20 Joshua Gleitze u1db-qt: status New Confirmed
2013-08-27 09:50:14 Cris Dywan u1db-qt: importance Undecided Critical
2013-08-27 09:50:20 Cris Dywan u1db-qt: assignee Christian Dywan (kalikiana)
2013-08-27 09:50:23 Cris Dywan u1db-qt: milestone 1.0
2013-09-04 14:16:13 Cris Dywan branch linked lp:~kalikiana/u1db-qt/ordering
2013-09-06 16:48:08 Cris Dywan branch linked lp:~kalikiana/u1db-qt/ordering2
2014-03-03 10:39:35 Cris Dywan branch linked lp:~kalikiana/u1db-qt/wonderiousFields
2014-03-03 16:16:59 Cris Dywan attachment added allFields.qml https://bugs.launchpad.net/u1db-qt/+bug/1214538/+attachment/4005275/+files/allFields.qml
2014-03-10 08:44:04 PS Jenkins bot u1db-qt: status Confirmed Fix Committed
2014-03-14 00:37:34 Launchpad Janitor branch linked lp:ubuntu/trusty-proposed/u1db-qt
2014-03-14 12:46:22 Launchpad Janitor u1db-qt (Ubuntu): status New Fix Released
2014-07-17 11:03:35 Launchpad Janitor branch linked lp:~ubuntu-branches/ubuntu/utopic/u1db-qt/utopic-proposed