|
5 | 5 | #include "access/pax_dml_state.h" |
6 | 6 | #include "access/pax_partition.h" |
7 | 7 | #include "access/pax_scanner.h" |
| 8 | +#include "access/pax_table_cluster.h" |
8 | 9 | #include "access/pax_updater.h" |
9 | 10 | #include "access/paxc_rel_options.h" |
10 | 11 | #include "access/paxc_scanner.h" |
@@ -242,24 +243,55 @@ void CCPaxAccessMethod::RelationCopyData(Relation rel, |
242 | 243 | } |
243 | 244 |
|
244 | 245 | /* |
245 | | - * Used by rebuild_relation, like CLUSTER, VACUUM FULL, etc. |
| 246 | + * Copy data from `OldTable` into `NewTable`, as part of a CLUSTER or VACUUM |
| 247 | + * FULL. |
246 | 248 | * |
247 | 249 | * PAX does not have dead tuples, but the core framework requires |
248 | 250 | * to implement this callback to do CLUSTER/VACUUM FULL/etc. |
249 | 251 | * PAX may have re-organize semantics for this function. |
250 | 252 | * |
251 | | - * TODO: how to split the set of micro-partitions to several QE handlers. |
| 253 | + * |
| 254 | + * Additional Input parameters: |
| 255 | + * - use_sort - if true, the table contents are sorted appropriate for |
| 256 | + * `OldIndex`; if false and OldIndex is not InvalidOid, the data is copied |
| 257 | + * in that index's order; if false and OldIndex is InvalidOid, no sorting is |
| 258 | + * performed |
| 259 | + * - OldIndex - see use_sort |
| 260 | + * - OldestXmin - computed by vacuum_set_xid_limits(), even when |
| 261 | + * not needed for the relation's AM |
| 262 | + * - *xid_cutoff - ditto |
| 263 | + * - *multi_cutoff - ditto |
| 264 | + * |
| 265 | + * Output parameters: |
| 266 | + * - *xid_cutoff - rel's new relfrozenxid value, may be invalid |
| 267 | + * - *multi_cutoff - rel's new relminmxid value, may be invalid |
| 268 | + * - *tups_vacuumed - stats, for logging, if appropriate for AM |
| 269 | + * - *tups_recently_dead - stats, for logging, if appropriate for AM |
252 | 270 | */ |
253 | 271 | void CCPaxAccessMethod::RelationCopyForCluster( |
254 | | - Relation old_heap, Relation new_heap, Relation /*old_index*/, |
255 | | - bool /*use_sort*/, TransactionId /*oldest_xmin*/, |
256 | | - TransactionId * /*xid_cutoff*/, MultiXactId * /*multi_cutoff*/, |
257 | | - double * /*num_tuples*/, double * /*tups_vacuumed*/, |
258 | | - double * /*tups_recently_dead*/) { |
259 | | - Assert(RELATION_IS_PAX(old_heap)); |
260 | | - Assert(RELATION_IS_PAX(new_heap)); |
| 272 | + Relation old_rel, Relation new_rel, Relation old_index, bool use_sort, |
| 273 | + TransactionId /*oldest_xmin*/, TransactionId * /*xid_cutoff*/, |
| 274 | + MultiXactId * /*multi_cutoff*/, double * /*num_tuples*/, |
| 275 | + double * /*tups_vacuumed*/, double * /* tups_recently_dead*/) { |
| 276 | + Assert(RELATION_IS_PAX(old_rel)); |
| 277 | + Assert(RELATION_IS_PAX(new_rel)); |
261 | 278 | CBDB_TRY(); |
262 | | - { pax::CCPaxAuxTable::PaxAuxRelationCopyDataForCluster(old_heap, new_heap); } |
| 279 | + { |
| 280 | + // if false and OldIndex is InvalidOid, no sorting is performed, just copy |
| 281 | + if (!use_sort && old_index == NULL) { |
| 282 | + pax::CCPaxAuxTable::PaxAuxRelationCopyDataForCluster(old_rel, new_rel); |
| 283 | + return; |
| 284 | + } |
| 285 | + |
| 286 | + // TODO(gongxun): should we support index's order to cluster table? ao/aocs |
| 287 | + // does not support. |
| 288 | + |
| 289 | + // like aocs, pax tables can only be clustered against a btree index |
| 290 | + CBDB_CHECK(old_index && (old_index->rd_rel->relam == BTREE_AM_OID), |
| 291 | + cbdb::CException::kExTypeInvalidIndexType, |
| 292 | + "PAX tables can only be clustered against a btree index"); |
| 293 | + pax::IndexCluster(old_rel, new_rel, old_index, GetActiveSnapshot()); |
| 294 | + } |
263 | 295 | CBDB_CATCH_DEFAULT(); |
264 | 296 | CBDB_FINALLY({}); |
265 | 297 | CBDB_END_TRY(); |
|
0 commit comments