Skip to content

Commit

Permalink
Add compiler setting check to order by compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 18, 2015
1 parent a177142 commit e555323
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 41 deletions.
47 changes: 28 additions & 19 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -116,29 +116,38 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource

mOrderByCompiled = true;

Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() )
if ( QSettings().value( "/qgis/compileExpressions", true ).toBool() )
{
QgsPostgresExpressionCompiler compiler = QgsPostgresExpressionCompiler( source );
QgsExpression expression = clause.expression();
if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete )
Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() )
{
QString part;
part = compiler.result();
part += clause.ascending() ? " ASC" : " DESC";
part += clause.nullsFirst() ? " NULLS FIRST" : " NULLS LAST";
orderByParts << part;
}
else
{
// Bail out on first non-complete compilation.
// Most important clauses at the beginning of the list
// will still be sent and used to pre-sort so the local
// CPU can use its cycles for fine-tuning.
mOrderByCompiled = false;
limitAtProvider = false;
break;
QgsPostgresExpressionCompiler compiler = QgsPostgresExpressionCompiler( source );
QgsExpression expression = clause.expression();
if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete )
{
QString part;
part = compiler.result();
part += clause.ascending() ? " ASC" : " DESC";
part += clause.nullsFirst() ? " NULLS FIRST" : " NULLS LAST";
orderByParts << part;
}
else
{
// Bail out on first non-complete compilation.
// Most important clauses at the beginning of the list
// will still be sent and used to pre-sort so the local
// CPU can use its cycles for fine-tuning.
mOrderByCompiled = false;
break;
}
}
}
else
{
mOrderByCompiled = false;
}

if ( !mOrderByCompiled )
limitAtProvider = false;

bool success = declareCursor( whereClause, limitAtProvider ? mRequest.limit() : -1, false, orderByParts.join( "," ) );
if ( !success && useFallbackWhereClause )
Expand Down
53 changes: 31 additions & 22 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Expand Up @@ -121,34 +121,43 @@ QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeature

mOrderByCompiled = true;

Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() )
if ( QSettings().value( "/qgis/compileExpressions", true ).toBool() )
{
QgsSpatiaLiteExpressionCompiler compiler = QgsSpatiaLiteExpressionCompiler( source );
QgsExpression expression = clause.expression();
if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete )
Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() )
{
QString part;
part = compiler.result();
QgsSpatiaLiteExpressionCompiler compiler = QgsSpatiaLiteExpressionCompiler( source );
QgsExpression expression = clause.expression();
if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete )
{
QString part;
part = compiler.result();

if ( clause.nullsFirst() )
orderByParts << QString( "%1 IS NOT NULL" ).arg( part );
else
orderByParts << QString( "%1 IS NULL" ).arg( part );
if ( clause.nullsFirst() )
orderByParts << QString( "%1 IS NOT NULL" ).arg( part );
else
orderByParts << QString( "%1 IS NULL" ).arg( part );

part += clause.ascending() ? " COLLATE NOCASE ASC" : " COLLATE NOCASE DESC";
orderByParts << part;
}
else
{
// Bail out on first non-complete compilation.
// Most important clauses at the beginning of the list
// will still be sent and used to pre-sort so the local
// CPU can use its cycles for fine-tuning.
mOrderByCompiled = false;
limitAtProvider = false;
break;
part += clause.ascending() ? " COLLATE NOCASE ASC" : " COLLATE NOCASE DESC";
orderByParts << part;
}
else
{
// Bail out on first non-complete compilation.
// Most important clauses at the beginning of the list
// will still be sent and used to pre-sort so the local
// CPU can use its cycles for fine-tuning.
mOrderByCompiled = false;
break;
}
}
}
else
{
mOrderByCompiled = false;
}

if ( !mOrderByCompiled )
limitAtProvider = false;

// preparing the SQL statement
bool success = prepareStatement( whereClause, limitAtProvider ? mRequest.limit() : -1, orderByParts.join( "," ) );
Expand Down

0 comments on commit e555323

Please sign in to comment.