We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Are you selecting more than 30% of the rows in your table with the greater than query? If so, MySQL will apparently ignore the index and do a full table scan because it thinks it is faster. If you change the date to be more selective (smaller date range that excludes more records) I bet it will use the index.
      • 34178
      • 212 Posts
      Thanks, you are completely right. I just tried it for the column `ìd` and it is very fast when WHERE includes less than 30 %. Unfortunately it doesn´t work for a field which type is `date` like in our case (I tried: 2011-11-25 which should bring back less than 10 % of the rows).

      Since we want the whole database (because we already deleted all events which took place in the past) is there any other tag to load the entire content of the database? We already tried this:

      $db= $modx->getCollection('events');


      But this wasn´t any faster than the other call and I am in addition not sure if this is a correct syntax.
        • 34178
        • 212 Posts
        We got a big speed-boost by changing

        $db= $modx->getCollection('events', array('date:>=' => $datetoday));

        into
        $db = mysql_query("SELECT * FROM `events` WHERE (`date` >= $datetoday)  ORDER BY date") or die(mysql_error());


        Now the call takes far less than 1 second (comparing to >7 seconds by the getCollection-method). Is this maybe a hint for having an error in our schema? (we use the CreateXpdoClasses-Snippet for creating the schema.)

        Does anybody has an idea what could be the problem in our setting?
          • 31946
          • 116 Posts
          I'm not sure:
          Maybe it's because of creating all the Objects with getCollection.
          Try to use getIterator instead of getCollection, the difference is described here:

          http://rtfm.modx.com/display/xPDO20/Retrieving+Objects