@@ -867,24 +867,15 @@ process_copy(ProcessUtilityArgs *args)
867867
868868 if (!ht )
869869 {
870- Chunk * chunk = ts_chunk_get_by_relid (relid , false);
871-
872- /* target is neither hypertable nor chunk so let postgres handle it */
873- if (!chunk )
874- {
875- ts_cache_release (& hcache );
876- return DDL_CONTINUE ;
877- }
878-
879- ht = ts_hypertable_get_by_id (chunk -> fd .hypertable_id );
880- if (ht -> fd .compression_state == HypertableInternalCompressionTable )
870+ /*
871+ * For operations on internal compressed chunks we block modifications
872+ * if the chunk belongs to a frozen chunk otherwise let postgres handle it.
873+ * Uncompressed frozen chunks are intercepted as part of tuple routing.
874+ */
875+ Oid uncompressed_relid = ts_relation_get_uncompressed_relid (relid );
876+ if (OidIsValid (uncompressed_relid ))
881877 {
882- /*
883- * For operations on internal compressed chunks we block modifications
884- * if the chunk belongs to a frozen chunk otherwise let postgres handle it.
885- * Uncompressed frozen chunks are intercepted as part of tuple routing.
886- */
887- Chunk * uncompressed = ts_chunk_get_compressed_chunk_parent (chunk );
878+ Chunk * uncompressed = ts_chunk_get_by_relid (uncompressed_relid , true);
888879 if (ts_chunk_is_frozen (uncompressed ))
889880 {
890881 ereport (ERROR ,
@@ -896,6 +887,16 @@ process_copy(ProcessUtilityArgs *args)
896887 ts_cache_release (& hcache );
897888 return DDL_CONTINUE ;
898889 }
890+
891+ /* target is neither hypertable nor chunk so let postgres handle it */
892+ int32 hypertable_id = ts_chunk_get_hypertable_id_by_reloid (relid );
893+ if (hypertable_id == INVALID_HYPERTABLE_ID )
894+ {
895+ ts_cache_release (& hcache );
896+ return DDL_CONTINUE ;
897+ }
898+
899+ ht = ts_hypertable_get_by_id (hypertable_id );
899900 }
900901 }
901902
@@ -1154,13 +1155,13 @@ add_chunk_to_vacuum(Hypertable *ht, Oid chunk_relid, void *arg)
11541155 ctx -> chunk_rels = lappend (ctx -> chunk_rels , chunk_vacuum_rel );
11551156
11561157 /* If we have a compressed chunk make sure to analyze it as well */
1157- if (chunk -> fd . compressed_chunk_id != INVALID_CHUNK_ID )
1158+ if (ts_chunk_is_compressed ( chunk ) )
11581159 {
1159- Chunk * comp_chunk = ts_chunk_get_by_id (chunk -> fd . compressed_chunk_id , false );
1160+ Oid compressed_relid = ts_relation_get_compressed_relid (chunk -> table_id );
11601161 /* Compressed chunk might be missing due to concurrent operations */
1161- if (comp_chunk )
1162+ if (OidIsValid ( compressed_relid ) )
11621163 {
1163- chunk_vacuum_rel = makeVacuumRelation (NULL , comp_chunk -> table_id , NIL );
1164+ chunk_vacuum_rel = makeVacuumRelation (NULL , compressed_relid , NIL );
11641165 ctx -> chunk_rels = lappend (ctx -> chunk_rels , chunk_vacuum_rel );
11651166 }
11661167 }
@@ -1565,17 +1566,18 @@ process_truncate(ProcessUtilityArgs *args)
15651566 ts_continuous_agg_invalidate_chunk (ht , chunk );
15661567 }
15671568 /* Truncate the compressed chunk too */
1568- if (chunk -> fd . compressed_chunk_id != INVALID_CHUNK_ID )
1569+ if (ts_chunk_is_compressed ( chunk ) )
15691570 {
1570- Chunk * compressed_chunk =
1571- ts_chunk_get_by_id (chunk -> fd . compressed_chunk_id , false );
1572- if (compressed_chunk != NULL )
1571+ Oid compressed_relid =
1572+ ts_relation_get_compressed_relid (chunk -> table_id );
1573+ if (OidIsValid ( compressed_relid ) )
15731574 {
15741575 /* Create list item into the same context of the list. */
15751576 oldctx = MemoryContextSwitchTo (parsetreectx );
1576- rv = makeRangeVar (NameStr (compressed_chunk -> fd .schema_name ),
1577- NameStr (compressed_chunk -> fd .table_name ),
1578- -1 );
1577+ char * schema_name =
1578+ get_namespace_name (get_rel_namespace (compressed_relid ));
1579+ char * table_name = get_rel_name (compressed_relid );
1580+ rv = makeRangeVar (schema_name , table_name , -1 );
15791581 MemoryContextSwitchTo (oldctx );
15801582 list_changed = true;
15811583 }
@@ -1712,7 +1714,7 @@ process_drop_chunk(ProcessUtilityArgs *args, DropStmt *stmt)
17121714 {
17131715 Hypertable * ht ;
17141716
1715- if (ts_chunk_contains_compressed_data (chunk ))
1717+ if (ts_relation_is_compressed_chunk_relation (chunk -> table_id ))
17161718 {
17171719 ereport (ERROR ,
17181720 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -1723,13 +1725,13 @@ process_drop_chunk(ProcessUtilityArgs *args, DropStmt *stmt)
17231725
17241726 /* if cascade is enabled, delete the compressed chunk with cascade too. Otherwise
17251727 * it would be blocked if there are dependent objects */
1726- if (stmt -> behavior == DROP_CASCADE && chunk -> fd . compressed_chunk_id != INVALID_CHUNK_ID )
1728+ if (stmt -> behavior == DROP_CASCADE && ts_chunk_is_compressed ( chunk ) )
17271729 {
1728- Chunk * compressed_chunk =
1729- ts_chunk_get_by_id_with_slice_lock ( chunk -> fd . compressed_chunk_id ,
1730- AccessExclusiveLock ,
1731- & slice_lock ,
1732- false);
1730+ Oid compressed_relid = ts_relation_get_compressed_relid ( chunk -> table_id );
1731+ Chunk * compressed_chunk = ts_chunk_get_by_relid_locked ( compressed_relid ,
1732+ AccessExclusiveLock ,
1733+ & slice_lock ,
1734+ false);
17331735 /* The chunk may have been delete by a CASCADE */
17341736 if (compressed_chunk != NULL )
17351737 {
@@ -4762,14 +4764,7 @@ process_altertable_end_index(Node *parsetree, CollectedCommand *cmd)
47624764static void
47634765process_altertable_chunk_propagate_to_compressed (AlterTableCmd * cmd , Oid relid )
47644766{
4765- Chunk * chunk = ts_chunk_get_by_relid (relid , false);
4766-
4767- if (chunk == NULL )
4768- {
4769- return ;
4770- }
4771-
4772- if (ts_chunk_contains_compressed_data (chunk ))
4767+ if (ts_relation_is_compressed_chunk_relation (relid ))
47734768 {
47744769 ereport (ERROR ,
47754770 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -4778,12 +4773,12 @@ process_altertable_chunk_propagate_to_compressed(AlterTableCmd *cmd, Oid relid)
47784773 "instead." )));
47794774 }
47804775
4776+ Oid compressed_relid = ts_relation_get_compressed_relid (relid );
4777+
47814778 /* set tablespace for compressed chunk */
4782- if (chunk -> fd . compressed_chunk_id != INVALID_CHUNK_ID )
4779+ if (OidIsValid ( compressed_relid ) )
47834780 {
4784- Chunk * compressed_chunk = ts_chunk_get_by_id (chunk -> fd .compressed_chunk_id , true);
4785-
4786- AlterTableInternal (compressed_chunk -> table_id , list_make1 (cmd ), false);
4781+ AlterTableInternal (compressed_relid , list_make1 (cmd ), false);
47874782 }
47884783}
47894784
0 commit comments