public class GroupByClient extends java.lang.Object implements Client
ONEKTUP
tables generated by WisconsinFiller
.
Based on the parameters specified when run, we perform a particular
GROUP BY statement, and fetch and check the number of rows returned,
as part of a performance run controlled by perf.clients.Runner.
For example, you could cause this benchmark's GROUP BY to be:
- one which returns 10 groups, with 1000 rows in each group, or
- one which returns 100 groups, with 100 rows in each group, or
- one which returns 1000 groups, with 10 rows in each group, etc.
With correspondingly larger numbers of groups as the scale factor grows.
You can use more rows by passing '-load_opts numRows=100000', e.g. Note that
this only has an effect when you run -init. Note that changing the number
of rows in the table also changes the expected size of each group; we issue
a select count(*) query at the start to figure out the expected group size,
but this hack only works with table sizes that are multiples of 1000.
If you use a substantially larger number of rows (say, 100000 or more), you
should specify '-rt 300' or higher so that a valid number of executions
can occur, as the benchmark starts to slow down dramatically with large
numbers of rows.
To prepare the database for this little benchmark:
java org.apache.derbyTesting.perf.clients.Runner -init -load group_by
-load_opts numRows=NNNNNN (if you want more than 10,000 rows in DB)
(this will also run the default GROUP BY, which is GROUP BY TEN)
On subsequent runs you can skip the '-init', and should instead specify
a particular GROUP BY to run, which you do by specifying:
- the number of GROUP_BY columns (-load_opts numGroupingCols=N), and
- the number of groups for each column (-load_opts numGroupsK=NNNN)
(NOTE: we count from 1, not from 0, with these parameters!)
I've tried this benchmark up to 5 grouping columns, which seemed like
plenty for the benchmarking I wanted to do. The code supports more, but
I'm not sure if it works or not.
For example, this runs a 2-column group by:
-load group_by -load_opts numGroupingCols=2,numGroups1=10,numGroups2=100
The resulting SQL will be:
SELECT TEN, ONEPERCENT, COUNT(*) FROM TENKTUP1 GROUP BY TEN,ONEPERCENT
Note that due to the way that the data in the TEN and ONEPERCENT columns
are loaded, they are not independent, so this actually produces 100 groups.
If numGroupingCols == 1, and thus the code can predict the number of
rows that ought to be in each group, and the total number of groups, then
it checks those values in the result as well.Modifier and Type | Field and Description |
---|---|
private java.sql.Connection |
conn |
private java.lang.String[] |
groupingExpr |
private static int |
MAX_GROUPING_COLS |
private int |
numGroupingCols |
private int[] |
numGroups |
private java.sql.PreparedStatement |
ps |
private java.lang.String |
sql |
private int |
tableSize |
private int |
totalExpectedGroups |
Constructor and Description |
---|
GroupByClient() |
Modifier and Type | Method and Description |
---|---|
private void |
appendGroups(java.lang.StringBuffer buf) |
private java.lang.String |
buildStatement() |
void |
doWork()
Perform the work for a single iteration of the test (typically a single
transaction).
|
private void |
dumpTables() |
private void |
getGroupingExpr(int i) |
private void |
getTableSize() |
void |
init(java.sql.Connection c)
Initialize this client (typically prepare the statements needed in the
doWork() method). |
void |
printReport(java.io.PrintStream out)
Print a report from the test run.
|
private static final int MAX_GROUPING_COLS
private java.sql.Connection conn
private java.sql.PreparedStatement ps
private int numGroupingCols
private int[] numGroups
private java.lang.String[] groupingExpr
private int totalExpectedGroups
private int tableSize
private java.lang.String sql
public void init(java.sql.Connection c) throws java.sql.SQLException
Client
doWork()
method).private void getGroupingExpr(int i)
private java.lang.String buildStatement()
private void appendGroups(java.lang.StringBuffer buf)
private void dumpTables() throws java.sql.SQLException
java.sql.SQLException
private void getTableSize() throws java.sql.SQLException
java.sql.SQLException
public void doWork() throws java.sql.SQLException
Client
public void printReport(java.io.PrintStream out)
Client
printReport
in interface Client
out
- stream to print the report toApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.