Here is my bench for large table scan if you want to try. Tell me if
you spot a mistake.

package org.h2.test.bench;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Test the table scan performance for a table that fit in memory.
 * Test also aggregation as it return the sum.
 */
public class BenchScanLarge implements Bench {
        private Database db;
        private int size;

        /**
         * Use a number not so small in order
         * to not fit in memory
         */
        public static int NUMBER_OF_FACTS = 10*1000*1000;

        public void init(Database db, int size) throws SQLException {
                this.db = db;
                this.size = Math.max(1, size/1000);

                db.start(this, "Init");
                db.openConnection();

                try{
                        db.update("CREATE TABLE FACTS_LARGE(ID INT NOT NULL 
PRIMARY KEY,
FACT1 DECIMAL(15,2), FACT2 DECIMAL(15,2))");

                        PreparedStatement prep;
                        db.setAutoCommit(false);
                        int commitEvery = 1000;
                        prep = db.prepare("INSERT INTO 
FACTS_LARGE(ID,FACT1,FACT2) VALUES
(?,?,?)");
                        for (int i = 0; i < NUMBER_OF_FACTS; i++) {
                                prep.setInt(1, i);
                                prep.setDouble(2, i);
                                prep.setDouble(3, i);
                                db.update(prep, "insertFacts");
                                if (i % commitEvery == 0) {
                                        db.commit();
                                }
                        }
                        db.commit();
                } catch(Exception e) {
                        // nothing to do, the table already exists, it's cool.
                }

                db.commit();
                db.closeConnection();
                db.end();

        }

        public void runTest() throws SQLException {

                db.start(this, "Scanning");
                db.openConnection();
                processQuery();
                db.closeConnection();
                db.end();

                db.openConnection();
                processQuery();
                db.logMemory(this, "Memory Usage");
                db.closeConnection();

        }

        private void processQuery() throws SQLException {
                PreparedStatement scan1 = db.prepare("SELECT SUM(FACT1) FROM
FACTS_LARGE");
                db.setAutoCommit(false);

                for (int i = 0; i < size; i++) {
                        db.queryReadResult(scan1);
                        db.commit();
                }

                scan1.close();
        }

        public String getName() {
                return "ScanLarge";
        }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to