@@ -33,7 +33,13 @@ public class AlterBenchmarkTest extends PLTestBase {
33
33
"year integer," +
34
34
"month integer);" ;
35
35
36
+ private static String selectSQL ;
37
+ private static String alterAdd ;
38
+ private static String alterDrop ;
39
+ private static String alterChangeInline ;
40
+ private static String alterChangeNotInline ;
36
41
42
+ private static enum DBMS {MySQL , Postgres , Peloton };
37
43
@ Rule
38
44
public ExpectedException thrown = ExpectedException .none ();
39
45
@@ -50,21 +56,53 @@ public static Connection makePostgresConnection(String host,
50
56
int port ,
51
57
String username ,
52
58
String pass ) throws SQLException {
53
- String url = String .format ("jdbc:postgresql://%s:%d/postgres" ,
54
- host , port );
59
+ String url = String .format ("jdbc:postgresql://%s:%d/postgres" , host , port );
60
+ Connection conn = DriverManager .getConnection (url , username , pass );
61
+ return conn ;
62
+ }
63
+
64
+ private static Connection makeMySQLConnection (String host ,
65
+ int port ,
66
+ String username ,
67
+ String pass ) throws SQLException {
68
+ String url = String .format ("jdbc:mysql://%s:%d/mysql" , host , port );
55
69
Connection conn = DriverManager .getConnection (url , username , pass );
56
70
return conn ;
57
71
}
58
72
59
73
/**
60
74
* Setup the connection to peloton or other DBMS
75
+ * If you want to run other
61
76
* @throws SQLException
62
77
*/
63
78
@ Before
64
79
public void Setup () throws SQLException {
65
- //connection to Postgres
66
- //conn = makePostgresConnection("localhost", 5432, "dingshilun", "");
67
- conn = makeDefaultConnection ();
80
+ DBMS testingDB = DBMS .Peloton ;
81
+ String userName = "" ;
82
+ String passWD = "" ;
83
+ switch (testingDB ){
84
+ case Peloton :
85
+ alterAdd = "alter table tbl add day integer;" ;
86
+ alterDrop = "alter table tbl drop month;" ;
87
+ alterChangeInline = "alter table tbl alter year type varchar" ;
88
+ alterChangeNotInline = "alter table tbl alter year type integer USING year::INTEGER" ;
89
+ conn = makeDefaultConnection ();
90
+ break ;
91
+ case Postgres :
92
+ alterAdd = "alter table tbl add day integer;" ;
93
+ alterDrop = "alter table tbl drop month;" ;
94
+ alterChangeInline = "alter table tbl alter year type varchar" ;
95
+ alterChangeNotInline = "alter table tbl alter year type integer USING year::INTEGER" ;
96
+ conn = makePostgresConnection ("localhost" , 5432 , userName , passWD );
97
+ break ;
98
+ case MySQL :
99
+ alterAdd = "alter table tbl add day integer;" ;
100
+ alterDrop = "alter table tbl drop month;" ;
101
+ alterChangeInline = "alter table tbl modify year type varchar" ;
102
+ alterChangeNotInline = "alter table tbl modify year type integer" ;
103
+ conn = makeMySQLConnection ("localhost" , 3306 , userName , passWD );
104
+ break ;
105
+ }
68
106
conn .setAutoCommit (true );
69
107
InitDatabase ();
70
108
}
@@ -82,6 +120,7 @@ public void Teardown() throws SQLException {
82
120
*/
83
121
@ Test
84
122
public void test_tuple_number_varies () throws SQLException {
123
+ //define tuple number
85
124
int [] workload = {};
86
125
for (int i = 0 ; i < workload .length ;i ++) {
87
126
// firstly use select * to make sure all tuples are in memory
@@ -96,29 +135,31 @@ public void test_tuple_number_varies() throws SQLException {
96
135
} catch (Exception e ) {
97
136
e .printStackTrace ();
98
137
}
99
-
100
- String alterSql1 = "alter table tbl add day integer;" ;
138
+
139
+ String alterSql1 = alterAdd ;
101
140
long startTime1 = System .currentTimeMillis ();
102
141
conn .createStatement ().execute (alterSql1 );
103
142
long endTime1 = System .currentTimeMillis ();
104
143
105
- String alterSql2 = "alter table tbl drop month;" ;
144
+ String alterSql2 = alterDrop ;
106
145
long startTime2 = System .currentTimeMillis ();
107
146
conn .createStatement ().execute (alterSql2 );
108
147
long endTime2 = System .currentTimeMillis ();
109
148
110
- String alterSql3 = "alter table tbl alter year type varchar" ;
149
+ String alterSql3 = alterChangeInline ;
111
150
long startTime3 = System .currentTimeMillis ();
112
151
conn .createStatement ().execute (alterSql3 );
113
152
long endTime3 = System .currentTimeMillis ();
114
153
115
- String alterSql4 = "alter table tbl alter year type integer USING year::INTEGER" ;
154
+ String alterSql4 = alterChangeNotInline ;
116
155
long startTime4 = System .currentTimeMillis ();
117
156
conn .createStatement ().execute (alterSql4 );
118
157
long endTime4 = System .currentTimeMillis ();
119
158
120
- System .out .println ("Alter add column " + workload [i ] + " tuples took: " + (endTime1 - startTime1 ) + " milliseconds" );
121
- System .out .println ("Alter drop column " + workload [i ] + " tuples took: " + (endTime2 - startTime2 ) + " milliseconds" );
159
+ System .out .println ("Alter add column " + workload [i ] + " tuples took: "
160
+ + (endTime1 - startTime1 ) + " milliseconds" );
161
+ System .out .println ("Alter drop column " + workload [i ] + " tuples took: "
162
+ + (endTime2 - startTime2 ) + " milliseconds" );
122
163
System .out .println ("Alter change type from inline to not inline " + workload [i ] + " tuples took: " +
123
164
(endTime3 - startTime3 ) + " milliseconds" );
124
165
System .out .println ("Alter change type from not inline to inline " + workload [i ] + " tuples took: " +
@@ -128,33 +169,30 @@ public void test_tuple_number_varies() throws SQLException {
128
169
}
129
170
130
171
private void NumVarInsertHelper (int insertNum ) throws SQLException {
131
- String sql = "INSERT INTO tbl VALUES (?, ?, ?);" ;
132
- PreparedStatement pstmt = conn .prepareStatement (sql );
172
+ String sql ;
133
173
for (int i = 0 ; i < insertNum ; i ++) {
134
- setValues ( pstmt , new int [] { i , i +1 , i +2 } );
135
- pstmt . addBatch ( );
174
+ sql = String . format ( "INSERT INTO tbl VALUES (%d, %d, %d);" , i , i +1 , i +2 );
175
+ conn . createStatement (). execute ( sql );
136
176
}
137
- pstmt .executeBatch ();
138
177
}
139
178
140
179
/**
141
- * Insert 10000 tuple, and test performance under different
142
- * length of the tuple
180
+ * Insert 'tupleNum' tuple, and test performance under different
181
+ * length of the tuple defined by workload{}
143
182
* @throws SQLException
144
183
*/
145
184
@ Test
146
185
public void test_tuple_length_variance () throws SQLException {
186
+ //define tuple length
147
187
int [] workload = {};
148
188
int tupleNum = 10000 ;
149
- String dropSQL = "DROP TABLE IF EXISTS tbl" ;
150
- String sql = "" ;
151
- conn .createStatement ().execute (dropSQL );
189
+ conn .createStatement ().execute (SQL_DROP_TABLE );
152
190
for (int i = 0 ; i < workload .length ; i ++) {
153
- sql = "CREATE TABLE tbl(id INTEGER PRIMARY KEY, " +
154
- "payload1 VARCHAR(" + workload [i ] + ")," +
155
- "payload2 VARCHAR(" + workload [i ] + ")," +
156
- "payload3 INTEGER);" ;
157
- conn .createStatement ().execute (sql );
191
+ String createSql = "CREATE TABLE tbl(id INTEGER PRIMARY KEY, " +
192
+ "month VARCHAR(" + workload [i ] + ")," +
193
+ "hour VARCHAR(" + workload [i ] + ")," +
194
+ "year INTEGER);" ;
195
+ conn .createStatement ().execute (createSql );
158
196
LengthVarInsertHelper (tupleNum , workload [i ]);
159
197
160
198
try {
@@ -164,25 +202,28 @@ public void test_tuple_length_variance() throws SQLException {
164
202
}
165
203
166
204
long startTime1 = System .currentTimeMillis ();
167
- conn .createStatement ().execute ("ALTER TABLE tbl add payload4 integer;" );
205
+ conn .createStatement ().execute (alterAdd );
168
206
long endTime1 = System .currentTimeMillis ();
169
207
170
208
long startTime2 = System .currentTimeMillis ();
171
- conn .createStatement ().execute ("ALTER TABLE tbl drop payload1;" );
209
+ conn .createStatement ().execute (alterDrop );
172
210
long endTime2 = System .currentTimeMillis ();
173
211
174
212
long startTime3 = System .currentTimeMillis ();
175
- conn .createStatement ().execute ("ALTER TABLE tbl alter payload3 type varchar;" );
213
+ conn .createStatement ().execute (alterChangeInline );
176
214
long endTime3 = System .currentTimeMillis ();
177
215
178
- System .out .println ("Alter add column " + workload [i ] + " length took: " + (endTime1 - startTime1 )
216
+ System .out .println ("Alter add column " + workload [i ] * 2 +
217
+ " length took: " + (endTime1 - startTime1 )
179
218
+ " milliseconds" );
180
- System .out .println ("Alter drop column " + workload [i ] + " length took: " + (endTime2 - startTime2 )
219
+ System .out .println ("Alter drop column " + workload [i ] * 2 +
220
+ " length took: " + (endTime2 - startTime2 )
181
221
+ " milliseconds" );
182
- System .out .println ("Alter change type from not inline to inline " + workload [i ] + " length took: " +
183
- (endTime3 - startTime3 ) + " milliseconds" );
222
+ System .out .println ("Alter change type from not inline to inline " + workload [i ] * 2
223
+ + " length took: " + (endTime3 - startTime3 ) +
224
+ " milliseconds" );
184
225
185
- conn .createStatement ().execute (dropSQL );
226
+ conn .createStatement ().execute (SQL_DROP_TABLE );
186
227
}
187
228
}
188
229
0 commit comments