@@ -281,6 +281,7 @@ check_alter_table_allowed_on_ht_with_compression(Hypertable *ht, AlterTableStmt
281
281
case AT_ReAddStatistics :
282
282
case AT_SetCompression :
283
283
case AT_DropNotNull :
284
+ case AT_SetNotNull :
284
285
#if PG15_GE
285
286
case AT_SetAccessMethod :
286
287
#endif
@@ -2563,11 +2564,50 @@ process_altertable_validate_constraint_end(Hypertable *ht, AlterTableCmd *cmd)
2563
2564
foreach_chunk (ht , validate_hypertable_constraint , cmd );
2564
2565
}
2565
2566
2567
+ /*
2568
+ * Validate that SET NOT NULL is ok for this chunk.
2569
+ *
2570
+ * Throws an error if SET NOT NULL on this chunk is not allowed, right now,
2571
+ * SET NOT NULL is allowed on chunks that are either a fully decompressed, or
2572
+ * are using the Hypercore table access method.
2573
+ */
2574
+ static void
2575
+ validate_set_not_null (Hypertable * ht , Oid chunk_relid , void * arg )
2576
+ {
2577
+ Chunk * chunk = ts_chunk_get_by_relid (chunk_relid , true);
2578
+ if (ts_chunk_is_compressed (chunk ) && !ts_is_hypercore_am (chunk -> amoid ))
2579
+ {
2580
+ ereport (ERROR ,
2581
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
2582
+ errmsg ("operation not supported on compressed chunks not using the "
2583
+ "\"hypercore\" table access method" ),
2584
+ errdetail ("Chunk %s.%s is using the heap table access method and has compressed "
2585
+ "data." ,
2586
+ NameStr (chunk -> fd .schema_name ),
2587
+ NameStr (chunk -> fd .table_name )),
2588
+ errhint ("Either decompress all chunks of the hypertable or use \"ALTER TABLE "
2589
+ "%s.%s SET ACCESS METHOD hypercore\" on all chunks to change access "
2590
+ "method." ,
2591
+ NameStr (chunk -> fd .schema_name ),
2592
+ NameStr (chunk -> fd .table_name ))));
2593
+ }
2594
+ }
2595
+
2596
+ /*
2597
+ * This function checks that we are not dropping NOT NULL from bad columns and
2598
+ * that all chunks support the modification.
2599
+ */
2566
2600
static void
2567
- process_altertable_drop_not_null (Hypertable * ht , AlterTableCmd * cmd )
2601
+ process_altertable_alter_not_null_start (Hypertable * ht , AlterTableCmd * cmd )
2568
2602
{
2569
2603
int i ;
2570
2604
2605
+ if (cmd -> subtype == AT_SetNotNull )
2606
+ foreach_chunk (ht , validate_set_not_null , cmd );
2607
+
2608
+ if (cmd -> subtype != AT_DropNotNull )
2609
+ return ;
2610
+
2571
2611
for (i = 0 ; i < ht -> space -> num_dimensions ; i ++ )
2572
2612
{
2573
2613
Dimension * dim = & ht -> space -> dimensions [i ];
@@ -3803,9 +3843,10 @@ process_altertable_start_table(ProcessUtilityArgs *args)
3803
3843
verify_constraint_hypertable (ht , cmd -> def );
3804
3844
}
3805
3845
break ;
3846
+ case AT_SetNotNull :
3806
3847
case AT_DropNotNull :
3807
3848
if (ht != NULL )
3808
- process_altertable_drop_not_null (ht , cmd );
3849
+ process_altertable_alter_not_null_start (ht , cmd );
3809
3850
break ;
3810
3851
case AT_AddColumn :
3811
3852
#if PG16_LT
@@ -4187,6 +4228,8 @@ process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *ob
4187
4228
case AT_DropCluster :
4188
4229
foreach_chunk (ht , process_altertable_chunk , cmd );
4189
4230
break ;
4231
+ case AT_SetNotNull :
4232
+ case AT_DropNotNull :
4190
4233
case AT_SetRelOptions :
4191
4234
case AT_ResetRelOptions :
4192
4235
case AT_ReplaceRelOptions :
@@ -4213,8 +4256,6 @@ process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *ob
4213
4256
case AT_SetStorage :
4214
4257
case AT_ColumnDefault :
4215
4258
case AT_CookedColumnDefault :
4216
- case AT_SetNotNull :
4217
- case AT_DropNotNull :
4218
4259
case AT_AddOf :
4219
4260
case AT_DropOf :
4220
4261
case AT_AddIdentity :
@@ -4494,8 +4535,8 @@ process_reassign_owned_start(ProcessUtilityArgs *args)
4494
4535
Oid newrole_oid = get_rolespec_oid (stmt -> newrole , false);
4495
4536
HeapTuple tuple = ts_scanner_fetch_heap_tuple (ti , false, & should_free );
4496
4537
4497
- /* We do not need to check privileges here since ReassignOwnedObjects() will check the
4498
- * privileges and error out if they are not correct. */
4538
+ /* We do not need to check privileges here since ReassignOwnedObjects() will check
4539
+ * the privileges and error out if they are not correct. */
4499
4540
ts_bgw_job_update_owner (ti -> scanrel , tuple , ts_scanner_get_tupledesc (ti ), newrole_oid );
4500
4541
4501
4542
if (should_free )
@@ -4631,8 +4672,8 @@ process_create_stmt(ProcessUtilityArgs *args)
4631
4672
errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
4632
4673
errmsg ("hypercore access method not supported on \"%s\"" , stmt -> relation -> relname ),
4633
4674
errdetail ("The hypercore access method is only supported for hypertables." ),
4634
- errhint ("It does not make sense to set the default access method for all tables "
4635
- "to \"%s\" since it is only supported for hypertables." ,
4675
+ errhint ("It does not make sense to set the default access method for all "
4676
+ "tables to \"%s\" since it is only supported for hypertables." ,
4636
4677
TS_HYPERCORE_TAM_NAME ));
4637
4678
4638
4679
return DDL_CONTINUE ;
0 commit comments