From derby-commits-return-1938-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Tue Dec 13 21:06:54 2005 Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 93454 invoked from network); 13 Dec 2005 21:06:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Dec 2005 21:06:54 -0000 Received: (qmail 60537 invoked by uid 500); 13 Dec 2005 21:06:53 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 60514 invoked by uid 500); 13 Dec 2005 21:06:52 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 60503 invoked by uid 99); 13 Dec 2005 21:06:52 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Dec 2005 13:06:52 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 13 Dec 2005 13:06:51 -0800 Received: (qmail 92791 invoked by uid 65534); 13 Dec 2005 21:06:21 -0000 Message-ID: <20051213210621.92790.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r356621 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ParameterNode.java engine/org/apache/derby/impl/sql/execute/BaseActivation.java testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java Date: Tue, 13 Dec 2005 21:06:20 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: kmarsden Date: Tue Dec 13 13:06:11 2005 New Revision: 356621 URL: http://svn.apache.org/viewcvs?rev=356621&view=rev Log: DERBY-739 Reduce generated code required to access a parameter's value Adds a new getParameter(position) method to BaseActivation and calls this.getParameter(position) instead of this.pvs.getParameter(position). This saves some generated byte code and increases the number of parameters in an IN predicate from 2700 to 3400 for an otherwise simple statement. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java?rev=356621&r1=356620&r2=356621&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ParameterNode.java Tue Dec 13 13:06:11 2005 @@ -20,43 +20,22 @@ package org.apache.derby.impl.sql.compile; -import org.apache.derby.iapi.sql.compile.CompilerContext; - -import org.apache.derby.iapi.types.JSQLType; - -import org.apache.derby.iapi.types.TypeId; - -import org.apache.derby.iapi.types.DataTypeDescriptor; -import org.apache.derby.iapi.types.DataValueDescriptor; - -import org.apache.derby.iapi.sql.dictionary.DataDictionary; - -import org.apache.derby.iapi.sql.execute.ExecutionFactory; +import java.sql.Types; +import java.util.Enumeration; +import java.util.Vector; import org.apache.derby.iapi.error.StandardException; - -import org.apache.derby.iapi.services.compiler.MethodBuilder; - -import org.apache.derby.iapi.sql.LanguageFactory; -import org.apache.derby.iapi.sql.ParameterValueSet; -import org.apache.derby.iapi.sql.Activation; import org.apache.derby.iapi.reference.ClassName; import org.apache.derby.iapi.reference.SQLState; - -import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; - +import org.apache.derby.iapi.services.classfile.VMOpcode; +import org.apache.derby.iapi.services.compiler.MethodBuilder; import org.apache.derby.iapi.services.sanity.SanityManager; - +import org.apache.derby.iapi.sql.compile.CompilerContext; import org.apache.derby.iapi.store.access.Qualifier; - -import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; -import org.apache.derby.impl.sql.execute.BaseActivation; -import org.apache.derby.iapi.services.classfile.VMOpcode; - -import java.sql.Types; - -import java.util.Enumeration; -import java.util.Vector; +import org.apache.derby.iapi.types.DataTypeDescriptor; +import org.apache.derby.iapi.types.DataValueDescriptor; +import org.apache.derby.iapi.types.JSQLType; +import org.apache.derby.iapi.types.TypeId; /** * This node type represents a ? parameter. @@ -384,12 +363,10 @@ /* Generate the return value */ - /* First, get the field that holds the ParameterValueSet */ - acb.pushPVSReference(mb); - + mb.pushThis(); mb.push(parameterNumber); // arg - mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getParameter", + mb.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, "getParameter", ClassName.DataValueDescriptor, 1); // For some types perform host variable checking Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java?rev=356621&r1=356620&r2=356621&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java Tue Dec 13 13:06:11 2005 @@ -1222,7 +1222,18 @@ lcc.getLanguageConnectionFactory().getClassFactory().getClassInspector(), paramCount, hasReturnParam); } - + + /** + * This method can help reduce the amount of generated code by changing + * instances of this.pvs.getParameter(position) to this.getParameter(position) + * @param position + * @return + * @throws StandardException + */ + protected final DataValueDescriptor getParameter(int position) throws StandardException { + return pvs.getParameter(position); + } + /** return the parameters. */ Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java?rev=356621&r1=356620&r2=356621&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java Tue Dec 13 13:06:11 2005 @@ -16,7 +16,7 @@ public class largeCodeGen { - + private static boolean TEST_QUERY_EXECUTION = true; public static void main(String argv[]) throws Exception @@ -25,7 +25,7 @@ Connection con = ij.startJBMS(); con.setAutoCommit(false); createTestTable(con); - testParamsInWhereClause(con); + testLogicalOperators(con); testInClause(con); testUnions(con); con.commit(); @@ -51,19 +51,62 @@ stmt.executeUpdate("insert into t0 values(2,3,4,5.3,5.3,5.3,31.13,123456.123, 'one','one','one')"); } - /** + + /** + * Prepares and executes query against table t0 with n parameters + * The assumption is that the query will always return our one row + * of data inserted into the t0 table. + * + * @param con + * @param testName + * @param sqlBuffer - StringBuffer with SQL Text + * @param numParams - Number of parameters + * @param paramValue - Parameter value + * @return true if the check fails + */ + private static boolean checkT0Query(Connection con, String testName, + StringBuffer sqlBuffer, int numParams, int paramValue) { + PreparedStatement ps; + try { + ps = con.prepareStatement(sqlBuffer.toString()); + + if (TEST_QUERY_EXECUTION) + { + for (int i = 1; i <= numParams; i++) + { + ps.setInt(i, paramValue); + } + ResultSet rs = ps.executeQuery(); + rs.next(); + checkRowData(rs); + rs.close(); + } + ps.close(); + System.out.println("PASS: " + testName); + return false; + }catch (Exception e) + { + reportFailure(testName, e); + return true; + + } + } + + /** * Test many parameters in the where clause * e.g. * @param con */ - private static void testParamsInWhereClause(Connection con) throws SQLException { + private static void testLogicalOperators(Connection con) throws SQLException { for (int count = 200; count <= 10000 ; count += 100) { - // keep testing until it fails. - if (testWhereParams(con, count)) + // keep testing until it fails with linkage error + if (testLogicalOperators(con, count)) break; } + // 10,000 causes Stack overflow and database corruption + //testLogicalOperators(con, 10000); } @@ -71,74 +114,63 @@ * Tests numParam parameter markers in a where clause * * @param con - * @param numparams + * @param numOperands */ - private static boolean testWhereParams(Connection con, int numParams) throws SQLException { - String pred = "(si = ? AND i = ? )"; - String testName = "WHERE clause with " + numParams + " parameters"; - StringBuffer sqlBuffer = new StringBuffer((numParams * 20) + 512); - sqlBuffer.append("DELETE FROM T0 WHERE " + pred ); - for (int i = 2; i < numParams; i+=2) - { - sqlBuffer.append(" OR (si = ? AND i = ? ) "); - } - try { - PreparedStatement ps = con.prepareStatement(sqlBuffer.toString()); - System.out.println("PASS: " + testName); - ps.close(); - return false; - - }catch (Exception e) + private static boolean testLogicalOperators(Connection con, + int numOperands) throws SQLException { + + // First with parameters + String pred = "(si = ? AND si = ? )"; + String testName = "Logical operators with " + numOperands + " parameters"; + StringBuffer sqlBuffer = new StringBuffer((numOperands * 20) + 512); + sqlBuffer.append("SELECT * FROM T0 WHERE " + pred ); + for (int i = 2; i < numOperands; i+=2) { - reportFailure(testName, e); - return true; - + sqlBuffer.append(" OR " + pred); } + return checkT0Query(con, testName, sqlBuffer, numOperands, 2); + + + + } + private static void testInClause(Connection con) throws SQLException { - for (int count = 2500; count <= 10000 ; count += 100) + + // DERBY-739 raised number of parameters from 2700 to 3400 + for (int count = 3300; count <= 10000 ; count += 100) { // keep testing until it fails. if (testInClause(con, count)) - break; + break; } } + + /** + * Test in clause with many parameters + * + * @param con + * @param numParams - Number of parameters to test + * @return true if the test fails + * @throws SQLException + */ private static boolean testInClause(Connection con, int numParams) throws SQLException { String testName = "IN clause with " + numParams + " parameters"; StringBuffer sqlBuffer = new StringBuffer((numParams * 20) + 512); - sqlBuffer.append("SELECT * FROM T0 WHERE I IN (" ); + sqlBuffer.append("SELECT * FROM T0 WHERE SI IN (" ); for (int i = 1; i < numParams; i++) { sqlBuffer.append("?, "); } sqlBuffer.append("?)"); - try { - PreparedStatement ps = con.prepareStatement(sqlBuffer.toString()); - System.out.println("PASS: " + testName); - ps.close(); - return false; - - }catch (Exception e) - { - reportFailure(testName, e); - return true; - - } + return checkT0Query(con, testName, sqlBuffer, numParams, 2); } + private static void testUnions(Connection con) throws Exception { Statement stmt = null; PreparedStatement pstmt = null; createTestTable(con); - //int numUnions = 4000; - //int numUnions = 2000; - /* - We still have problems with large queries. - Passes at 4000. - With size 5000 it gets "java.lang.VerifyError: - (class: db2j/exe/ac601a400fx0102xc673xe3e9x000000163ac04, method: - execute signature: ()Lcom/ibm/db2j/protocol/Database/Language/Interface/ResultSet;) Illegal target of jump or branch". My fix affects generated method "fillResultSet". With size 10000 largeCodeGen gets Java exception: 'java.io.IOException: constant_pool(70796 > 65535)'. - */ String viewName = "v0"; stmt = con.createStatement(); @@ -162,8 +194,6 @@ //System.out.println(createViewString); stmt.executeUpdate(createView.toString()); - // 2000 unions caused method too big error in verifier - // 10000 unions overflows the number of constant pool entries for (int count = 800; count <= 10000; count += 100) { @@ -171,6 +201,8 @@ if (largeUnionSelect(con, viewName, count)) break; } + // 10000 gives a different constant pool error + largeUnionSelect(con, viewName, 10000); } private static boolean largeUnionSelect(Connection con, String viewName,