From: Greg W. <wo...@ee...> - 2013-05-07 19:48:39
|
Hello. I'm using tdbc::postgres with a fairly large database (PostgreSQL version 8.4), and while everything is working, I've noticed that issuing the "columns" command on a large table (~300,000 rows) takes nearly 3 seconds. The code is executing a "SELECT * FROM table" query, but only retrieving a single row. Unfortunately, with my tables, there seems to be a substantial delay before that row can be retrieved. I believe that adding "LIMIT 1" tells the query planner to use a more appropriate plan for this case. --- generic/tdbcpostgres.c.bak 2013-05-07 15:08:24.000000000 -0400 +++ generic/tdbcpostgres.c 2013-05-07 14:56:50.000000000 -0400 @@ -1479,6 +1479,7 @@ /* Check if table exists by retreiving one row. * The result wille be later used to determine column types (oids) */ Tcl_AppendObjToObj(sqlQuery, objv[2]); + Tcl_AppendToObj(sqlQuery," LIMIT 1", -1); if (ExecSimpleQuery(interp, cdata->pgPtr, Tcl_GetString(sqlQuery), &resType) != TCL_OK) { I've tested this patch, briefly, but not in production yet. The columns command definitely runs more quickly. Does this seem like an appropriate solution, or have I overlooked something? |