Beispiel #1
0
        void run() {
            Client::WriteContext ctx(ns());

            for (int i = 0; i < 50; ++i) {
                insert(BSON("foo" << 8 << "bar" << 20));
            }

            addIndex(BSON("foo" << 1));
            addIndex(BSON("bar" << 1));

            WorkingSet ws;
            scoped_ptr<AndSortedStage> ah(new AndSortedStage(&ws, NULL));

            // Foo == 7.  Should be EOF.
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 7);
            params.bounds.endKey = BSON("" << 7);
            params.bounds.endKeyInclusive = true;
            params.direction = 1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Bar == 20, not EOF.
            params.descriptor = getIndex(BSON("bar" << 1));
            params.bounds.startKey = BSON("" << 20);
            params.bounds.endKey = BSON("" << 20);
            params.bounds.endKeyInclusive = true;
            params.direction = 1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            ASSERT_EQUALS(0, countResults(ah.get()));
        }
Beispiel #2
0
        void run() {
            Client::WriteContext ctx(ns());

            for (int i = 0; i < 50; ++i) {
                insert(BSON("foo" << 1 << "bar" << 1));
            }

            addIndex(BSON("foo" << 1));
            addIndex(BSON("bar" << 1));

            WorkingSet ws;
            BSONObj filterObj = BSON("foo" << BSON("$ne" << 1));
            StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
            verify(swme.isOK());
            auto_ptr<MatchExpression> filterExpr(swme.getValue());
            scoped_ptr<AndSortedStage> ah(new AndSortedStage(&ws, filterExpr.get()));

            // Scan over foo == 1
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 1);
            params.bounds.endKey = BSON("" << 1);
            params.bounds.endKeyInclusive = true;
            params.direction = 1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // bar == 1
            params.descriptor = getIndex(BSON("bar" << 1));
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Filter drops everything.
            ASSERT_EQUALS(0, countResults(ah.get()));
        }
Beispiel #3
0
        void run() {
            Client::WriteContext ctx(ns());

            for (int i = 0; i < 50; ++i) {
                insert(BSON("foo" << i << "bar" << 20));
            }

            addIndex(BSON("foo" << 1));
            addIndex(BSON("bar" << 1));

            WorkingSet ws;
            scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, NULL));

            // Foo <= 20
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.startKey = BSON("" << 20);
            params.endKey = BSONObj();
            params.endKeyInclusive = true;
            params.direction = -1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Bar == 5.  Index scan should be eof.
            params.descriptor = getIndex(BSON("bar" << 1));
            params.startKey = BSON("" << 5);
            params.endKey = BSON("" << 5);
            params.endKeyInclusive = true;
            params.direction = 1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            ASSERT_EQUALS(0, countResults(ah.get()));
        }
Beispiel #4
0
        void run() {
            // 20 <= foo <= 30
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.startKey = BSON("" << 20);
            params.endKey = BSON("" << 30);
            params.endKeyInclusive = true;
            params.direction = 1;

            ASSERT_EQUALS(countResults(params), 11);
        }
        void run() {
            // foo <= 20
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 20);
            params.bounds.endKey = BSONObj();
            params.bounds.endKeyInclusive = true;
            params.direction = -1;

            ASSERT_EQUALS(countResults(params), 21);
        }
Beispiel #6
0
        void run() {
            // 20 <= foo < 30
            // bar == 25 (not covered, should error.)
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.startKey = BSON("" << 20);
            params.endKey = BSON("" << 30);
            params.endKeyInclusive = true;
            params.direction = 1;

            ASSERT_THROWS(countResults(params, BSON("baz" << 25)), MsgAssertionException);
        }
        void run() {
            // 20 <= foo < 30
            // foo == 25
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 20);
            params.bounds.endKey = BSON("" << 30);
            params.bounds.endKeyInclusive = true;
            params.direction = 1;

            ASSERT_EQUALS(countResults(params, BSON("foo" << 25)), 1);
        }
Beispiel #8
0
        void run() {
            makeGeoData();
            addIndex(BSON("geo" << "2d"));

            // 2d should also work.
            IndexScanParams params;
            params.descriptor = getIndex(BSON("geo" << "2d"));
            params.startKey = BSON("geo" << BSON("$near" << BSON_ARRAY(0 << 0)));
            params.endKey = BSONObj();
            params.endKeyInclusive = true;
            params.direction = 1;

            ASSERT_EQUALS(countResults(params), numObj());
        }
