在PostGIS View中优化查询和连接

时间:2015-07-29 09:00:22

标签: sql postgresql postgis postgresql-performance

我正在开发一个webmapping应用程序,其中我使用PosgreSQL和PostGIS插件作为我的数据库。

我有这两张桌子; CREATE TABLE evidensapp_seniangcbr ( id serial NOT NULL, hazard character varying(16) NOT NULL, geom geometry(MultiPolygon,32651), CONSTRAINT evidensapp_seniangcbr_pkey PRIMARY KEY (id) ); CREATE INDEX evidensapp_seniangcbr_geom_id ON evidensapp_seniangcbr USING gist (geom); CREATE TABLE evidensapp_polystructures ( id serial NOT NULL, bldg_name character varying(100) NOT NULL, bldg_type character varying(50) NOT NULL, brgy_locat character varying(50) NOT NULL, municipali character varying(50) NOT NULL, province character varying(50) NOT NULL, geom geometry(MultiPolygon,32651), CONSTRAINT evidensapp_polystructures_pkey PRIMARY KEY (id) ); CREATE INDEX evidensapp_polystructures_geom_id ON evidensapp_polystructures USING gist (geom); ALTER TABLE evidensapp_polystructures CLUSTER ON evidensapp_polystructures_geom_id; structures。两个表都包含几何(多边形)。

seniang

我的查询下面需要将近15分钟。获得与hazard='High'Medium相交的Low的结果-- Executing query: SELECT count(evidensapp_polystructures.brgy_locat) AS High, evidensapp_polystructures.brgy_locat AS Barangay, evidensapp_polystructures.municipali AS Municipality FROM evidensapp_seniangcbr INNER JOIN evidensapp_polystructures ON ST_Intersects(evidensapp_seniangcbr.geom, evidensapp_polystructures.geom) WHERE evidensapp_seniangcbr.hazard = 'High' GROUP BY evidensapp_polystructures.brgy_locat, evidensapp_polystructures.municipali; Total query runtime: 896688 ms. 23 rows retrieved. 。这同样适用于hazardCREATE OR REPLACE VIEW high_seninang AS SELECT count(evidensapp_polystructures.brgy_locat) AS high, evidensapp_polystructures.brgy_locat AS barangay, evidensapp_polystructures.municipali AS municipality FROM evidensapp_seniangcbr JOIN evidensapp_polystructures ON ST_Intersects(evidensapp_seniangcbr.geom, evidensapp_polystructures.geom) WHERE evidensapp_seniangcbr.hazard::text = 'High'::text AND evidensapp_seniangcbr.geom && evidensapp_polystructures.geom GROUP BY evidensapp_polystructures.brgy_locat, evidensapp_polystructures.municipali;

polystructures

这是不可接受的。那么,我该如何优化呢?我已根据此site完成了空间索引和聚类。

我为每个INFO: analyzing "public.evidensapp_polystructures" INFO: "evidensapp_polystructures": scanned 288 of 288 pages, containing 9847 live rows and 0 dead rows; 9847 rows in sample, 9847 estimated total rows Total query runtime: 122 ms. 创建了一个视图:

seniangcbr

这导致高危险的结果:

enter image description here

如何使用我的视图获得结果: enter image description here

INFO: analyzing "public.evidensapp_seniangcbr" INFO: "evidensapp_seniangcbr": scanned 1 of 1 pages, containing 6 live rows and 0 dead rows; 6 rows in sample, 6 estimated total rows Total query runtime: 219 ms.

public frmChequeFormat()
    {
        InitializeComponent();
        gbCheque.MouseMove += gbCheque_MouseMove;
    }
    bool mDown = false;
    private void gbCheque_MouseMove(object sender, MouseEventArgs e)
    {
        if (mDown)
        {
            label13.Location = e.Location;
        }
    }
    private void label13_MouseDown(object sender, MouseEventArgs e)
    {
        mDown = true;
    }
    private void label13_MouseUp(object sender, MouseEventArgs e)
    {
        mDown = false;
    }

2. CONDITIONAL FORMATTING DIFFERENCES FORMULA1: Sheet1(0) Rule 0 IS: SHOULD BE: IF(INT(COUNT($C$1:$C$7)*13%)>0,LARGE($C$1:$C$7,INT(COUNT($C$1:$C$7)*13%)),MAX($C$1:$C$7))<=A1 BCOLOR: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 20 UNDERLINE: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 255 Sheet1(0) Rule 0 IS: 0 SHOULD BE: 255 Sheet1(0) Rule 1 IS: 0 SHOULD BE: 255 LCOLOR: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 20 FOREGROUND: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 64 Sheet1(0) Rule 0 IS: 0 SHOULD BE: 64 Sheet1(0) Rule 1 IS: 0 SHOULD BE: 64 TYPE: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 2 ESCAPMENT TYPE: Sheet1(0) Rule 0 IS: 0 SHOULD BE: -1 Sheet1(0) Rule 0 IS: 0 SHOULD BE: -1 Sheet1(0) Rule 1 IS: 0 SHOULD BE: -1 TCOLOR: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 20 BACKCOLOR: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 45 Sheet1(0) Rule 0 IS: 0 SHOULD BE: 43 Sheet1(0) Rule 1 IS: 0 SHOULD BE: 43 FONT COLOR: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 20 Sheet1(0) Rule 0 IS: 0 SHOULD BE: 60 Sheet1(0) Rule 1 IS: 0 SHOULD BE: 60 RCOLOR: Sheet1(0) Rule 0 IS: 0 SHOULD BE: 20

.seperator {
 display: inline-block;
 height: 10px;
 margin-left: 69px;
 margin-right: 206px;
 width: 10px;
}

0 个答案:

没有答案