Skip to content

Commit 0ccd7bd

Browse files
committed
postgres provider: avoid column lookups with tableoids
1 parent 46da64a commit 0ccd7bd

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -706,30 +706,34 @@ bool QgsPostgresProvider::loadFields()
706706
tableoids.insert( tableoid );
707707
}
708708
}
709-
QStringList tableoidsList;
710-
foreach ( int tableoid, tableoids )
711-
{
712-
tableoidsList.append( QString::number( tableoid ) );
713-
}
714-
715-
QString tableoidsFilter = "(" + tableoidsList.join( "," ) + ")";
716-
717-
// Collect formatted field types
718-
sql = "SELECT attrelid, attnum, pg_catalog.format_type(atttypid,atttypmod), pg_catalog.col_description(attrelid,attnum), pg_catalog.pg_get_expr(adbin,adrelid)"
719-
" FROM pg_attribute"
720-
" LEFT OUTER JOIN pg_attrdef ON attrelid=adrelid AND attnum=adnum"
721-
" WHERE attrelid IN " + tableoidsFilter;
722-
QgsPostgresResult fmtFieldTypeResult = connectionRO()->PQexec( sql );
723-
for ( int i = 0; i < fmtFieldTypeResult.PQntuples(); ++i )
724-
{
725-
int attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toInt();
726-
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt();
727-
QString formatType = fmtFieldTypeResult.PQgetvalue( i, 2 );
728-
QString descr = fmtFieldTypeResult.PQgetvalue( i, 3 );
729-
QString defVal = fmtFieldTypeResult.PQgetvalue( i, 4 );
730-
fmtFieldTypeMap[attrelid][attnum] = formatType;
731-
descrMap[attrelid][attnum] = descr;
732-
defValMap[attrelid][attnum] = defVal;
709+
710+
if ( !tableoids.isEmpty() )
711+
{
712+
QStringList tableoidsList;
713+
foreach ( int tableoid, tableoids )
714+
{
715+
tableoidsList.append( QString::number( tableoid ) );
716+
}
717+
718+
QString tableoidsFilter = "(" + tableoidsList.join( "," ) + ")";
719+
720+
// Collect formatted field types
721+
sql = "SELECT attrelid, attnum, pg_catalog.format_type(atttypid,atttypmod), pg_catalog.col_description(attrelid,attnum), pg_catalog.pg_get_expr(adbin,adrelid)"
722+
" FROM pg_attribute"
723+
" LEFT OUTER JOIN pg_attrdef ON attrelid=adrelid AND attnum=adnum"
724+
" WHERE attrelid IN " + tableoidsFilter;
725+
QgsPostgresResult fmtFieldTypeResult = connectionRO()->PQexec( sql );
726+
for ( int i = 0; i < fmtFieldTypeResult.PQntuples(); ++i )
727+
{
728+
int attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toInt();
729+
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt();
730+
QString formatType = fmtFieldTypeResult.PQgetvalue( i, 2 );
731+
QString descr = fmtFieldTypeResult.PQgetvalue( i, 3 );
732+
QString defVal = fmtFieldTypeResult.PQgetvalue( i, 4 );
733+
fmtFieldTypeMap[attrelid][attnum] = formatType;
734+
descrMap[attrelid][attnum] = descr;
735+
defValMap[attrelid][attnum] = defVal;
736+
}
733737
}
734738
}
735739

0 commit comments

Comments
 (0)