Beispiel #9
0
    void run() {
        Client::WriteContext ctx(ns());
        Database* db = ctx.ctx().db();
        Collection* coll = db->getCollection(ns());
        if (!coll) {
            coll = db->createCollection(ns());
        }

        for (int i = 0; i < 50; ++i) {
            insert(BSON("foo" << i << "bar" << i << "baz" << i));
        }

        addIndex(BSON("foo" << 1));
        addIndex(BSON("bar" << 1));
        addIndex(BSON("baz" << 1));

        WorkingSet ws;
        scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, NULL));

        // Foo <= 20
        IndexScanParams params;
        params.descriptor = getIndex(BSON("foo" << 1), coll);
        params.bounds.isSimpleRange = true;
        params.bounds.startKey = BSON("" << 20);
        params.bounds.endKey = BSONObj();
        params.bounds.endKeyInclusive = true;
        params.direction = -1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // Bar >= 10
        params.descriptor = getIndex(BSON("bar" << 1), coll);
        params.bounds.startKey = BSON("" << 10);
        params.bounds.endKey = BSONObj();
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // 5 <= baz <= 15
        params.descriptor = getIndex(BSON("baz" << 1), coll);
        params.bounds.startKey = BSON("" << 5);
        params.bounds.endKey = BSON("" << 15);
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // foo == bar == baz, and foo<=20, bar>=10, 5<=baz<=15, so our values are:
        // foo == 10, 11, 12, 13, 14, 15.
        ASSERT_EQUALS(6, countResults(ah.get()));
    }
Beispiel #10
0
        void run() {
            // Add numObj() geo points.  Make sure we get them back.
            makeGeoData();
            addIndex(BSON("geo" << "2dsphere"));

            IndexScanParams params;
            params.descriptor = getIndex(BSON("geo" << "2dsphere"));
            params.startKey = BSON("geo" << BSON("$geoNear" << BSON("$geometry"
                                   << BSON("type" << "Point"
                                        << "coordinates" << BSON_ARRAY(0 << 0)))));
            params.endKey = BSONObj();
            params.endKeyInclusive = true;
            params.direction = 1;

            ASSERT_EQUALS(countResults(params), numObj());
        }
Beispiel #11
0
    void run() {
        Client::WriteContext ctx(ns());
        Database* db = ctx.ctx().db();
        Collection* coll = db->getCollection(ns());
        if (!coll) {
            coll = db->createCollection(ns());
        }

        // Insert a bunch of data
        for (int i = 0; i < 50; ++i) {
            // Some data that'll show up but not be in all.
            insert(BSON("foo" << 1 << "baz" << 1));
            insert(BSON("foo" << 1 << "bar" << 1));
            // The needle in the haystack.  Only these should be returned by the AND.
            insert(BSON("foo" << 1 << "bar" << 1 << "baz" << 1));
            insert(BSON("foo" << 1));
            insert(BSON("bar" << 1));
            insert(BSON("baz" << 1));
        }

        addIndex(BSON("foo" << 1));
        addIndex(BSON("bar" << 1));
        addIndex(BSON("baz" << 1));

        WorkingSet ws;
        scoped_ptr<AndSortedStage> ah(new AndSortedStage(&ws, NULL));

        // Scan over foo == 1
        IndexScanParams params;
        params.descriptor = getIndex(BSON("foo" << 1), coll);
        params.bounds.isSimpleRange = true;
        params.bounds.startKey = BSON("" << 1);
        params.bounds.endKey = BSON("" << 1);
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // bar == 1
        params.descriptor = getIndex(BSON("bar" << 1), coll);
        ah->addChild(new IndexScan(params, &ws, NULL));

        // baz == 1
        params.descriptor = getIndex(BSON("baz" << 1), coll);
        ah->addChild(new IndexScan(params, &ws, NULL));

        ASSERT_EQUALS(50, countResults(ah.get()));
    }
