Permalink
Browse files

[PostGIS] Format literal number in filter as integer when possible to…

… avoid performance issues
  • Loading branch information...
rouault committed Mar 27, 2017
1 parent 62c1735 commit b814f93cda0bf9b9b8ed7f32626803519d3d1571
Showing with 7 additions and 3 deletions.
  1. +7 −3 mappostgis.c
View
@@ -3636,9 +3636,13 @@ int msPostGISLayerTranslateFilter(layerObj *layer, expressionObj *filter, char *
native_string = msStringConcatenate(native_string, "FALSE");
break;
case MS_TOKEN_LITERAL_NUMBER:
- strtmpl = "%lf";
- snippet = (char *) msSmallMalloc(strlen(strtmpl) + 16);
- sprintf(snippet, strtmpl, node->tokenval.dblval);
+ snippet = (char *) msSmallMalloc(32);
+ if( node->tokenval.dblval >= INT_MIN &&
+ node->tokenval.dblval <= INT_MAX &&
+ node->tokenval.dblval == (int)node->tokenval.dblval )
+ sprintf(snippet, "%d", (int)node->tokenval.dblval);
+ else
+ sprintf(snippet, "%.18g", node->tokenval.dblval);
native_string = msStringConcatenate(native_string, snippet);
msFree(snippet);
break;

0 comments on commit b814f93

Please sign in to comment.