void AlterTableCreateAoBlkdirTable(Oid relOid, bool is_part_child) { Relation rel; TupleDesc tupdesc; IndexInfo *indexInfo; Oid classObjectId[3]; int16 coloptions[3]; /* * Grab an exclusive lock on the target table, which we will NOT release * until end of transaction. (This is probably redundant in all present * uses...) */ if (is_part_child) rel = heap_open(relOid, NoLock); else rel = heap_open(relOid, AccessExclusiveLock); if (!RelationIsAoRows(rel) && !RelationIsAoCols(rel)) { heap_close(rel, NoLock); return; } /* Create a tuple descriptor */ tupdesc = CreateTemplateTupleDesc(4, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "segno", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "columngroup_no", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 3, "first_row_no", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 4, "minipage", VARBITOID, -1, 0); /* * We don't want any toast columns here. */ tupdesc->attrs[0]->attstorage = 'p'; tupdesc->attrs[1]->attstorage = 'p'; tupdesc->attrs[2]->attstorage = 'p'; /* TODO (dmeister): In the next line, the index should have been 3. * Therefore the minipage might be toasted. */ tupdesc->attrs[2]->attstorage = 'p'; /* * Create index on segno, first_row_no. */ indexInfo = makeNode(IndexInfo); indexInfo->ii_NumIndexAttrs = 3; indexInfo->ii_KeyAttrNumbers[0] = 1; indexInfo->ii_KeyAttrNumbers[1] = 2; indexInfo->ii_KeyAttrNumbers[2] = 3; indexInfo->ii_Expressions = NIL; indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_Predicate = NIL; indexInfo->ii_PredicateState = NIL; indexInfo->ii_Unique = true; indexInfo->ii_Concurrent = false; classObjectId[0] = INT4_BTREE_OPS_OID; classObjectId[1] = INT4_BTREE_OPS_OID; classObjectId[2] = INT8_BTREE_OPS_OID; coloptions[0] = 0; coloptions[1] = 0; coloptions[2] = 0; (void) CreateAOAuxiliaryTable(rel, "pg_aoblkdir", RELKIND_AOBLOCKDIR, tupdesc, indexInfo, classObjectId, coloptions); heap_close(rel, NoLock); }
void AlterTableCreateAoSegTable(Oid relOid, bool is_part_child, bool is_part_parent) { TupleDesc tupdesc; Relation rel; const char *prefix; /* * Grab an exclusive lock on the target table, which we will NOT release * until end of transaction. (This is probably redundant in all present * uses...) */ if (is_part_child) rel = heap_open(relOid, NoLock); else rel = heap_open(relOid, AccessExclusiveLock); if(RelationIsAoRows(rel)) { prefix = "pg_aoseg"; /* this is pretty painful... need a tuple descriptor */ tupdesc = CreateTemplateTupleDesc(8, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "segno", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "eof", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 3, "tupcount", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 4, "varblockcount", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 5, "eofuncompressed", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 6, "modcount", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 7, "formatversion", INT2OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 8, "state", INT2OID, -1, 0); } else if (RelationIsAoCols(rel)) { prefix = "pg_aocsseg"; /* * XXX * At this moment, we hardwire the rel aocs info. * Essentially, we assume total vertical partition, and * we do not do datatype specific compression. * * In order to make things right, we need to first fix * the DefineRelation, so that we store the per column * info, then, we need to open the catalog, pull out * info here. */ /* * XXX We do not handle add/drop column etc nicely yet. */ /* * Assuming full vertical partition, we want to include * the following in the seg table. * * segno int, -- whatever purpose ao use it * tupcount bigint -- total tup * varblockcount bigint, -- total varblock * vpinfo varbinary(max) -- vertical partition info encoded in * binary. NEEDS TO BE REFACTORED * INTO MULTIPLE COLUMNS!! * state (smallint) -- state of the segment file */ tupdesc = CreateTemplateTupleDesc(7, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "segno", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "tupcount", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 3, "varblockcount", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 4, "vpinfo", BYTEAOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 5, "modcount", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 6, "formatversion", INT2OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 7, "state", INT2OID, -1, 0); } else { heap_close(rel, NoLock); return; } (void) CreateAOAuxiliaryTable(rel, prefix, RELKIND_AOSEGMENTS, tupdesc, NULL, NIL, NULL, NULL, is_part_parent); heap_close(rel, NoLock); }
void AlterTableCreateAoVisimapTable(Oid relOid, bool is_part_child) { Relation rel; IndexInfo *indexInfo; TupleDesc tupdesc; Oid classObjectId[2]; int16 coloptions[2]; elogif(Debug_appendonly_print_visimap, LOG, "Create visimap for relation %d", relOid); /* * Grab an exclusive lock on the target table, which we will NOT release * until end of transaction. (This is probably redundant in all present * uses...) */ if (is_part_child) rel = heap_open(relOid, NoLock); else rel = heap_open(relOid, AccessExclusiveLock); if (!RelationIsAoRows(rel) && !RelationIsAoCols(rel)) { heap_close(rel, NoLock); return; } /* Create a tuple descriptor */ tupdesc = CreateTemplateTupleDesc(Natts_pg_aovisimap, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "segno", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "first_row_no", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 3, "visimap", BYTEAOID, -1, 0); /* * We don't want any toast columns here. */ tupdesc->attrs[0]->attstorage = 'p'; tupdesc->attrs[1]->attstorage = 'p'; tupdesc->attrs[2]->attstorage = 'p'; /* * Create index on segno, first_row_no. */ indexInfo = makeNode(IndexInfo); indexInfo->ii_NumIndexAttrs = 2; indexInfo->ii_KeyAttrNumbers[0] = 1; indexInfo->ii_KeyAttrNumbers[1] = 2; indexInfo->ii_Expressions = NIL; indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_Predicate = NIL; indexInfo->ii_PredicateState = NIL; indexInfo->ii_Unique = true; indexInfo->ii_Concurrent = false; classObjectId[0] = INT4_BTREE_OPS_OID; classObjectId[1] = INT8_BTREE_OPS_OID; coloptions[0] = 0; coloptions[1] = 0; (void) CreateAOAuxiliaryTable(rel, "pg_aovisimap", RELKIND_AOVISIMAP, tupdesc, indexInfo, classObjectId, coloptions); heap_close(rel, NoLock); }