/* * Has the same signature as RelationGetAttributeCompressionFuncs() even though * we don't actually need the full Relation data structure. I deem consistency * of API more important in this case. */ PGFunction * RelationGetRelationCompressionFuncs(Relation rel) { AppendOnlyEntry *aoentry; char *comptype = NULL; PGFunction *compFuncs; if(RelationIsAoRows(rel) || RelationIsParquet(rel)){ aoentry = GetAppendOnlyEntry(RelationGetRelid(rel), SnapshotNow); comptype = aoentry->compresstype; } compFuncs = get_funcs_for_compression(comptype); return compFuncs; }
DatumStreamRead * create_datumstreamread( char *compName, int32 compLevel, bool checksum, int32 safeFSWriteSize, int32 maxsz, Form_pg_attribute attr, char *relname, char *title) { DatumStreamRead *acc = palloc0(sizeof(DatumStreamRead)); PGFunction *compressionFunctions; CompressionState *compressionState; acc->memctxt = CurrentMemoryContext; init_datumstream_info( &acc->typeInfo, &acc->datumStreamVersion, &acc->rle_can_have_compression, &acc->delta_can_have_compression, &acc->ao_attr, &acc->maxAoBlockSize, compName, compLevel, checksum, safeFSWriteSize, maxsz, attr); compressionFunctions = NULL; compressionState = NULL; if (acc->ao_attr.compress) { /* * BULK compression. */ compressionFunctions = get_funcs_for_compression(acc->ao_attr.compressType); if (compressionFunctions != NULL) { StorageAttributes sa; sa.comptype = acc->ao_attr.compressType; sa.complevel = acc->ao_attr.compressLevel; sa.blocksize = acc->maxAoBlockSize; compressionState = callCompressionConstructor( compressionFunctions[COMPRESSION_CONSTRUCTOR], NULL, &sa, false /* compress */ ); determine_datumstream_compression_overflow( &acc->ao_attr, compressionState->desired_sz, acc->maxAoBlockSize); } } AppendOnlyStorageRead_Init( &acc->ao_read, /* memoryContext */ NULL, acc->maxAoBlockSize, relname, title, &acc->ao_attr); acc->ao_read.compression_functions = compressionFunctions; acc->ao_read.compressionState = compressionState; acc->title = title; acc->blockFirstRowNum = 1; Assert(acc->blockFileOffset == 0); Assert(acc->blockRowCount == 0); DatumStreamBlockRead_Init( &acc->blockRead, &acc->typeInfo, acc->datumStreamVersion, acc->rle_can_have_compression, /* errdetailCallback */ datumstreamread_detail_callback, /* errdetailArg */ (void *) acc, /* errcontextCallback */ datumstreamread_context_callback, /* errcontextArg */ (void *) acc); Assert(acc->large_object_buffer == NULL); Assert(acc->large_object_buffer_size == 0); Assert(acc->largeObjectState == DatumStreamLargeObjectState_None); Assert(acc->eof == 0); Assert(acc->eofUncompress == 0); if (Debug_appendonly_print_scan) { if (!acc->ao_attr.compress) { ereport(LOG, (errmsg("Datum stream read %s created with NO bulk compression for %s" "(maximum Append-Only blocksize %d, " "checksum %s)", DatumStreamVersion_String(acc->datumStreamVersion), acc->title, acc->maxAoBlockSize, (acc->ao_attr.checksum ? "true" : "false")))); } else { ereport(LOG, (errmsg("Datum stream read %s created with bulk compression for %s " "(maximum Append-Only blocksize %d, " "compression type %s, compress level %d, " "checksum %s)", DatumStreamVersion_String(acc->datumStreamVersion), acc->title, acc->maxAoBlockSize, acc->ao_attr.compressType, acc->ao_attr.compressLevel, (acc->ao_attr.checksum ? "true" : "false")))); } } return acc; }
DatumStreamWrite * create_datumstreamwrite( char *compName, int32 compLevel, bool checksum, int32 safeFSWriteSize, int32 maxsz, Form_pg_attribute attr, char *relname, char *title) { DatumStreamWrite *acc = palloc0(sizeof(DatumStreamWrite)); int32 initialMaxDatumPerBlock; int32 maxDatumPerBlock; PGFunction *compressionFunctions; CompressionState *compressionState; CompressionState *verifyBlockCompressionState; init_datumstream_info( &acc->typeInfo, &acc->datumStreamVersion, &acc->rle_want_compression, &acc->delta_want_compression, &acc->ao_attr, &acc->maxAoBlockSize, compName, compLevel, checksum, safeFSWriteSize, maxsz, attr); compressionFunctions = NULL; compressionState = NULL; verifyBlockCompressionState = NULL; if (acc->ao_attr.compress) { /* * BULK compression. */ compressionFunctions = get_funcs_for_compression(acc->ao_attr.compressType); if (compressionFunctions != NULL) { TupleDesc td = CreateTupleDesc(1, false, &attr); StorageAttributes sa; sa.comptype = acc->ao_attr.compressType; sa.complevel = acc->ao_attr.compressLevel; sa.blocksize = acc->maxAoBlockSize; compressionState = callCompressionConstructor( compressionFunctions[COMPRESSION_CONSTRUCTOR], td, &sa, /* compress */ true); determine_datumstream_compression_overflow( &acc->ao_attr, compressionState->desired_sz, acc->maxAoBlockSize); if (gp_appendonly_verify_write_block) { verifyBlockCompressionState = callCompressionConstructor( compressionFunctions[COMPRESSION_CONSTRUCTOR], td, &sa, /* compress */ false); } } } AppendOnlyStorageWrite_Init( &acc->ao_write, /* memoryContext */ NULL, acc->maxAoBlockSize, relname, title, &acc->ao_attr); acc->ao_write.compression_functions = compressionFunctions; acc->ao_write.compressionState = compressionState; acc->ao_write.verifyWriteCompressionState = verifyBlockCompressionState; acc->title = title; /* * Temporarily set the firstRowNum for the block so that we can * calculate the correct header length. */ AppendOnlyStorageWrite_SetFirstRowNum(&acc->ao_write, 1); switch (acc->datumStreamVersion) { case DatumStreamVersion_Original: initialMaxDatumPerBlock = MAXDATUM_PER_AOCS_ORIG_BLOCK; maxDatumPerBlock = MAXDATUM_PER_AOCS_ORIG_BLOCK; acc->maxAoHeaderSize = AoHeader_Size( /* isLong */ false, checksum, /* hasFirstRowNum */ true); break; case DatumStreamVersion_Dense: case DatumStreamVersion_Dense_Enhanced: initialMaxDatumPerBlock = INITIALDATUM_PER_AOCS_DENSE_BLOCK; maxDatumPerBlock = MAXDATUM_PER_AOCS_DENSE_BLOCK; acc->maxAoHeaderSize = AoHeader_Size( /* isLong */ true, checksum, /* hasFirstRowNum */ true); break; default: ereport(ERROR, (errmsg("Unexpected datum stream version %d", acc->datumStreamVersion))); initialMaxDatumPerBlock = 0; /* Quiet down compiler. */ maxDatumPerBlock = 0; break; /* Never reached. */ } DatumStreamBlockWrite_Init( &acc->blockWrite, &acc->typeInfo, acc->datumStreamVersion, acc->rle_want_compression, acc->delta_want_compression, initialMaxDatumPerBlock, maxDatumPerBlock, acc->maxAoBlockSize - acc->maxAoHeaderSize, /* errdetailCallback */ datumstreamwrite_detail_callback, /* errdetailArg */ (void *) acc, /* errcontextCallback */ datumstreamwrite_context_callback, /* errcontextArg */ (void *) acc); return acc; }