Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-16762

Loss of type information for covered queries in WiredTiger

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Index Maintenance, Storage
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Hide
      #include <iostream>
      #include <vector>
      #include "mongo/client/dbclient.h"
      
      using namespace std;
      using namespace mongo;
      
      int main() {
          client::initialize();
          DBClientConnection c;
          c.connect("localhost");
      
          c.dropDatabase("test");
          c.createIndex("test.wow", IndexSpec().addKeys(BSON("a" << 1)));
      
          BSONObj toInsert = BSON("a" << 1);
          cout << "type in: " << toInsert.getField("a").type() << endl;
          c.insert("test.wow", toInsert);
      
          BSONObj distinct;
          c.runCommand("test", BSON(
              "distinct" << "wow" <<
              "key" << "a"
          ), distinct);
      
          vector<BSONElement> result = distinct.getField("values").Array();
          cout << "type out: " << result[0].type() << endl;
      }
      
      $ g++ test.cpp -I ./include -L ./lib -lmongoclient -lboost_system -lboost_regex -lboost_thread
      $ ./a.out                                                                                     
      type in: 16
      type out: 1
      
      Show
      #include <iostream> #include <vector> #include "mongo/client/dbclient.h" using namespace std ; using namespace mongo; int main() { client::initialize(); DBClientConnection c; c.connect( "localhost" ); c.dropDatabase( "test" ); c.createIndex( "test.wow" , IndexSpec().addKeys(BSON( "a" << 1))); BSONObj toInsert = BSON( "a" << 1); cout << "type in: " << toInsert.getField( "a" ).type() << endl; c.insert( "test.wow" , toInsert); BSONObj distinct; c.runCommand( "test" , BSON( "distinct" << "wow" << "key" << "a" ), distinct); vector <BSONElement> result = distinct.getField( "values" ).Array(); cout << "type out: " << result[0].type() << endl; } $ g++ test.cpp -I ./include -L ./lib -lmongoclient -lboost_system -lboost_regex -lboost_thread $ ./a.out type in: 16 type out: 1

      I'm not sure if this is by design but I have observed this behavior change between WiredTiger and MMAPv1.

      Using MMAP the covered distinct result has the same bson type as the data that was inserted. However when using WiredTiger the distinct result has type double instead of Int32.

      I realize that this is due to the new index key format for WiredTiger but I was surprised that distinct would product this result.

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            tyler@10gen.com Tyler Brock
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: