- if($params['sort'] == 'timestamp')
- $this->addWhereRange('cl_timestamp', ($params['dir'] == 'asc' ? 'newer' : 'older'), $params['start'], $params['end']);
- else
- {
- $this->addWhereRange('cl_sortkey', ($params['dir'] == 'asc' ? 'newer' : 'older'), $params['startsortkey'], $params['endsortkey']);
- $this->addWhereRange('cl_from', ($params['dir'] == 'asc' ? 'newer' : 'older'), null, null);
+
+ $dir = $params['dir'] == 'asc' ? 'newer' : 'older';
+
+ if ( $params['sort'] == 'timestamp' ) {
+ $this->addWhereRange( 'cl_timestamp',
+ $dir,
+ $params['start'],
+ $params['end'] );
+
+ $this->addOption( 'USE INDEX', 'cl_timestamp' );
+ } else {
+ // The below produces ORDER BY cl_type, cl_sortkey, cl_from, possibly with DESC added to each of them
+ $this->addWhereRange( 'cl_type', $dir, null, null );
+ $this->addWhereRange( 'cl_sortkey',
+ $dir,
+ $params['startsortkey'],
+ $params['endsortkey'] );
+ $this->addWhereRange( 'cl_from', $dir, null, null );
+ $this->addOption( 'USE INDEX', 'cl_sortkey' );