⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcachesize.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) 2001-2005, The HSQL Development Group * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the HSQL Development Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.hsqldb.test;import java.io.FileWriter;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Random;import org.hsqldb.lib.FileUtil;import org.hsqldb.lib.StopWatch;import org.hsqldb.persist.HsqlProperties;/** * Test large cached tables by setting up a cached table of 100000 records * or more and a much smaller memory table with about 1/100th rows used. * Populate both tables so that an indexed column of the cached table has a * foreign key reference to the main table. * * This database can be used to demonstrate efficient queries to retrieve * the data from the cached table. * * 1.7.1 insert timings for 100000 rows, cache scale 12: * simple table, no extra index: 52 s * with index on lastname only: 56 s * with index on zip only: 211 s * foreign key, referential_integrity true: 216 s * * The above have improved a lot in 1.7.2 * * This test now incorporates the defunct TestTextTables * * @author fredt@users * @version 1.8.0 * @since 1.7.0 */public class TestCacheSize {    // program can edit the *.properties file to set cache_size, old files are deleted    protected boolean filedb = true;    // shutdown performed mid operation - not for mem: or hsql: URL's    protected boolean shutdown = true;    // fixed    protected String url = "jdbc:hsqldb:";//    protected String  filepath = "hsql://localhost/mytest";//    protected String filepath = "mem:test";    protected String filepath = "/hsql/testcache/test";    // frequent reporting of progress    boolean reportProgress = false;    // type of the big table {MEMORY | CACHED | TEXT | ""}    String  tableType      = "CACHED";    int     cacheScale     = 12;    int     cacheSizeScale = 10;    boolean nioMode        = false;    // script format {TEXT | BINARY | COMPRESSED}    String  logType       = "TEXT";    int     writeDelay    = 60;    boolean indexZip      = false;    boolean indexLastName = false;    boolean addForeignKey = false;    boolean refIntegrity  = true;    // may speed up inserts when tableType=="CACHED"    boolean createTempTable = false;    // introduces fragmentation to the .data file during insert    boolean deleteWhileInsert         = false;    int     deleteWhileInsertInterval = 10000;    // size of the tables used in test    int bigrows = 16000;    // number of ops    int bigops    = 16000;    int smallops  = 8000;    int smallrows = 0xfff;    // if the extra table needs to be created and filled up    boolean multikeytable = false;    //    String     user;    String     password;    Statement  sStatement;    Connection cConnection;    FileWriter writer;    private void checkSelects() {        countTestID();        selectID();        selectZipTable();    }    private void checkUpdates() {        updateIDLinear();        updateID();        countTestID();        deleteTest();        countTestID();        countZip();    }    protected void setUp() {        try {            writer = new FileWriter("speedtests.html", true);            writer.write("<table>\n");            storeResult(new java.util.Date().toString(), 0, 0, 0);            storeResult(filepath + " " + tableType + " " + nioMode,                        cacheScale, 0, 0);        } catch (Exception e) {}        user     = "sa";        password = "";        try {            sStatement  = null;            cConnection = null;            Class.forName("org.hsqldb.jdbcDriver");            if (filedb) {                deleteDatabase(filepath);                cConnection = DriverManager.getConnection(url + filepath,                        user, password);                sStatement = cConnection.createStatement();                sStatement.execute("SET WRITE_DELAY " + 10);                sStatement.execute("SET CHECKPOINT DEFRAG " + 10);                sStatement.execute("SET SCRIPTFORMAT " + logType);                sStatement.execute("SET LOGSIZE " + 6);                sStatement.execute("SET PROPERTY \"hsqldb.cache_scale\" "                                   + cacheScale);                sStatement.execute("SET PROPERTY \"hsqldb.cache_size_scale\" "                                   + cacheSizeScale);                sStatement.execute("SET PROPERTY \"hsqldb.nio_data_file\" "                                   + nioMode);                sStatement.execute("SHUTDOWN");                cConnection.close();            }        } catch (Exception e) {            e.printStackTrace();            System.out.println("TestSql.setUp() error: " + e.getMessage());        }    }    /**     * Fill up the cache     *     *     */    public void testFillUp() {        StopWatch sw    = new StopWatch();        String    ddl1  = "DROP TABLE test IF EXISTS";        String    ddl11 = "DROP TABLE zip IF EXISTS";        String    ddl2  = "CREATE TABLE zip( zip INT IDENTITY )";        String ddl3 = "CREATE " + tableType + " TABLE test( id INT IDENTITY,"                      + " firstname VARCHAR(20), "                      + " lastname VARCHAR(20), " + " zip INTEGER, "                      + " filler VARCHAR(300))";        String ddl31 = "SET TABLE test SOURCE \"test.csv;cache_scale="                       + cacheScale + "\"";        // adding extra index will slow down inserts a bit        String ddl4 = "CREATE INDEX idx1 ON TEST (lastname)";        // adding this index will slow down  inserts a lot        String ddl5 = "CREATE INDEX idx2 ON TEST (zip)";        // referential integrity checks will slow down inserts a bit        String ddl6 =            "ALTER TABLE test add constraint c1 FOREIGN KEY (zip) REFERENCES zip(zip) ON DELETE CASCADE;";        String ddl7 = "CREATE TEMP TABLE temptest( id INT,"                      + " firstname VARCHAR, " + " lastname VARCHAR, "                      + " zip INTEGER, " + " filler VARCHAR)";        String filler =            "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"            + "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";        String mddl1 = "DROP TABLE test2 IF EXISTS";        String mddl2 = "CREATE " + tableType                       + " TABLE test2( id1 INT, id2 INT,"                       + " firstname VARCHAR, " + " lastname VARCHAR, "                       + " zip INTEGER, " + " filler VARCHAR, "                       + " PRIMARY KEY (id1,id2) )";        String mdd13 = "SET TABLE test2 SOURCE \"test2.csv;cache_scale="                       + cacheScale + "\"";        try {//            System.out.println("Connecting");            sw.zero();            cConnection = null;            sStatement  = null;            cConnection = DriverManager.getConnection(url + filepath, user,                    password);            System.out.println("connection time -- " + sw.elapsedTime());            sw.zero();            sStatement = cConnection.createStatement();            java.util.Random randomgen = new java.util.Random();//            sStatement.execute("SET WRITE_DELAY " + writeDelay);            sStatement.execute(ddl1);            sStatement.execute(ddl2);            sStatement.execute(ddl3);            if (tableType.equals("TEXT")) {                sStatement.execute(ddl31);            }//            System.out.println("test table with no index");            if (indexLastName) {                sStatement.execute(ddl4);                System.out.println("created index on lastname");            }            if (indexZip) {                sStatement.execute(ddl5);                System.out.println("created index on zip");            }            if (addForeignKey) {                sStatement.execute(ddl6);                System.out.println("added foreign key");            }            if (createTempTable) {                sStatement.execute(ddl7);                System.out.println("created temp table");            }            if (multikeytable) {                sStatement.execute(mddl1);                sStatement.execute(mddl2);                if (tableType.equals("TEXT")) {                    sStatement.execute(mdd13);                }                System.out.println("created multi key table");            }//            sStatement.execute("CREATE INDEX idx3 ON tempTEST (zip);");            System.out.println("complete setup time -- " + sw.elapsedTime()                               + " ms");            fillUpBigTable(filler, randomgen);            if (multikeytable) {                fillUpMultiTable(filler, randomgen);            }            sw.zero();            if (shutdown) {                sStatement.execute("SHUTDOWN");                long time = sw.elapsedTime();                storeResult("shutdown", 0, time, 0);                System.out.println("shutdown time  -- " + time + " ms");            }            cConnection.close();        } catch (SQLException e) {            System.out.println(e.getMessage());        }    }    private void fillUpBigTable(String filler,                                Random randomgen) throws SQLException {        StopWatch sw = new StopWatch();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -