Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

[15721] Schema Change Final PR #1366

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
238f5f3
add alter table catalog
DeanChensj Apr 2, 2018
0f883a3
add change column catalog
DeanChensj Apr 5, 2018
2a7421b
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
9478c11
This commit added parser support of alter table
Dingshilun Apr 5, 2018
45793c9
add rename column executor
sxzh93 Apr 7, 2018
c0bf622
Catalog for change column name
DeanChensj Apr 6, 2018
dc8fdef
resolve comments, add header, TODO, remove context in subclass
sxzh93 Apr 8, 2018
f99d74a
fix
sxzh93 Apr 8, 2018
93b4883
add alter table catalog
DeanChensj Apr 2, 2018
6d52944
add change column catalog
DeanChensj Apr 5, 2018
ec89247
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
a9f476d
This commit added parser support of alter table
Dingshilun Apr 5, 2018
5c05dfc
add rename column executor
sxzh93 Apr 7, 2018
d21d3ec
Catalog for change column name
DeanChensj Apr 6, 2018
7af2df1
resolve comments, add header, TODO, remove context in subclass
sxzh93 Apr 8, 2018
ed0f25f
fix
sxzh93 Apr 8, 2018
9a1f61f
AlterTable init test
DeanChensj Apr 8, 2018
35168ee
added headers, comments and TODO
Dingshilun Apr 10, 2018
f098817
remove comments
DeanChensj Apr 11, 2018
636abfd
add alter table catalog
DeanChensj Apr 2, 2018
694582c
add change column catalog
DeanChensj Apr 5, 2018
1ec004e
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
c339c95
add rename column executor
sxzh93 Apr 7, 2018
e234829
Catalog for change column name
DeanChensj Apr 6, 2018
29d35a9
fix
sxzh93 Apr 8, 2018
d81697c
add alter table catalog
DeanChensj Apr 2, 2018
d122913
add change column catalog
DeanChensj Apr 5, 2018
34f3c05
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
17f7b80
add rename column executor
sxzh93 Apr 7, 2018
a495aa7
Catalog for change column name
DeanChensj Apr 6, 2018
b8f53b2
fix
sxzh93 Apr 8, 2018
3cf47dc
Add transactional test
DeanChensj Apr 12, 2018
cc5c6ab
Fix mac compile error
DeanChensj Apr 28, 2018
3a95bc1
Addressed comments in test and catalog
DeanChensj Apr 28, 2018
828f2c0
add rename column executor
sxzh93 Apr 7, 2018
a50f7b2
fix
sxzh93 Apr 8, 2018
fd7531d
This commit added parser support of alter table
Dingshilun Apr 5, 2018
76ea89e
added alter table drop column parser, planner, and catalog support, w…
Dingshilun Apr 16, 2018
7d6fa8a
add drop column executor
sxzh93 Apr 16, 2018
2462059
refacted the rename into alter (parser, planner)
Dingshilun Apr 28, 2018
27483c1
added parser support for change column type and add column
Dingshilun Apr 29, 2018
6584cdb
new implement of rename
DeanChensj Apr 29, 2018
1f2c1c0
alter table in catalog
DeanChensj Apr 30, 2018
900502d
added change type into alter tabe
Dingshilun May 3, 2018
c327fb6
add alter executor
sxzh93 May 1, 2018
2ea140e
resolve pr comments
sxzh93 May 3, 2018
56a2e44
modified alter plan, fixed bugs
Dingshilun May 3, 2018
6d1961c
added change type, changed logic in alter_executor, varchar still not…
Dingshilun May 3, 2018
764fcfb
addressed comments and fix varchar
DeanChensj May 4, 2018
4924383
basic test for alterTable
DeanChensj May 4, 2018
02b0fdc
add alter table tests, change unsupported type, multiple operation in…
sxzh93 May 4, 2018
a08410d
added alter varchar length support, changed the plan to use schema
Dingshilun May 5, 2018
d20a924
addressed the modification from cmu-db master
Dingshilun May 5, 2018
f8b10a5
change type quick fix
DeanChensj May 13, 2018
8a51c36
add gc logic
DeanChensj May 13, 2018
470323a
added alter benchmark, leave all workload of benchmark to be empty
Dingshilun May 14, 2018
6c986fd
Fix auto-merge conflict
DeanChensj May 14, 2018
9001841
Addressed commments from index team
DeanChensj May 14, 2018
3953b2f
modified AlterBenchmarkTest to support multiple SQL
Dingshilun May 14, 2018
8febb24
comment out concurrent test
DeanChensj May 15, 2018
19eac34
refactored plan and statement using std::string
sxzh93 May 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 252 additions & 0 deletions script/testing/junit/AlterBenchmarkTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// AlterBenchmarkTest.java
//
// Identification: script/testing/junit/AlterBenchmarkTest.java
//
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

