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

[15721] Blocking Schema Changes #1341

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0d83528
add alter table catalog
DeanChensj Apr 2, 2018
f015e94
add change column catalog
DeanChensj Apr 5, 2018
583ec6a
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
469474b
This commit added parser support of alter table
Dingshilun Apr 5, 2018
7b2ae56
add rename column executor
sxzh93 Apr 7, 2018
f255f78
Catalog for change column name
DeanChensj Apr 6, 2018
fd0cb0b
resolve comments, add header, TODO, remove context in subclass
sxzh93 Apr 8, 2018
a3a7cfa
fix
sxzh93 Apr 8, 2018
9e07a95
add alter table catalog
DeanChensj Apr 2, 2018
e695ac2
add change column catalog
DeanChensj Apr 5, 2018
d843ae3
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
59e5982
This commit added parser support of alter table
Dingshilun Apr 5, 2018
dd42a3b
add rename column executor
sxzh93 Apr 7, 2018
a845135
Catalog for change column name
DeanChensj Apr 6, 2018
57e9a6e
resolve comments, add header, TODO, remove context in subclass
sxzh93 Apr 8, 2018
3575048
fix
sxzh93 Apr 8, 2018
6b5da72
AlterTable init test
DeanChensj Apr 8, 2018
b08fa9e
added headers, comments and TODO
Dingshilun Apr 10, 2018
0e46c90
remove comments
DeanChensj Apr 11, 2018
d07920e
add alter table catalog
DeanChensj Apr 2, 2018
88a397c
add change column catalog
DeanChensj Apr 5, 2018
f0ecc68
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
a2f73d9
add rename column executor
sxzh93 Apr 7, 2018
ed7a2a9
Catalog for change column name
DeanChensj Apr 6, 2018
397cf24
fix
sxzh93 Apr 8, 2018
e61451e
add alter table catalog
DeanChensj Apr 2, 2018
098a35a
add change column catalog
DeanChensj Apr 5, 2018
f344a55
Revert "Merge pull request #1 from DeanChensj/catlog"
Apr 5, 2018
e930b11
add rename column executor
sxzh93 Apr 7, 2018
c31ef3a
Catalog for change column name
DeanChensj Apr 6, 2018
74ca51b
fix
sxzh93 Apr 8, 2018
ed1a0de
AlterTable init test
DeanChensj Apr 8, 2018
ef6b9f4
Add transactional test
DeanChensj Apr 12, 2018
844e564
Fix mac compile error
DeanChensj Apr 28, 2018
8cdea77
Addressed comments in test and catalog
DeanChensj Apr 28, 2018
c70353e
add rename column executor
sxzh93 Apr 7, 2018
d3b1321
fix
sxzh93 Apr 8, 2018
6a294fc
This commit added parser support of alter table
Dingshilun Apr 5, 2018
f7af80f
added alter table drop column parser, planner, and catalog support, w…
Dingshilun Apr 16, 2018
d7465e3
add drop column executor
sxzh93 Apr 16, 2018
bf20b05
refacted the rename into alter (parser, planner)
Dingshilun Apr 28, 2018
d1c8437
Merge pull request #9 from sxzh93/refactor_rename_alter_parser
Dingshilun Apr 29, 2018
1ce6ed0
merge
DeanChensj Apr 29, 2018
66220b5
Merge pull request #10 from sxzh93/address-comment
DeanChensj Apr 29, 2018
32ec8fd
added parser support for change column type and add column
Dingshilun Apr 29, 2018
36f111a
Merge pull request #11 from sxzh93/add_column_parser_planner
DeanChensj Apr 29, 2018
253b471
new implement of rename
DeanChensj Apr 29, 2018
41039b8
Merge pull request #13 from sxzh93/new-rename
DeanChensj Apr 30, 2018
4df594b
alter table in catalog
DeanChensj Apr 30, 2018
cf0c5a6
Merge pull request #15 from sxzh93/alter-table
Dingshilun May 2, 2018
21ee68d
added change type into alter tabe
Dingshilun May 3, 2018
68f492f
add alter executor
sxzh93 May 1, 2018
9904788
resolve pr comments
sxzh93 May 3, 2018
a1e7265
Merge pull request #16 from sxzh93/alter_executor
Dingshilun May 3, 2018
fdce5cf
modified alter plan, fixed bugs
Dingshilun May 3, 2018
ae65f67
added change type, changed logic in alter_executor, varchar still not…
Dingshilun May 3, 2018
4e4dfdc
addressed comments and fix varchar
DeanChensj May 4, 2018
4d00de1
Merge pull request #17 from sxzh93/change_type
DeanChensj May 4, 2018
5e454d4
basic test for alterTable
DeanChensj May 4, 2018
bc26411
add alter table tests, change unsupported type, multiple operation in…
sxzh93 May 4, 2018
32a260f
Merge pull request #18 from sxzh93/alter_test
DeanChensj May 5, 2018
72c35ac
added alter varchar length support, changed the plan to use schema
Dingshilun May 5, 2018
733fa9b
Merge pull request #19 from sxzh93/varchar_length
Dingshilun May 5, 2018
a57a5df
rebase master
sxzh93 May 5, 2018
5b9818c
addressed the modification from cmu-db master
Dingshilun May 5, 2018
939df35
change type quick fix
DeanChensj May 13, 2018
20f5d27
add gc logic
DeanChensj May 13, 2018
dbf6d7d
added alter benchmark, leave all workload of benchmark to be empty
Dingshilun May 14, 2018
fc3e951
cache-only set to true when get db object
sxzh93 May 14, 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
211 changes: 211 additions & 0 deletions script/testing/junit/AlterBenchmarkTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// AlterTableTest.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);";


