Author: kwright
Date: Wed Apr 24 00:57:10 2013
New Revision: 1471217
URL: http://svn.apache.org/r1471217
Log:
Add EXPLAIN ANALYZE to postgresql
Modified:
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
Modified:
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java?rev=1471217&r1=1471216&r2=1471217&view=diff
==============================================================================
---
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
(original)
+++
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
Wed Apr 24 00:57:10 2013
@@ -108,6 +108,7 @@ public class DBInterfacePostgreSQL exten
/** Initialize. This method is called once per JVM instance, in order to
set up
* database communication.
*/
+ @Override
public void openDatabase()
throws ManifoldCFException
{
@@ -117,6 +118,7 @@ public class DBInterfacePostgreSQL exten
/** Uninitialize. This method is called during JVM shutdown, in order to
close
* all database communication.
*/
+ @Override
public void closeDatabase()
throws ManifoldCFException
{
@@ -126,6 +128,7 @@ public class DBInterfacePostgreSQL exten
/** Get the database general cache key.
*@return the general cache key for the database.
*/
+ @Override
public String getDatabaseCacheKey()
{
return cacheKey;
@@ -137,6 +140,7 @@ public class DBInterfacePostgreSQL exten
* invalidated.
*@param parameterMap is the map of column name/values to write.
*/
+ @Override
public void performInsert(String tableName, Map<String,Object> parameterMap,
StringSet invalidateKeys)
throws ManifoldCFException
{
@@ -190,6 +194,7 @@ public class DBInterfacePostgreSQL exten
*@param whereClause is the where clause describing the match (including the
WHERE), or null if none.
*@param whereParameters are the parameters that come with the where clause,
if any.
*/
+ @Override
public void performUpdate(String tableName, Map<String,Object> parameterMap,
String whereClause,
List whereParameters, StringSet invalidateKeys)
throws ManifoldCFException
@@ -256,6 +261,7 @@ public class DBInterfacePostgreSQL exten
*@param whereClause is the where clause describing the match (including the
WHERE), or null if none.
*@param whereParameters are the parameters that come with the where clause,
if any.
*/
+ @Override
public void performDelete(String tableName, String whereClause, List
whereParameters, StringSet invalidateKeys)
throws ManifoldCFException
{
@@ -282,6 +288,7 @@ public class DBInterfacePostgreSQL exten
* layer.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
+ @Override
public void performCreate(String tableName, Map<String,ColumnDescription>
columnMap, StringSet invalidateKeys)
throws ManifoldCFException
{
@@ -341,6 +348,7 @@ public class DBInterfacePostgreSQL exten
*@param columnDeleteList is the list of column names to delete.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
+ @Override
public void performAlter(String tableName, Map<String,ColumnDescription>
columnMap,
Map<String,ColumnDescription> columnModifyMap, List<String>
columnDeleteList,
StringSet invalidateKeys)
@@ -435,6 +443,7 @@ public class DBInterfacePostgreSQL exten
*@param columnList is the list of columns that need to be included
* in the index, in order.
*/
+ @Override
public void addTableIndex(String tableName, boolean unique, List<String>
columnList)
throws ManifoldCFException
{
@@ -453,6 +462,7 @@ public class DBInterfacePostgreSQL exten
*@param indexName is the optional name of the table index. If null, a name
will be chosen automatically.
*@param description is the index description.
*/
+ @Override
public void performAddIndex(String indexName, String tableName,
IndexDescription description)
throws ManifoldCFException
{
@@ -489,6 +499,7 @@ public class DBInterfacePostgreSQL exten
*@param indexName is the name of the index to remove.
*@param tableName is the table the index belongs to.
*/
+ @Override
public void performRemoveIndex(String indexName, String tableName)
throws ManifoldCFException
{
@@ -500,6 +511,7 @@ public class DBInterfacePostgreSQL exten
*@param tableName is the name of the table to drop.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
+ @Override
public void performDrop(String tableName, StringSet invalidateKeys)
throws ManifoldCFException
{
@@ -511,6 +523,7 @@ public class DBInterfacePostgreSQL exten
*@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
+ @Override
public void createUserAndDatabase(String adminUserName, String
adminPassword, StringSet invalidateKeys)
throws ManifoldCFException
{
@@ -565,6 +578,7 @@ public class DBInterfacePostgreSQL exten
*@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
+ @Override
public void dropUserAndDatabase(String adminUserName, String adminPassword,
StringSet invalidateKeys)
throws ManifoldCFException
{
@@ -623,6 +637,7 @@ public class DBInterfacePostgreSQL exten
*@param params are the parameterized values, if needed.
*@param invalidateKeys are the cache keys to invalidate.
*/
+ @Override
public void performModification(String query, List params, StringSet
invalidateKeys)
throws ManifoldCFException
{
@@ -643,6 +658,7 @@ public class DBInterfacePostgreSQL exten
*@return a map of column names and ColumnDescription objects, describing the
schema, or null if the
* table doesn't exist.
*/
+ @Override
public Map<String,ColumnDescription> getTableSchema(String tableName,
StringSet cacheKeys, String queryClass)
throws ManifoldCFException
{
@@ -687,6 +703,7 @@ public class DBInterfacePostgreSQL exten
*@param queryClass is the name of the query class, or null.
*@return a map of index names and IndexDescription objects, describing the
indexes.
*/
+ @Override
public Map<String,IndexDescription> getTableIndexes(String tableName,
StringSet cacheKeys, String queryClass)
throws ManifoldCFException
{
@@ -770,6 +787,7 @@ public class DBInterfacePostgreSQL exten
*@param queryClass is the name of the query class, or null.
*@return the set of tables.
*/
+ @Override
public StringSet getAllTables(StringSet cacheKeys, String queryClass)
throws ManifoldCFException
{
@@ -795,6 +813,7 @@ public class DBInterfacePostgreSQL exten
* or null if no LRU behavior desired.
*@return a resultset.
*/
+ @Override
public IResultSet performQuery(String query, List params, StringSet
cacheKeys, String queryClass)
throws ManifoldCFException
{
@@ -818,6 +837,7 @@ public class DBInterfacePostgreSQL exten
*@param returnLimit is a description of how to limit the return result, or
null if no limit.
*@return a resultset.
*/
+ @Override
public IResultSet performQuery(String query, List params, StringSet
cacheKeys, String queryClass,
int maxResults, ILimitChecker returnLimit)
throws ManifoldCFException
@@ -843,6 +863,7 @@ public class DBInterfacePostgreSQL exten
*@param returnLimit is a description of how to limit the return result, or
null if no limit.
*@return a resultset.
*/
+ @Override
public IResultSet performQuery(String query, List params, StringSet
cacheKeys, String queryClass,
int maxResults, ResultSpecification resultSpec, ILimitChecker returnLimit)
throws ManifoldCFException
@@ -863,6 +884,7 @@ public class DBInterfacePostgreSQL exten
*@param value is the value to be cast.
*@return the query chunk needed.
*/
+ @Override
public String constructDoubleCastClause(String value)
{
return "CAST("+value+" AS DOUBLE PRECISION)";
@@ -874,6 +896,7 @@ public class DBInterfacePostgreSQL exten
*@param column is the column string to be counted.
*@return the query chunk needed.
*/
+ @Override
public String constructCountClause(String column)
{
return "COUNT("+column+")";
@@ -886,6 +909,7 @@ public class DBInterfacePostgreSQL exten
*@param caseInsensitive is true of the regular expression match is to be
case insensitive.
*@return the query chunk needed, not padded with spaces on either side.
*/
+ @Override
public String constructRegexpClause(String column, String regularExpression,
boolean caseInsensitive)
{
return column + "~" + (caseInsensitive?"*":"") + regularExpression;
@@ -899,6 +923,7 @@ public class DBInterfacePostgreSQL exten
*@param caseInsensitive is true if the regular expression match is to be
case insensitive.
*@return the expression chunk needed, not padded with spaces on either side.
*/
+ @Override
public String constructSubstringClause(String column, String
regularExpression, boolean caseInsensitive)
{
StringBuilder sb = new StringBuilder();
@@ -923,6 +948,7 @@ public class DBInterfacePostgreSQL exten
*@param afterOrderBy is true if this offset/limit comes after an ORDER BY.
*@return the proper clause, with no padding spaces on either side.
*/
+ @Override
public String constructOffsetLimitClause(int offset, int limit, boolean
afterOrderBy)
{
StringBuilder sb = new StringBuilder();
@@ -951,6 +977,7 @@ public class DBInterfacePostgreSQL exten
*@param otherFields are the rest of the fields to return, keyed by the AS
name, value being the base query column value, e.g. "value AS key"
*@return a revised query that performs the necessary DISTINCT ON operation.
The list outputParameters will also be appropriately filled in.
*/
+ @Override
public String constructDistinctOnClause(List outputParameters, String
baseQuery, List baseParameters,
String[] distinctFields, String[] orderFields, boolean[]
orderFieldsAscending, Map<String,String> otherFields)
{
@@ -1014,6 +1041,7 @@ public class DBInterfacePostgreSQL exten
* to drop.
*@return the maximum number of IN clause members.
*/
+ @Override
public int getMaxInClause()
{
return 100;
@@ -1024,6 +1052,7 @@ public class DBInterfacePostgreSQL exten
* to drop.
*@return the maximum number of OR clause members.
*/
+ @Override
public int getMaxOrClause()
{
return 25;
@@ -1033,6 +1062,7 @@ public class DBInterfacePostgreSQL exten
* that can reasonably be expected to complete in an acceptable time.
*@return the maximum number of rows.
*/
+ @Override
public int getWindowedReportMaxRows()
{
return 5000;
@@ -1046,6 +1076,7 @@ public class DBInterfacePostgreSQL exten
* calls to executeQuery(). After this should be a catch for every exception
type, including Error, which should call the
* signalRollback() method, and rethrow the exception. Then, after that a
finally{} block which calls endTransaction().
*/
+ @Override
public void beginTransaction()
throws ManifoldCFException
{
@@ -1061,6 +1092,7 @@ public class DBInterfacePostgreSQL exten
* signalRollback() method, and rethrow the exception. Then, after that a
finally{} block which calls endTransaction().
*@param transactionType is the kind of transaction desired.
*/
+ @Override
public void beginTransaction(int transactionType)
throws ManifoldCFException
{
@@ -1106,6 +1138,7 @@ public class DBInterfacePostgreSQL exten
/** Signal that a rollback should occur on the next endTransaction().
*/
+ @Override
public void signalRollback()
{
if (serializableDepth == 0)
@@ -1115,6 +1148,7 @@ public class DBInterfacePostgreSQL exten
/** End a database transaction, either performing a commit or a rollback
(depending on whether
* signalRollback() was called within the transaction).
*/
+ @Override
public void endTransaction()
throws ManifoldCFException
{
@@ -1143,6 +1177,7 @@ public class DBInterfacePostgreSQL exten
}
/** Abstract method to start a transaction */
+ @Override
protected void startATransaction()
throws ManifoldCFException
{
@@ -1157,6 +1192,7 @@ public class DBInterfacePostgreSQL exten
}
/** Abstract method to commit a transaction */
+ @Override
protected void commitCurrentTransaction()
throws ManifoldCFException
{
@@ -1172,6 +1208,7 @@ public class DBInterfacePostgreSQL exten
}
/** Abstract method to roll back a transaction */
+ @Override
protected void rollbackCurrentTransaction()
throws ManifoldCFException
{
@@ -1186,10 +1223,14 @@ public class DBInterfacePostgreSQL exten
}
/** Abstract method for explaining a query */
+ @Override
protected void explainQuery(String query, List params)
throws ManifoldCFException
{
- IResultSet x = executeUncachedQuery("EXPLAIN "+query,params,true,
+ String queryType = "EXPLAIN ";
+ if ("SELECT".equalsIgnoreCase(query.substring(0,6)))
+ queryType += "ANALYZE ";
+ IResultSet x = executeUncachedQuery(queryType+query,params,true,
-1,null,null);
int k = 0;
while (k < x.getRowCount())