import java.sql.*;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.postgresql.util.PSQLException;
import static org.junit.Assert.assertEquals;

/*
* Test case that compare performance under different workload
* Will need to contact with different local SQL
*/
public class AlterBenchmarkTest extends PLTestBase {
private Connection conn;
private Connection conn2;

private static final String SQL_DROP_TABLE =
"DROP TABLE IF EXISTS tbl;";

private static final String SQL_CREATE_TABLE =
"CREATE TABLE tbl (" +
"id integer, " +
"year integer," +
"month integer);";

private static String selectSQL;
private static String alterAdd;
private static String alterDrop;
private static String alterChangeInline;
private static String alterChangeNotInline;

private static enum DBMS {MySQL, Postgres, Peloton};
@Rule
public ExpectedException thrown = ExpectedException.none();

/**
* Initialize the database and table for testing
*/
private void InitDatabase() throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute(SQL_DROP_TABLE);
stmt.execute(SQL_CREATE_TABLE);
}

public static Connection makePostgresConnection(String host,
int port,
String username,
String pass) throws SQLException {
String url = String.format("jdbc:postgresql://%s:%d/postgres", host, port);
Connection conn = DriverManager.getConnection(url, username, pass);
return conn;
}

private static Connection makeMySQLConnection(String host,
int port,
String username,
String pass) throws SQLException {
String url = String.format("jdbc:mysql://%s:%d/mysql", host, port);
Connection conn = DriverManager.getConnection(url, username, pass);
return conn;
}

/**
* Setup the connection to peloton or other DBMS
* If you want to run other
* @throws SQLException
*/
@Before
public void Setup() throws SQLException {
DBMS testingDB = DBMS.Peloton;
String userName = "";
String passWD = "";
switch (testingDB){
case Peloton:
alterAdd = "alter table tbl add day integer;";
alterDrop = "alter table tbl drop month;";
alterChangeInline = "alter table tbl alter year type varchar";
alterChangeNotInline = "alter table tbl alter year type integer USING year::INTEGER";
conn = makeDefaultConnection();
break;
case Postgres:
alterAdd = "alter table tbl add day integer;";
alterDrop = "alter table tbl drop month;";
alterChangeInline = "alter table tbl alter year type varchar";
alterChangeNotInline = "alter table tbl alter year type integer USING year::INTEGER";
conn = makePostgresConnection("localhost", 5432, userName, passWD);
break;
case MySQL:
alterAdd = "alter table tbl add day integer;";
alterDrop = "alter table tbl drop month;";
alterChangeInline = "alter table tbl modify year type varchar";
alterChangeNotInline = "alter table tbl modify year type integer";
conn = makeMySQLConnection("localhost", 3306, userName, passWD);
break;
}
conn.setAutoCommit(true);
InitDatabase();
}

@After
public void Teardown() throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute(SQL_DROP_TABLE);
}

