Very poor performance of QGIS and PostGIS 2. User error or feature?

To my knowledge, GIS as Arcmap or QGIS can't support layers with several primitives (point, polygon or polyline). What GIS do you use?

You can try to create tables for each type:

Point:

SELECT * INTO newtablepoints FROM initial_table 
WHERE ST_GeometryType(geom) = 'ST_Point' ;

polygon :

SELECT * INTO newtablepolygones FROM initial_table 
WHERE ST_GeometryType(geom) = 'ST_MultiPolygon' or ST_GeometryType(geom) = 'ST_Polygon' ;

polyline :

SELECT * INTO newtablelines FROM initial_table 
WHERE ST_GeometryType(geom) ='ST_MultiLineString' or ST_GeometryType(geom) = 'ST_LineString';

You can try to add a geometric index :

CREATE INDEX idx_spatial_points ON newtablepoints USING GIST (geom);
CREATE INDEX idx_spatial_polygones ON newtablepolygones USING GIST (geom);
CREATE INDEX idx_spatial_lines ON newtablelines USING GIST (geom);

It will accelerate geographic queries.

Then these three tables will be more easily support by QGIS


As previously mentioned, mixed Geometries in one layer are not supported by QGIS.

If you have strong use case for keeping all of the data in a single table, another option to creating new tables (as suggested by @Benno) would be to create views referencing each geometry type from the initial table:

CREATE VIEW vwPoints 
SELECT <fields> 
FROM initial_table 
WHERE ST_GeometryType(geom) = 'ST_Point'

I am not sure about is the performance implications of going with views vs. individual tables, but that is something you could easily experiment with and decide which route you want to take.


When setting up the Postgis connection, you can check "use estimated table metadata". This will prevent QGIS from looking through all features every time you load the layer.

Unfortunately, you can't change it later on in an easy way.

EDIT

Mixed Geometries in one layer are not supported by QGIS.