- 
                Notifications
    You must be signed in to change notification settings 
- Fork 619
Constraint refactoring #1415
Constraint refactoring #1415
Conversation
| @apavlo Joy wrote the original code and nobody has touched that code in a long time. I don't know if anybody else understands it so can you take a look? | 
| @tli2 Sure, I will rebase locally, and fix all tabs. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant calls and unused variables. Revise incorrect comments. And some possible testing improvements.
        
          
                src/catalog/catalog.cpp
              
                Outdated
          
        
      |  | ||
| // Insert column info into each catalog | ||
| oid_t column_id = 0; | ||
| std::vector<oid_t> pkey_attrs, unique_attrs; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables are unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete them.
        
          
                src/catalog/catalog.cpp
              
                Outdated
          
        
      | // Insert column info into each catalog | ||
| oid_t column_id = 0; | ||
| std::vector<oid_t> pkey_attrs, unique_attrs; | ||
| std::shared_ptr<Constraint> pkey_constraint, unique_constraint; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables are also unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete them.
        
          
                src/catalog/catalog.cpp
              
                Outdated
          
        
      | ->GetSchema(); | ||
|  | ||
| // Create index | ||
| std::stringstream index_name(table_object->GetTableName().c_str()); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant call to c_str()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete it.
        
          
                src/catalog/catalog.cpp
              
                Outdated
          
        
      | src_table_oid, txn); | ||
| auto src_schema = src_table->GetSchema(); | ||
|  | ||
| std::stringstream index_name(src_table_object->GetTableName().c_str()); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant call to c_str()
        
          
                src/catalog/constraint_catalog.cpp
              
                Outdated
          
        
      |  | ||
| /*@brief Insert a constraint into the pg_constraint table | ||
| * This targets PRIMARY KEY, FOREIGN KEY, UNIQUE or CHECK constraint | ||
| * @param table_oid oid of the table related to this constraint | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
table_oid is not in the parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete redundant comments.
        
          
                test/catalog/catalog_test.cpp
              
                Outdated
          
        
      | auto salary = catalog->GetTableObject("emp_db", DEFAULT_SCHEMA_NAME, | ||
| "salary_table", txn); | ||
|  | ||
| catalog->AddPrimaryKeyConstraint(emp->GetDatabaseOid(), emp->GetTableOid(), | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add PrimaryKey constraints in the CreatingTable test and without verifying it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not adding, but just fixing. These might be used in other test? Verifying for primary keys is done in ConstraintCatalogTest.
        
          
                test/catalog/catalog_test.cpp
              
                Outdated
          
        
      |  | ||
| catalog->AddPrimaryKeyConstraint(emp->GetDatabaseOid(), emp->GetTableOid(), | ||
| {0}, "con_primary", txn); | ||
| catalog->AddPrimaryKeyConstraint(department->GetDatabaseOid(), | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add PrimaryKey constraints in the CreatingTable test and without verifying it?
        
          
                test/catalog/catalog_test.cpp
              
                Outdated
          
        
      | catalog->AddPrimaryKeyConstraint(department->GetDatabaseOid(), | ||
| department->GetTableOid(), {0}, | ||
| "con_primary", txn); | ||
| catalog->AddPrimaryKeyConstraint( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add PrimaryKey constraints in the CreatingTable test and without verifying it?
| LOG_DEBUG("%s", con_table->GetSchema()->GetInfo().c_str()); | ||
| LOG_DEBUG("Complete check for constraint table"); | ||
|  | ||
| // Drop constraint | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better if we can verify it after dropping constraints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Add verifying.
| table->AddIndex(pkey_index); | ||
|  | ||
| // Create primary key constraint on the table | ||
| if (need_primary_index) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be need_primary_index or need_primary_key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix it to need_primary_key.
* Add pg_constraint catalog table * Reconstruct constraints
* Revert "Constraint refactoring (cmu-db#1415)" This reverts commit 898219f
This PR refactors constraint stuff related to planner, executor, storage and catalog.
- Contributions
pg_constraintTable constraint (Primary key, Foreign key, Unique, Check) ->
Constraint(pg_constraint)Column constraint (Not null, Default) ->
Column(pg_attribute)Deleted class ->
ForeignKey,MultiConstraintCatalog.DataTablewhen inserting/updating.- Related Issues
- Remaining Issues