From f5c7c0fe099bafc81bf8d2d4d4529c605a2c8682 Mon Sep 17 00:00:00 2001 From: phib Date: Thu, 19 Nov 2009 22:13:57 +0000 Subject: [PATCH] 2900767 Zoom to child tab - inefficient queries https://sourceforge.net/tracker/?func=detail&aid=2900767&group_id=176962&atid=879332 --- base/src/org/compiere/model/GridTab.java | 12 ++++++++---- base/src/org/compiere/util/DB.java | 8 +++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/base/src/org/compiere/model/GridTab.java b/base/src/org/compiere/model/GridTab.java index 1b9574a9e7..09013eafbc 100644 --- a/base/src/org/compiere/model/GridTab.java +++ b/base/src/org/compiere/model/GridTab.java @@ -87,6 +87,8 @@ import org.compiere.util.ValueNamePair; * @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1877902&group_id=176962 to FR [1877902] * @author Cristina Ghita, www.arhipac.ro FR [2870645] Set null value for an ID * @see https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2870645&group_id=176962 + * @author Paul Bowden, phib BF 2900767 Zoom to child tab - inefficient queries + * @see https://sourceforge.net/tracker/?func=detail&aid=2900767&group_id=176962&atid=879332 */ public class GridTab implements DataStatusListener, Evaluatee, Serializable { @@ -741,7 +743,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable return query.getWhereClause(); } - // Find Refernce Column e.g. BillTo_ID -> C_BPartner_Location_ID + // Find Reference Column e.g. BillTo_ID -> C_BPartner_Location_ID String sql = "SELECT cc.ColumnName " + "FROM AD_Column c" + " INNER JOIN AD_Ref_Table r ON (c.AD_Reference_Value_ID=r.AD_Reference_ID)" @@ -823,11 +825,13 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable } query.setTableName("xx"); - StringBuffer result = new StringBuffer ("EXISTS (SELECT * FROM ") + // use IN instead of EXISTS as subquery should be highly selective + StringBuffer result = new StringBuffer (getTableName()).append(".").append(tabKeyColumn) + .append(" IN (SELECT xx.").append(tabKeyColumn) + .append(" FROM ") .append(tableName).append(" xx WHERE ") .append(query.getWhereClause(true)) - .append(" AND xx.").append(tabKeyColumn).append("=") - .append(getTableName()).append(".").append(tabKeyColumn).append(")"); + .append(")"); log.fine(result.toString()); return result.toString(); } // validateQuery diff --git a/base/src/org/compiere/util/DB.java b/base/src/org/compiere/util/DB.java index 15ef016092..491819fa79 100644 --- a/base/src/org/compiere/util/DB.java +++ b/base/src/org/compiere/util/DB.java @@ -85,6 +85,8 @@ import org.compiere.process.SequenceCheck; * https://sourceforge.net/tracker/?func=detail&aid=2873324&group_id=176962&atid=879332 *
  • FR [ 2873891 ] DB.getKeyNamePairs should use trxName * https://sourceforge.net/tracker/?func=detail&aid=2873891&group_id=176962&atid=879335 + * @author Paul Bowden, phib BF 2900767 Zoom to child tab - inefficient queries + * @see https://sourceforge.net/tracker/?func=detail&aid=2900767&group_id=176962&atid=879332 */ public final class DB { @@ -1676,10 +1678,10 @@ public final class DB if (TableName.endsWith("Line")) { String hdr = TableName.substring(0, TableName.indexOf("Line")); + // use IN instead of EXISTS as the subquery should be highly selective sql = "SELECT IsSOTrx FROM " + hdr - + " h WHERE EXISTS (SELECT * FROM " + TableName - + " l WHERE h." + hdr + "_ID=l." + hdr + "_ID AND " - + whereClause + ")"; + + " h WHERE h." + hdr + "_ID IN (SELECT l." + hdr + "_ID FROM " + TableName + + " l WHERE " + whereClause + ")"; PreparedStatement pstmt2 = null; ResultSet rs2 = null; try