Is ST_GeomFromText better than providing direct geometry?

Is ST_GeomFromText better than providing direct geometry?

  • I have been working with postgis recently,and in my query if I use ST_GeomFromText it execute faster than running a sub-query to get geom. I thought ST_GeomFromText will be more expensive but after running many tests every time I got the result faster, my question Is there any explanation behind this? because for me getting the geom directly in sub-query is better than getting geom as text then added as GeomFromText. Thanks

  • Answer:

    You should run an "explain analyze" on both queries. As with most performance-related questions, this can provide you with the quantitative data you'll need to answer your question. Post here if you find anything interesting. Based on your question alone, it's totally possible the sub-query approach would take longer. Why do you expect it to be quicker? Yes, the RDBMS doesn't have to parse your WKT string to a geometry type, BUT your sub query represents additional processing. Based on your schema, this could actually be very expensive! Look at the explain output - the query planner could be executing a sequential scan in the sub-query.

Sara at Geographic Information Systems Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.