EnterpriseDB / mongo_fdw

PostgreSQL foreign data wrapper for MongoDB
GNU Lesser General Public License v3.0
326 stars 70 forks source link

Why so many getmore operations? #63

Closed lifubang closed 2 years ago

lifubang commented 8 years ago

When I use mongo_fdw, I find that the mongo network output is too big, the top of it can reach 300M per seconds. I analyses the mongo log, and find that there are so many getmore operations. The log contents is:

mongo日志 query

{
        "op" : "query",
        "ns" : "hello-world.Cands",
        "query" : {
                "find" : "Cands",
                "filter" : {

                }
        },
        "cursorid" : 49274336338,
        "keysExamined" : 0,
        "docsExamined" : 101,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 0,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(2)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(1)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(1)
                        }
                }
        },
        "nreturned" : 101,
        "responseLength" : 129753,
        "protocol" : "op_query",
        "millis" : 0,
        "execStats" : {
                "stage" : "COLLSCAN",
                "filter" : {
                        "$and" : [ ]
                },
                "nReturned" : 101,
                "executionTimeMillisEstimate" : 0,
                "works" : 102,
                "advanced" : 101,
                "needTime" : 1,
                "needYield" : 0,
                "saveState" : 1,
                "restoreState" : 0,
                "isEOF" : 0,
                "invalidates" : 0,
                "direction" : "forward",
                "docsExamined" : 101
        },
        "ts" : ISODate("2016-09-21T16:14:16.147Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "query",
        "ns" : "hello-world.Cands",
        "query" : {
                "find" : "Cands",
                "filter" : {
                        "id" : NumberLong(4380498)
                }
        },
        "keysExamined" : 1,
        "docsExamined" : 1,
        "cursorExhausted" : true,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 0,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(2)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(1)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(1)
                        }
                }
        },
        "nreturned" : 1,
        "responseLength" : 946,
        "protocol" : "op_query",
        "millis" : 0,
        "execStats" : {
                "stage" : "CACHED_PLAN",
                "nReturned" : 1,
                "executionTimeMillisEstimate" : 0,
                "works" : 2,
                "advanced" : 1,
                "needTime" : 0,
                "needYield" : 0,
                "saveState" : 0,
                "restoreState" : 0,
                "isEOF" : 1,
                "invalidates" : 0,
                "inputStage" : {
                        "stage" : "FETCH",
                        "nReturned" : 1,
                        "executionTimeMillisEstimate" : 0,
                        "works" : 2,
                        "advanced" : 1,
                        "needTime" : 0,
                        "needYield" : 0,
                        "saveState" : 0,
                        "restoreState" : 0,
                        "isEOF" : 1,
                        "invalidates" : 0,
                        "docsExamined" : 1,
                        "alreadyHasObj" : 0,
                        "inputStage" : {
                                "stage" : "IXSCAN",
                                "nReturned" : 1,
                                "executionTimeMillisEstimate" : 0,
                                "works" : 2,
                                "advanced" : 1,
                                "needTime" : 0,
                                "needYield" : 0,
                                "saveState" : 0,
                                "restoreState" : 0,
                                "isEOF" : 1,
                                "invalidates" : 0,
                                "keyPattern" : {
                                        "id" : 1
                                },
                                "indexName" : "id_1",
                                "isMultiKey" : false,
                                "isUnique" : false,
                                "isSparse" : false,
                                "isPartial" : false,
                                "indexVersion" : 1,
                                "direction" : "forward",
                                "indexBounds" : {
                                        "id" : [
                                                "[4380498, 4380498]"
                                        ]
                                },
                                "keysExamined" : 1,
                                "dupsTested" : 0,
                                "dupsDropped" : 0,
                                "seenInvalidated" : 0
                        }
                }
        },
        "ts" : ISODate("2016-09-21T16:14:15.198Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}

mongo日志 getmore

{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "cursorExhausted" : true,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 12,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(26)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(13)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(13)
                        }
                }
        },
        "nreturned" : 1646,
        "responseLength" : 1326206,
        "protocol" : "op_query",
        "millis" : 0,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:23.346Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 40,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(82)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(41)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(41)
                        }
                }
        },
        "nreturned" : 5178,
        "responseLength" : 4194602,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:23.277Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 39,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(80)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(40)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(40)
                        }
                }
        },
        "nreturned" : 5090,
        "responseLength" : 4194510,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:23.221Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 40,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(82)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(41)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(41)
                        }
                }
        },
        "nreturned" : 5129,
        "responseLength" : 4194463,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:23.146Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 41,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(84)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(42)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(42)
                        }
                }
        },
        "nreturned" : 5368,
        "responseLength" : 4194365,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:23.070Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 39,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(80)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(40)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(40)
                        }
                }
        },
        "nreturned" : 5100,
        "responseLength" : 4194748,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.997Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3761,
        "responseLength" : 4195117,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.948Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 37,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(76)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(38)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(38)
                        }
                }
        },
        "nreturned" : 4850,
        "responseLength" : 4194867,
        "protocol" : "op_query",
        "millis" : 3,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.885Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 25,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(52)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(26)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(26)
                        }
                }
        },
        "nreturned" : 3231,
        "responseLength" : 4194849,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.822Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 23,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(48)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(24)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(24)
                        }
                }
        },
        "nreturned" : 3042,
        "responseLength" : 4194359,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.752Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3750,
        "responseLength" : 4194978,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.701Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 28,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(58)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(29)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(29)
                        }
                }
        },
        "nreturned" : 3705,
        "responseLength" : 4194493,
        "protocol" : "op_query",
        "millis" : 3,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.631Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3760,
        "responseLength" : 4195046,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.553Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3769,
        "responseLength" : 4195514,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.510Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3763,
        "responseLength" : 4194871,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.468Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 24,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(50)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(25)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(25)
                        }
                }
        },
        "nreturned" : 3120,
        "responseLength" : 4195096,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.424Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 25,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(52)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(26)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(26)
                        }
                }
        },
        "nreturned" : 3227,
        "responseLength" : 4194458,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.361Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3738,
        "responseLength" : 4195200,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.286Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 29,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(60)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(30)
                        }
                }
        },
        "nreturned" : 3758,
        "responseLength" : 4194855,
        "protocol" : "op_query",
        "millis" : 2,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:22.143Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}
{
        "op" : "getmore",
        "ns" : "hello-world.Cands",
        "query" : {
                "getMore" : NumberLong("49274336338"),
                "collection" : "Cands"
        },
        "cursorid" : 49274336338,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 28,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(58)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(29)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(29)
                        }
                }
        },
        "nreturned" : 3641,
        "responseLength" : 4195266,
        "protocol" : "op_query",
        "millis" : 3,
        "execStats" : {

        },
        "ts" : ISODate("2016-09-21T16:14:21.814Z"),
        "client" : "10.47.208.162",
        "allUsers" : [
                {
                        "user" : "node",
                        "db" : "hello-world"
                }
        ],
        "user" : "node@hello-world"
}