@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;
}

/**
* Setup the connection to peloton or other DBMS
* @throws SQLException
*/
@Before
public void Setup() throws SQLException {
//connection to Postgres
//conn = makePostgresConnection("localhost", 5432, "dingshilun", "");
conn = makeDefaultConnection();
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 {
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 = "alter table tbl add day integer;";
long startTime1 = System.currentTimeMillis();
conn.createStatement().execute(alterSql1);
long endTime1 = System.currentTimeMillis();

String alterSql2 = "alter table tbl drop month;";
long startTime2 = System.currentTimeMillis();
conn.createStatement().execute(alterSql2);
long endTime2 = System.currentTimeMillis();

String alterSql3 = "alter table tbl alter year type varchar";
long startTime3 = System.currentTimeMillis();
conn.createStatement().execute(alterSql3);
long endTime3 = System.currentTimeMillis();

String alterSql4 = "alter table tbl alter year type integer USING year::INTEGER";
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 = "INSERT INTO tbl VALUES (?, ?, ?);";
PreparedStatement pstmt = conn.prepareStatement(sql);
for (int i = 0; i < insertNum; i++) {
setValues(pstmt, new int [] {i, i+1, i+2});
pstmt.addBatch();
}
pstmt.executeBatch();
}

/**
* Insert 10000 tuple, and test performance under different
* length of the tuple
* @throws SQLException
*/
@Test
public void test_tuple_length_variance() throws SQLException {
int[] workload = {};
int tupleNum = 10000;
String dropSQL = "DROP TABLE IF EXISTS tbl";
String sql = "";
conn.createStatement().execute(dropSQL);
for (int i = 0; i < workload.length; i++) {
sql = "CREATE TABLE tbl(id INTEGER PRIMARY KEY, " +
"payload1 VARCHAR(" + workload[i] + ")," +
"payload2 VARCHAR(" + workload[i] + ")," +
"payload3 INTEGER);";
conn.createStatement().execute(sql);
LengthVarInsertHelper(tupleNum, workload[i]);

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

long startTime1 = System.currentTimeMillis();
conn.createStatement().execute("ALTER TABLE tbl add payload4 integer;");
long endTime1 = System.currentTimeMillis();

long startTime2 = System.currentTimeMillis();
conn.createStatement().execute("ALTER TABLE tbl drop payload1;");
long endTime2 = System.currentTimeMillis();

long startTime3 = System.currentTimeMillis();
conn.createStatement().execute("ALTER TABLE tbl alter payload3 type varchar;");
long endTime3 = System.currentTimeMillis();

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

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

// 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