-
Notifications
You must be signed in to change notification settings - Fork 879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support column renames on tables that have compression enabled. #2909
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2909 +/- ##
==========================================
+ Coverage 90.12% 90.27% +0.14%
==========================================
Files 212 212
Lines 34793 34937 +144
==========================================
+ Hits 31358 31540 +182
+ Misses 3435 3397 -38
Continue to review full report at Codecov.
|
29da96f
to
1d9865a
Compare
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.
Consider if you should move all the code to the tsl/
directory.
* Assumption: column names are the same on compressed and | ||
* uncompressed chunk. |
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.
Is this something you should add a check for? Metadata can break, will the code work correctly if it is broken?
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.
This is a pre-existing assumption. This code does not change any pre-existing assumptions.
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.
What happens if this assumption is not correct, does the code crash or does it just give an error?
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.
I added this comment to clarify existing code and the assumptions made by it. This would crash if the rename were to go through without respecting the existing assumption.
if (TS_HYPERTABLE_HAS_COMPRESSION_TABLE(ht)) | ||
{ | ||
int32 compress_htid = ht->fd.compressed_hypertable_id; | ||
Hypertable *compress_ht = ts_hypertable_get_by_id(compress_htid); |
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.
Hypertable *compress_ht = ts_hypertable_get_by_id(compress_htid); | |
const Hypertable *compress_ht = ts_hypertable_get_by_id(compress_htid); |
if (stmt->renameType == OBJECT_COLUMN) | ||
{ | ||
if (TS_HYPERTABLE_HAS_COMPRESSION_TABLE(ht) || TS_HYPERTABLE_HAS_COMPRESSION_ENABLED(ht)) |
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.
Suggest to combine these conditions: it's a lot easier to read.
WHERE attname = 'coli' and hypertable_id = (SELECT id from _timescaledb_catalog.hypertable | ||
WHERE table_name = 'test1' ); |
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.
A little hard to read, suggesting an alternative that you can ignore if you like.
WHERE attname = 'coli' and hypertable_id = (SELECT id from _timescaledb_catalog.hypertable | |
WHERE table_name = 'test1' ); | |
WHERE attname = 'coli' | |
AND hypertable_id = (SELECT id from _timescaledb_catalog.hypertable WHERE table_name = 'test1' ); |
SELECT COUNT(*) AS count_compressed | ||
FROM | ||
( | ||
SELECT compress_chunk(chunk.schema_name|| '.' || chunk.table_name) |
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.
Any reason to not use format
? It is used elsewhere.
SELECT format('%I.%I', cht.schema_name, cht.table_name) AS "COMPRESSION_TBLNM" | ||
FROM _timescaledb_catalog.hypertable ht, _timescaledb_catalog.hypertable cht | ||
WHERE ht.table_name = 'test1' and cht.id = ht.compressed_hypertable_id \gset | ||
|
||
SELECT count(*) | ||
FROM ( SELECT attrelid::regclass, attname FROM pg_attribute | ||
WHERE attrelid in (SELECT inhrelid::regclass from pg_inherits | ||
where inhparent = :'COMPRESSION_TBLNM'::regclass ) | ||
and attname = 'bigintcol' ) q; |
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.
Nit: you're only using the variable here so suggest to use a CTE: it's a lot easier to read.
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.
Can you add some tests where identifiers are getting truncated.
ALTER TABLE t RENAME c TO cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc;
ALTER TABLE t RENAME cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
TO accccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc;
ts_dimension_set_name(dim, stmt->newname); | ||
if (dim) | ||
ts_dimension_set_name(dim, stmt->newname); | ||
if (ts_cm_functions->process_rename_cmd) |
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.
Do we really this this new cross module function? We can use existing tsl_ddl_command_start
hook instead
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.
I tried to refactor the process_utility code to directly call tsl_ddl_command_start without any additional tsl support functions. It doesn't work as expected as some ddl functions are executed in multi transaction contexts. For this particular ddl command, the original hypertable has already been modified and the hypertable cache cannot find it by the time we get here with the original name.
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.
I share @pmwkaa's concern (and I have given similar feedback in the past). If the existing DDL forwarding doesn't work for some reason (I am not sure I understand why not), then we should at least use just one cross-module function for all DDL statements instead of adding a new one for each DDL. The reason the the hypertable cannot be found in the cache is because CommandCounterIncrement()
. We have catalog update functions to deal with that without doing command-counter increment.
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.
@erimatnor This is the refactoring change we discussed. I spent a few days trying to refactor the code to get this to work: Setting the hypertable cache and passing it around didn't work as expected. I didn't want to spend more time fixing this at the cost of derailing this feature support. process_utility code needs a wider overhaul to work without adding new functions to the tsl code. We also have exactly the same issue calling out to sql functions that have implementations under tsl. This should also be addressed as part of the refactoring effort.
1d9865a
to
5d1a666
Compare
b324c1f
to
07999aa
Compare
ALTER TABLE <hypertable> RENAME <column_name> TO <new_column_name> is now supported for hypertables that have compression enabled. Note: Column renaming is not supported for distributed hypertables. So this will not work on distributed hypertables that have compression enabled.
07999aa
to
74d874a
Compare
-1); | ||
ExecRenameStmt(compress_col_stmt); | ||
} | ||
// update catalog entries for the renamed column for the hypertable |
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.
Nit: C++ style comment.
@@ -158,3 +158,49 @@ ts_hypertable_compression_delete_by_hypertable_id(int32 htid) | |||
} | |||
return count > 0; | |||
} | |||
|
|||
TSDLLEXPORT void | |||
ts_hypertable_compression_rename_column(int32 htid, char *old_column_name, char *new_column_name) |
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.
ts_hypertable_compression_rename_column(int32 htid, char *old_column_name, char *new_column_name) | |
ts_hypertable_compression_rename_column(int32 htid, const char *old_column_name, const char *new_column_name) |
} | ||
} | ||
if (found == false) | ||
elog(ERROR, "column %s not found in hypertable_compression catalog table", old_column_name); |
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 this be an assert? AFAIK, it shouldn't happen so this will be dead code that we cannot test for. If it is a valid error, I think it is preferred that this is a more user-friendly message that doesn't reference specific internal catalogs.
@@ -99,6 +99,7 @@ typedef struct CrossModuleFunctions | |||
bool (*process_compress_table)(AlterTableCmd *cmd, Hypertable *ht, | |||
WithClauseResult *with_clause_options); | |||
void (*process_altertable_cmd)(Hypertable *ht, const AlterTableCmd *cmd); | |||
void (*process_rename_cmd)(Hypertable *ht, const RenameStmt *stmt); |
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.
I think this has come up before, and I don't know the conclusion so I'll reiterate.
I think creating a new cross-module function for every process utility (DDL) command is not a good idea and doesn't really scale. We already "forward" DDL commands to TSL and we should try to use that mechanism or improve it if it isn't sufficient in its current form.
The next best approach, IMO, is to have a "general" cross-module function that we can reuse for all DDL commands, e.g.:
void (*process_ddl_cmd)(Hypertable *ht, const Node *cmd);
then use a switch on it in the process_ddl_cmd
function:
switch (nodeTag(cmd))
{
case T_RenameStmt:
....
break;
case T_AlterTableCmd:
...
break;
}
ts_dimension_set_name(dim, stmt->newname); | ||
if (dim) | ||
ts_dimension_set_name(dim, stmt->newname); | ||
if (ts_cm_functions->process_rename_cmd) |
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.
I share @pmwkaa's concern (and I have given similar feedback in the past). If the existing DDL forwarding doesn't work for some reason (I am not sure I understand why not), then we should at least use just one cross-module function for all DDL statements instead of adding a new one for each DDL. The reason the the hypertable cannot be found in the cache is because CommandCounterIncrement()
. We have catalog update functions to deal with that without doing command-counter increment.
This release adds major new features since the 2.0.2 release. We deem it moderate priority for upgrading. This release adds the long-awaited support for PostgreSQL 13 to TimescaleDB. This release also relaxes some restrictions for compressed hypertables; namely, TimescaleDB now supports adding columns to compressed hypertables and renaming columns of compressed hypertables. **Major Features** * timescale#2779 Add support for PostgreSQL 13 **Minor features** * timescale#2736 Support adding columns to hypertables with compression enabled * timescale#2909 Support renaming columns of hypertables with compression enabled
This release adds major new features since the 2.0.2 release. We deem it moderate priority for upgrading. This release adds the long-awaited support for PostgreSQL 13 to TimescaleDB. This release also relaxes some restrictions for compressed hypertables; namely, TimescaleDB now supports adding columns to compressed hypertables and renaming columns of compressed hypertables. **Major Features** * timescale#2779 Add support for PostgreSQL 13 **Minor features** * timescale#2736 Support adding columns to hypertables with compression enabled * timescale#2909 Support renaming columns of hypertables with compression enabled
This release adds major new features since the 2.0.2 release. We deem it moderate priority for upgrading. This release adds the long-awaited support for PostgreSQL 13 to TimescaleDB. The minimum required PostgreSQL 13 version is 13.2 due to a security vulnerability affecting TimescaleDB functionality present in earlier versions of PostgreSQL 13. This release also relaxes some restrictions for compressed hypertables; namely, TimescaleDB now supports adding columns to compressed hypertables and renaming columns of compressed hypertables. **Major Features** * timescale#2779 Add support for PostgreSQL 13 **Minor features** * timescale#2736 Support adding columns to hypertables with compression enabled * timescale#2909 Support renaming columns of hypertables with compression enabled
This release adds major new features since the 2.0.2 release. We deem it moderate priority for upgrading. This release adds the long-awaited support for PostgreSQL 13 to TimescaleDB. The minimum required PostgreSQL 13 version is 13.2 due to a security vulnerability affecting TimescaleDB functionality present in earlier versions of PostgreSQL 13. This release also relaxes some restrictions for compressed hypertables; namely, TimescaleDB now supports adding columns to compressed hypertables and renaming columns of compressed hypertables. **Major Features** * #2779 Add support for PostgreSQL 13 **Minor features** * #2736 Support adding columns to hypertables with compression enabled * #2909 Support renaming columns of hypertables with compression enabled
This release adds major new features since the 2.0.2 release. We deem it moderate priority for upgrading. This release adds the long-awaited support for PostgreSQL 13 to TimescaleDB. The minimum required PostgreSQL 13 version is 13.2 due to a security vulnerability affecting TimescaleDB functionality present in earlier versions of PostgreSQL 13. This release also relaxes some restrictions for compressed hypertables; namely, TimescaleDB now supports adding columns to compressed hypertables and renaming columns of compressed hypertables. **Major Features** * #2779 Add support for PostgreSQL 13 **Minor features** * #2736 Support adding columns to hypertables with compression enabled * #2909 Support renaming columns of hypertables with compression enabled
This release adds major new features since the 2.0.2 release. We deem it moderate priority for upgrading. This release adds the long-awaited support for PostgreSQL 13 to TimescaleDB. The minimum required PostgreSQL 13 version is 13.2 due to a security vulnerability affecting TimescaleDB functionality present in earlier versions of PostgreSQL 13. This release also relaxes some restrictions for compressed hypertables; namely, TimescaleDB now supports adding columns to compressed hypertables and renaming columns of compressed hypertables. **Major Features** * #2779 Add support for PostgreSQL 13 **Minor features** * #2736 Support adding columns to hypertables with compression enabled * #2909 Support renaming columns of hypertables with compression enabled
ALTER TABLE RENAME <column_name> TO <new_column_name>
is now supported for hypertables that have compression enabled.
To reviewers:
This PR has multiple commits to help with reviewing test changes. These will be merged.