Beispiel #12
0
    void run() {
        Client::WriteContext ctx(ns());
        Database* db = ctx.ctx().db();
        Collection* coll = db->getCollection(ns());
        if (!coll) {
            coll = db->createCollection(ns());
        }

        for (int i = 0; i < 50; ++i) {
            insert(BSON("foo" << i << "bar" << (100 - i)));
        }

        addIndex(BSON("foo" << 1));
        addIndex(BSON("bar" << 1));

        WorkingSet ws;
        BSONObj filter = BSON("bar" << 97);
        StatusWithMatchExpression swme = MatchExpressionParser::parse(filter);
        verify(swme.isOK());
        auto_ptr<MatchExpression> filterExpr(swme.getValue());
        scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, filterExpr.get()));

        // Foo <= 20
        IndexScanParams params;
        params.descriptor = getIndex(BSON("foo" << 1), coll);
        params.bounds.isSimpleRange = true;
        params.bounds.startKey = BSON("" << 20);
        params.bounds.endKey = BSONObj();
        params.bounds.endKeyInclusive = true;
        params.direction = -1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // Bar >= 95
        params.descriptor = getIndex(BSON("bar" << 1), coll);
        params.bounds.startKey = BSON("" << 10);
        params.bounds.endKey = BSONObj();
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // Bar == 97
        ASSERT_EQUALS(1, countResults(ah.get()));
    }
Beispiel #13
0
    void run() {
        Client::WriteContext ctx(ns());
        Database* db = ctx.ctx().db();
        Collection* coll = db->getCollection(ns());
        if (!coll) {
            coll = db->createCollection(ns());
        }

        for (int i = 0; i < 50; ++i) {
            // Insert data with foo=7, bar==20, but nothing with both.
            insert(BSON("foo" << 8 << "bar" << 20));
            insert(BSON("foo" << 7 << "bar" << 21));
            insert(BSON("foo" << 7));
            insert(BSON("bar" << 20));
        }

        addIndex(BSON("foo" << 1));
        addIndex(BSON("bar" << 1));

        WorkingSet ws;
        scoped_ptr<AndSortedStage> ah(new AndSortedStage(&ws, NULL));

        // foo == 7.
        IndexScanParams params;
        params.descriptor = getIndex(BSON("foo" << 1), coll);
        params.bounds.isSimpleRange = true;
        params.bounds.startKey = BSON("" << 7);
        params.bounds.endKey = BSON("" << 7);
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // bar == 20.
        params.descriptor = getIndex(BSON("bar" << 1), coll);
        params.bounds.startKey = BSON("" << 20);
        params.bounds.endKey = BSON("" << 20);
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        ASSERT_EQUALS(0, countResults(ah.get()));
    }
Beispiel #14
0
    void run() {
        Client::WriteContext ctx(ns());
        Database* db = ctx.ctx().db();
        Collection* coll = db->getCollection(ns());
        if (!coll) {
            coll = db->createCollection(ns());
        }

        for (int i = 0; i < 10; ++i) {
            insert(BSON("foo" << (100 + i)));
            insert(BSON("bar" << i));
        }

        addIndex(BSON("foo" << 1));
        addIndex(BSON("bar" << 1));

        WorkingSet ws;
        scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, NULL));

        // Foo >= 100
        IndexScanParams params;
        params.descriptor = getIndex(BSON("foo" << 1), coll);
        params.bounds.isSimpleRange = true;
        params.bounds.startKey = BSON("" << 100);
        params.bounds.endKey = BSONObj();
        params.bounds.endKeyInclusive = true;
        params.direction = 1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        // Bar <= 100
        params.descriptor = getIndex(BSON("bar" << 1), coll);
        params.bounds.startKey = BSON("" << 100);
        // This is subtle and confusing.  We couldn't extract any keys from the elements with
        // 'foo' in them so we would normally index them with the "nothing found" key.  We don't
        // want to include that in our scan.
        params.bounds.endKey = BSON("" << "");
        params.bounds.endKeyInclusive = false;
        params.direction = -1;
        ah->addChild(new IndexScan(params, &ws, NULL));

        ASSERT_EQUALS(0, countResults(ah.get()));
    }
Beispiel #15
0
 void run() {
     BSONObj obj = BSON("foo" << BSON("$lt" << 25));
     ASSERT_EQUALS(25, countResults(CollectionScanParams::BACKWARD, obj));
 }
Beispiel #16
0
 void run() {
     ASSERT_EQUALS(numObj(), countResults(CollectionScanParams::BACKWARD, BSONObj()));
 }
Beispiel #17
0
	unsigned int countSuccess() const { return countResults() - countFailed(); };