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

Commit bf33cd6

Browse files
authored
Merge pull request #1120 from pervazea/unique
Fix for issue #1117, UNIQUE
2 parents 60b98f3 + 863b5bf commit bf33cd6

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

Jenkinsfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ pipeline {
5959
sh 'python ./script/validators/source_validator.py'
6060
sh 'mkdir build'
6161
sh 'cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCOVERALLS=False .. && make -j4'
62+
sh 'cd build && make check -j4 || true'
63+
// sh 'cd build && cp -pr test /job/'
64+
sh 'cd build && make benchmark -j4'
65+
sh 'cd build && make install'
66+
sh 'cd build && bash ../script/testing/psql/psql_test.sh'
67+
sh 'cd build && python ../script/validators/jdbc_validator.py'
6268
}
6369
}
6470

src/catalog/catalog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ ResultType Catalog::CreateTable(const std::string &database_name,
271271
table_oid, column.GetName(), column_id, column.GetOffset(),
272272
column.GetType(), column.IsInlined(), column.GetConstraints(),
273273
pool_.get(), txn);
274-
column_id++;
275274

276275
// Create index on unique single column
277276
if (column.IsUnique()) {
@@ -282,6 +281,7 @@ ResultType Catalog::CreateTable(const std::string &database_name,
282281
LOG_DEBUG("Added a UNIQUE index on %s in %s.", col_name.c_str(),
283282
table_name.c_str());
284283
}
284+
column_id++;
285285
}
286286
CreatePrimaryIndex(database_object->GetDatabaseOid(), table_oid, txn);
287287
return ResultType::SUCCESS;

src/storage/data_table.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,6 @@ bool DataTable::CheckForeignKeyConstraints(
773773

774774
// The foreign key constraints only refer to the primary key
775775
if (index->GetIndexType() == IndexConstraintType::PRIMARY_KEY) {
776-
LOG_INFO("BEGIN checking referred table");
777776

778777
std::vector<oid_t> key_attrs = foreign_key->GetSinkColumnIds();
779778
std::unique_ptr<catalog::Schema> foreign_key_schema(

test/sql/insert_sql_test.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,5 +523,52 @@ TEST_F(InsertSQLTests, InsertIntoSelectColumn) {
523523
txn_manager.CommitTransaction(txn);
524524
}
525525

526+
TEST_F(InsertSQLTests, UniqueColumn) {
527+
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
528+
auto txn = txn_manager.BeginTransaction();
529+
catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
530+
txn_manager.CommitTransaction(txn);
531+
532+
std::string create_table("CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY,"
533+
"st VARCHAR(15) NOT NULL UNIQUE);");
534+
TestingSQLUtil::ExecuteSQLQuery(create_table);
535+
536+
ResultType result;
537+
std::vector<std::string> ref_result;
538+
std::string result_query = "select st from t;";
539+
540+
// Single row, should succeed
541+
std::string ins_query_1("INSERT INTO t VALUES (1, 'abc');");
542+
result = TestingSQLUtil::ExecuteSQLQuery(ins_query_1);
543+
EXPECT_EQ(result, ResultType::SUCCESS);
544+
ref_result.push_back("abc");
545+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(result_query,
546+
ref_result,
547+
false);
548+
549+
// Second row, distinct from first, should succeed
550+
std::string ins_query_2("INSERT INTO t VALUES (2, 'def');");
551+
result = TestingSQLUtil::ExecuteSQLQuery(ins_query_2);
552+
EXPECT_EQ(result, ResultType::SUCCESS);
553+
ref_result.push_back("def");
554+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(result_query,
555+
ref_result,
556+
false);
557+
558+
// Third row, non-unique value for string, should fail
559+
std::string ins_query_3("INSERT INTO t VALUES (3, 'abc');");
560+
result = TestingSQLUtil::ExecuteSQLQuery(ins_query_3);
561+
EXPECT_EQ(result, ResultType::ABORTED);
562+
// and the results returned should not include failed insert
563+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(result_query,
564+
ref_result,
565+
false);
566+
567+
// free the database just created
568+
txn = txn_manager.BeginTransaction();
569+
catalog::Catalog::GetInstance()->DropDatabaseWithName(DEFAULT_DB_NAME, txn);
570+
txn_manager.CommitTransaction(txn);
571+
}
572+
526573
} // namespace test
527574
} // namespace peloton

0 commit comments

Comments
 (0)