Opened 8 years ago

Closed 8 years ago

#6301 closed enhancement (invalid)

ogr2ogr slow query for large number of schemas

Reported by: ktraff Owned by: warmerdam
Priority: high Milestone: 2.1.0
Component: OGR_SRS Version: 2.0.1
Severity: normal Keywords: ogr2ogr
Cc:

Description

We use ogr2ogr to upload shapefiles to our PostgreSQL database using the following command:

Error: Failed to load processor bash
No macro or processor named 'bash' found

Running this command generates a query (from ogrpgdatasource.cpp):

DECLARE mycursor CURSOR for
SELECT c.relname, n.nspname, c.relkind, g.f_geometry_column, g.type, g.coord_dimension, g.srid, 1, c.oid as oid, a.attnum as attnum
FROM pg_class c, pg_namespace n, geometry_columns g, pg_attribute a
WHERE (c.relkind in ('r','v') AND c.relname !~ '^pg_'
    AND c.relnamespace=n.oid AND c.relname::TEXT = g.f_table_name::TEXT
    AND n.nspname = g.f_table_schema AND a.attname = g.f_geometry_column
    AND a.attrelid = c.oid)
UNION SELECT c.relname, n.nspname, c.relkind, g.f_geography_column, g.type, g.coord_dimension, g.srid, 2, c.oid as oid, a.attnum as attnum
FROM pg_class c, pg_namespace n, geography_columns g, pg_attribute a
WHERE (c.relkind in ('r','v') AND c.relname !~ '^pg_'
    AND c.relnamespace=n.oid AND c.relname::TEXT = g.f_table_name::TEXT
    AND n.nspname = g.f_table_schema AND a.attname = g.f_geography_column
    AND a.attrelid = c.oid)
ORDER BY oid, attnum;
FETCH ALL in mycursor;

On development servers, where the number of schemas and tables are low, this query runs in less than 1 second. However, our beta and production databases have 925 users and each user has their own schema with about 5-15 tables in each. The query takes about 34 seconds and generates 13,331 rows.

Are there some simple optimizations that could be made to improve the performance of this query?

Change History (1)

comment:1 by Even Rouault, 8 years ago

Resolution: invalid
Status: newclosed

Questions should rather be directed to the gdal-dev mailing list. You can either restrict to specific schemas with the schemas= option, or to specific tables with the tables= option. See http://gdal.org/drv_pg_advanced.html

Note: See TracTickets for help on using tickets.