I am using postgis to serve 10+ layers, and the data will be returned by a given bbox and a zoom level.

This is the sql I used for query features:

```
public List<Feature> getFeature(double[] bbox, int zoom){
    List<Feature> features=new ArrayList();
    for(String layer:layers){
        String sql = "SELECT name, ST_Intersection(layer.geom,bbox.geom) as dest_geom FROM layer JOIN (select ST_MakeEnvelope(?, ?, ?, ?, 4326) as geom) bbox ON st_intersects(table_name.geom, bbox.geom) where layer.zoom <= ?";
        ResultSet rs=conn.executeQuery(sql); //

        while(rs.next()){
            Feature f=new Feature();
            f.name = rs.getString("name");
            f.geometry = f.getObject("dest_geom")
        ....
            features.add(f);
        }

    }
    return features;
}

```

Now it will take almost 200ms for a bbox which conver a 512x512 tile in zoom 16, however it will take almost 10s for a bbox which conver a 512x512 tile in zoom 10. 

Though the later have a wide range which means more features, however in a small zoom level the visible features is less too, and that is what the `where layer.zoom<=?` condition does.

And I have created index for each layer by following this [docs](http://revenant.ca/www/postgis/workshop/indexing.html):

```
CREATE INDEX layer_gix ON layer USING GIST (geom);
....

```

Is there anything I can do to speedup the query?

---

Update( add explain analyze):

[![enter image description here](https://i.stack.imgur.com/XXD5I.png)](https://i.stack.imgur.com/XXD5I.png)

select no-geometry fields:
[![enter image description here](https://i.stack.imgur.com/FSJ9U.png)](https://i.stack.imgur.com/FSJ9U.png)