~james-page/ubuntu/precise/mongodb/arch-enablement

« back to all changes in this revision

Viewing changes to db/queryoptimizer.cpp

  • Committer: Package Import Robot
  • Author(s): Antonin Kral
  • Date: 2012-06-05 19:52:28 UTC
  • mfrom: (1.2.18)
  • Revision ID: package-import@ubuntu.com-20120605195228-y35631zus0oblqd7
Tags: 1:2.0.6-1
New upstream release 2.0.6
https://jira.mongodb.org/browse/SERVER/fixforversion/11165

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
        if ( willScanTable() ) {
215
215
            if ( _frs.nNontrivialRanges() ) {
216
216
                checkTableScanAllowed( _frs.ns() );
217
 
                
218
 
                // if we are doing a table scan on _id
219
 
                // and its a capped collection
220
 
                // we disallow as its a common user error
221
 
                // .system. and local collections are exempt
222
 
                if ( _d && _d->capped && _frs.range( "_id" ).nontrivial() ) {
223
 
                    if ( cc().isSyncThread() ||
224
 
                         str::contains( _frs.ns() , ".system." ) || 
225
 
                         str::startsWith( _frs.ns() , "local." ) ) {
226
 
                        // ok
227
 
                    }
228
 
                    else {
229
 
                        warning() << "_id query on capped collection without an _id index, performance will be poor collection: " << _frs.ns() << endl;
230
 
                        //uassert( 14820, str::stream() << "doing _id query on a capped collection without an index is not allowed: " << _frs.ns() ,
231
 
                    }
232
 
                }
233
217
            }
234
218
            return findTableScan( _frs.ns(), _order, startLoc );
235
219
        }
486
470
                    _usingPrerecordedPlan = true;
487
471
                    _mayRecordPlan = false;
488
472
                    _plans.push_back( p );
 
473
                    warnOnCappedIdTableScan();
489
474
                    return;
490
475
                }
491
476
            }
492
477
        }
493
478
 
494
479
        addOtherPlans( false );
 
480
        warnOnCappedIdTableScan();
495
481
    }
496
482
 
497
483
    void QueryPlanSet::addOtherPlans( bool checkFirst ) {
633
619
        }
634
620
        return _plans[0];
635
621
    }
 
622
    
 
623
    void QueryPlanSet::warnOnCappedIdTableScan() const {
 
624
        // if we are doing a table scan on _id
 
625
        // and it's a capped collection
 
626
        // we warn as it's a common user error
 
627
        // .system. and local collections are exempt
 
628
        const char *ns = _frsp->ns();
 
629
        NamespaceDetails *d = nsdetails( ns );
 
630
        if ( d &&
 
631
            d->capped &&
 
632
            nPlans() == 1 &&
 
633
            firstPlan()->willScanTable() &&
 
634
            firstPlan()->multikeyFrs().range( "_id" ).nontrivial() ) {
 
635
            if ( cc().isSyncThread() ||
 
636
                str::contains( ns , ".system." ) ||
 
637
                str::startsWith( ns , "local." ) ) {
 
638
                // ok
 
639
            }
 
640
            else {
 
641
                warning()
 
642
                << "unindexed _id query on capped collection, "
 
643
                << "performance will be poor collection: " << ns << endl;
 
644
            }
 
645
        }
 
646
    }
636
647
 
637
648
    QueryPlanSet::Runner::Runner( QueryPlanSet &plans, QueryOp &op ) :
638
649
        _op( op ),
1247
1258
    void QueryUtilIndexed::clearIndexesForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order ) {
1248
1259
        SimpleMutex::scoped_lock lk(NamespaceDetailsTransient::_qcMutex);
1249
1260
        NamespaceDetailsTransient& nsd = NamespaceDetailsTransient::get_inlock( frsp.ns() );
1250
 
        nsd.registerIndexForPattern( frsp._singleKey.pattern( order ), BSONObj(), 0 );
1251
 
        nsd.registerIndexForPattern( frsp._multiKey.pattern( order ), BSONObj(), 0 );
 
1261
        if ( frsp._singleKey.matchPossible() ) {
 
1262
            nsd.registerIndexForPattern( frsp._singleKey.pattern( order ), BSONObj(), 0 );
 
1263
        }
 
1264
        if ( frsp._multiKey.matchPossible() ) {
 
1265
            nsd.registerIndexForPattern( frsp._multiKey.pattern( order ), BSONObj(), 0 );
 
1266
        }
1252
1267
    }
1253
1268
    
1254
1269
    pair< BSONObj, long long > QueryUtilIndexed::bestIndexForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order ) {