I don't use no filter query in pg, but the getmore operation has no filter. by the way, my query in pg have indexes in mongo. how to deal with it?

I guess if you exec a sql in pg, the mongo_fdw will scan the whole foreign table in mongo.

lifubang commented 8 years ago

w clsui _uity2j 689c ki

lifubang commented 8 years ago

I think it the reason of MongoAcquireSampleRows function, after I changed this function like this, the network output bytes changed: `static int MongoAcquireSampleRows(Relation relation, int errorLevel, HeapTuple _sampleRows, int targetRowCount, double totalRowCount, double totalDeadRowCount) { (_totalRowCount) = 100000000;//rowCount; (*totalDeadRowCount) = 0;

    return 0;

}

//the old MongoAcquireSampleRows function static int MongoAcquireSampleRows1(Relation relation, int errorLevel, HeapTuple sampleRows, int targetRowCount, double totalRowCount, double *totalDeadRowCount) { int sampleRowCount = 0; double rowCount = 0; ....

    foreignTableId = RelationGetRelid(relation);
    queryDocument = QueryDocument(foreignTableId, NIL);  **// no filter**
    ....

    **//get more for the whole table**
    for (;;)
    {
            /* check for user-requested abort or sleep */
            vacuum_delay_point();

            /* initialize all values for this row to null */
            memset(columnValues, 0, columnCount * sizeof(Datum));
            memset(columnNulls, true, columnCount * sizeof(bool));

            if(MongoCursorNext(mongoCursor, NULL))
            {
    ....

}`

lifubang commented 8 years ago

Ah, No, it's not true. the same thing occurs again: g r92 5sq kal xe p 6x

netout 206M now.

how to disable documents full scan?

ahsanhadi commented 8 years ago

You are saying that the mongodb_fdw is scanning the full document even when you use a where clause in your query? Can you share a small example to demonstrate the issue?

lifubang commented 8 years ago

Here is the small example. You need to reference jars as follows: ./lib/commons-dbcp-1.2.1.jar ./lib/commons-pool-1.2.jar ./lib/commons-collections-3.2.jar ./lib/postgresql-9.4.1208.jre7.jar

import org.apache.commons.dbcp.BasicDataSource;

import java.lang.Integer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.util.List;
import java.lang.Thread;

public class dbcp {
    public static BasicDataSource dataSource = new BasicDataSource();

    public static void main(String args[])
    {
        dataSource.setPoolPreparedStatements(false);
        dataSource.setUrl("jdbc:postgresql://*************/acmcoder");
        dataSource.setUsername("postgres");
        dataSource.setPassword("***************");

        int testcases = 100;
        if (args.length > 0) {
            testcases = Integer.parseInt(args[0]);
        }
        System.out.println("testcases: " + testcases);

        for (int i=0; i<testcases; i++) {
            Thread thread = new TestThread();

            thread.start();
        }
    }

    public static boolean getKandsMailState(Long id, String prjId) throws Exception {
        Connection conn = null;
        PreparedStatement psmt = null;
        ResultSet res = null;
        boolean flag = false;
        try {
            String sql = " select \"confirmState\" from \"wb_Cands_Writeable\" where id=? ";

            dataSource.setPoolPreparedStatements(false);
            conn = dataSource.getConnection();
            psmt = conn.prepareStatement(sql);

            psmt.setLong(1, id);
            res = psmt.executeQuery();
            while (res.next()) {
                String confirmState = res.getString("confirmState");
                System.out.println(confirmState);
                if (confirmState != null) {
                    if (confirmState.equals("40") || confirmState.equals("50") || confirmState.equals("60")) {
                        flag = true;
                    }
                }

            }

        } catch (Exception e) {
            throw e;
        } finally {
            if (res != null)
                res.close();
            if (psmt != null)
                psmt.close();
            if (conn != null)
                conn.close();
        }
        return flag;
    }
}
class TestThread extends Thread {
    public void run() {
        try {
            System.out.println(Thread.currentThread().getName() + " is running.");
            System.out.println(Thread.currentThread().getName() + ": " + dbcp.getKandsMailState(4392325L, ""));
        } catch (Exception exp) {
            System.out.println(exp.getMessage());
            exp.printStackTrace();
        }
    }
}

There were about 10 java, mongo and postgresql engineers to examine the problem. We found that: The first 6 or 7 thread are correct, after that, it start to scan the full table. If there are no conn.prepareStatement(sql), and use "select confirmState from wb_Cands_Writeable where id=4392325L", it works normally.

Alvin-Fu commented 5 years ago

你好,getmore的日志是怎么打印的?

lifubang commented 5 years ago

@AlvinLiFu You need to db.setProfilingLevel(2) first. and then use db.system.profile.find({ns:'****', "op" : "getmore"})

andreasscherbaum commented 5 years ago

Given that the original report was on a no longer supported PostgreSQL version: is this issue still open?

vaibhavdalvi93 commented 2 years ago

Hi @lifubang , Are you still facing this issue? If not, can you please close this ticket?

lifubang commented 2 years ago

Given that the original report was on a no longer supported PostgreSQL version

The maintainer said this maybe the reason, but I have no time to upgrade it, so close this, thanks.