mongodb-d4 icon indicating copy to clipboard operation
mongodb-d4 copied to clipboard

Use output of a query as input to other queries

Open apavlo opened this issue 13 years ago • 0 comments
trafficstars

When converting from MySQL to MongoDB, we have to break up joins into multiple queries. This means that the application is going to have to do the join itself. We currently do not support this and our converted queries contain the column name that it was trying to join on.

In the example below you can see that the first query contains "i_id" : "r.i_id":

> db.sessions.findOne({"_id": ObjectId('4f9c68eb7ea5738a7f021e67')})
{
        "_id" : ObjectId("4f9c68eb7ea5738a7f021e67"),
        "ip2" : "192.168.63.1",
        "operations" : [
                {
                        "timestamp" : 1335551250,
                        "collection" : "item",
                        "content" : [
                                {
                                        "query" : {
                                                "i_id" : "r.i_id"
                                        }
                                }
                        ],
                        "output" : [ ],
                        "type" : "$query",
                        "size" : 0
                },
                {
                        "timestamp" : 1335551250,
                        "collection" : "review",
                        "content" : [
                                {
                                        "query" : {
                                                "i_id" : 24
                                        }
                                }
                        ],
                        "output" : [ ],
                        "type" : "$query",
                        "size" : 0
                }
        ],
        "ip1" : "127.0.0.1",
        "uid" : 59
}

We need to be able to identify when this occurs and recognize that that the output of one query is used as the input for the second query. This means that we need to make sure that the operations are stored in the proper order (in the example above, the order is incorrect since we need the output of the second query as input to the first). Then in the replay benchmark, we will need to quickly see that we need some output value from a previous query as the input to one query.

This mapping information should be stored in the Session object.

apavlo avatar Apr 29 '12 01:04 apavlo