/**
* Insert workload{} tuples into the table
* In order to test performancce variance under different workload
* @throws SQLException
*/
@Test
public void test_tuple_number_varies() throws SQLException {
//define tuple number
int[] workload = {};
for (int i = 0; i< workload.length;i++) {
// firstly use select * to make sure all tuples are in memory
// for postgres and other disk based DBMS
InitDatabase();
NumVarInsertHelper(workload[i]);
String sql = "select * from tbl;";
conn.createStatement().execute(sql);

try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}

String alterSql1 = alterAdd;
long startTime1 = System.currentTimeMillis();
conn.createStatement().execute(alterSql1);
long endTime1 = System.currentTimeMillis();

String alterSql2 = alterDrop;
long startTime2 = System.currentTimeMillis();
conn.createStatement().execute(alterSql2);
long endTime2 = System.currentTimeMillis();

String alterSql3 = alterChangeInline;
long startTime3 = System.currentTimeMillis();
conn.createStatement().execute(alterSql3);
long endTime3 = System.currentTimeMillis();

String alterSql4 = alterChangeNotInline;
long startTime4 = System.currentTimeMillis();
conn.createStatement().execute(alterSql4);
long endTime4 = System.currentTimeMillis();

System.out.println("Alter add column " + workload[i] + " tuples took: "
+ (endTime1 - startTime1) + " milliseconds");
System.out.println("Alter drop column " + workload[i] + " tuples took: "
+ (endTime2 - startTime2) + " milliseconds");
System.out.println("Alter change type from inline to not inline " + workload[i] + " tuples took: " +
(endTime3 - startTime3) + " milliseconds");
System.out.println("Alter change type from not inline to inline " + workload[i] + " tuples took: " +
(endTime4 - startTime4) + " milliseconds");

}
}

private void NumVarInsertHelper(int insertNum) throws SQLException {
String sql;
for (int i = 0; i < insertNum; i++) {
sql = String.format("INSERT INTO tbl VALUES (%d, %d, %d);", i, i+1, i+2);
conn.createStatement().execute(sql);
}
}

/**
* Insert 'tupleNum' tuple, and test performance under different
* length of the tuple defined by workload{}
* @throws SQLException
*/
@Test
public void test_tuple_length_variance() throws SQLException {
//define tuple length
int[] workload = {};
int tupleNum = 10000;
conn.createStatement().execute(SQL_DROP_TABLE);
for (int i = 0; i < workload.length; i++) {
String createSql = "CREATE TABLE tbl(id INTEGER PRIMARY KEY, " +
"month VARCHAR(" + workload[i] + ")," +
"hour VARCHAR(" + workload[i] + ")," +
"year INTEGER);";
conn.createStatement().execute(createSql);
LengthVarInsertHelper(tupleNum, workload[i]);

try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}

long startTime1 = System.currentTimeMillis();
conn.createStatement().execute(alterAdd);
long endTime1 = System.currentTimeMillis();

long startTime2 = System.currentTimeMillis();
conn.createStatement().execute(alterDrop);
long endTime2 = System.currentTimeMillis();

long startTime3 = System.currentTimeMillis();
conn.createStatement().execute(alterChangeInline);
long endTime3 = System.currentTimeMillis();

System.out.println("Alter add column " + workload[i] * 2 +
" length took: " + (endTime1 - startTime1)
+ " milliseconds");
System.out.println("Alter drop column " + workload[i] * 2 +
" length took: " + (endTime2 - startTime2)
+ " milliseconds");
System.out.println("Alter change type from not inline to inline " + workload[i] * 2
+ " length took: " + (endTime3 - startTime3) +
" milliseconds");

conn.createStatement().execute(SQL_DROP_TABLE);
}
}

// will simply generate string with length and return
private String PayloadGenerate(int length) {
long seed = System.currentTimeMillis() % 26 + 'a';
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
builder.append((char)seed);
}
return builder.toString();
}

private void LengthVarInsertHelper(int insertNum, int varLen) throws SQLException {
String payload1 = PayloadGenerate(varLen);
String payload2 = PayloadGenerate(varLen);
for (int i = 0; i<insertNum; i++){
if( i%1000 == 0) {
payload1 = PayloadGenerate(varLen);
payload2 = PayloadGenerate(varLen);
}
String sql = String.format("INSERT INTO tbl VALUES (%d, '%s', '%s', %d);", i, payload1, payload2, i+1);
conn.createStatement().execute(sql);
}
}
}
Loading