performance - 索引和性能

标签 performance postgresql indexing postgis geotools

我是 Geotools 的新手并面临这个问题:我在 PostGis 中注入(inject)了大约 2MB 的 shapefile 信息(大约 5800 个条目),令人惊讶的是它大约需要 6 分钟才能完成!非常烦人,因为按 shapefile 组(shp、dbf...),我的“真实”数据集可能高达 25MB,需要 100 个组。

有人告诉我这可能是一个索引问题,因为 Postgre 在每个 INSERT 时都会更新表的索引。有没有办法在我的大量 INSERT 期间“禁用”这些索引并告诉数据库最后创建所有索引?或者有更好的方法吗?

这是我的代码片段:

Map<String, Object> shpparams = new HashMap<String, Object>();
shpparams.put("url", "file://" + path);
FileDataStore shpStore = (FileDataStore) shpFactory.createDataStore(shpparams);
SimpleFeatureCollection features = shpStore.getFeatureSource().getFeatures();
if (schema == null) {
    // Copy schema and change name in order to refer to the same
    // global schema for all files
    SimpleFeatureType originalSchema = shpStore.getSchema();
    Name originalName = originalSchema.getName();
    NameImpl theName = new NameImpl(originalName.getNamespaceURI(), originalName.getSeparator(), POSTGIS_TABLENAME);
    schema = factory.createSimpleFeatureType(theName, originalSchema.getAttributeDescriptors(), originalSchema.getGeometryDescriptor(),
            originalSchema.isAbstract(), originalSchema.getRestrictions(), originalSchema.getSuper(), originalSchema.getDescription());
    pgStore.createSchema(schema);
}
// String typeName = shpStore.getTypeNames()[0];
SimpleFeatureStore featureStore = (SimpleFeatureStore) pgStore.getFeatureSource(POSTGIS_TABLENAME);

// Ajout des objets du shapefile dans la table PostGIS
DefaultTransaction transaction = new DefaultTransaction("create");
featureStore.setTransaction(transaction);
try {
    featureStore.addFeatures(features);
    transaction.commit();
} catch (Exception problem) {
    LOGGER.error(problem.getMessage(), problem);
    transaction.rollback();
} finally {
    transaction.close();
}
shpStore.dispose();

感谢您的帮助!


所以我测试了您的解决方案,但没有任何帮助...完成时间仍然相同。这是我的表格定义:

  • fid 序列号 10
  • the_geom 几何 2147483647
  • xxx 变量 10
  • xxx int4 10
  • xxx 可变字符 3
  • xxx 变量 2
  • xxx float8 17
  • xxx float8 17
  • xxx float8 17

所以我认为问题与我的代码或数据库没有直接关系,可能是由于系统限制(RAM、缓冲区...)。在接下来的几天里,我会看看这个。

你有更多的想法吗?

最佳答案

我带着这个问题的解决方案回来了。经过多次调查,我发现物理网络是问题所在:使用本地数据库(本地到 geotools 应用程序)没有问题。网络为每个 INSERT 语句请求增加了 200 或 300 毫秒。随着数据库中注入(inject)的大量数据,响应时间变得非常长!

所以原始 Postgis 配置或我的代码片段没有问题...

感谢大家的参与。

关于performance - 索引和性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8578417/

相关文章:

MATLAB 索引问题

MySQL 查询 - 跨多个查询定义复合索引和单个索引。如何防止索引冲突并产生慢查询?

performance - Joomla与CodeIgniter/YII

java - 未使用的基元数组 : what do javac and the JIT compiler do with it?

r - 提升 ggplot2 性能

mysql - Postgresql 查询用于在连接期间更新不同表中的多个列

json - 函数 json_each 不存在

ruby-on-rails - 如何创建 Rails 迁移以删除/更改精度和小数位数?

search - 在索引时而不是在 Solr 中查询时应用字段提升的好处?

ios - CoreData 总和性能