diff --git a/sql/binlog.cc b/sql/binlog.cc index 6d4a8b8c2fd..4095aa35d05 100644 --- a/sql/binlog.cc +++ b/sql/binlog.cc @@ -2055,20 +2055,26 @@ bool binlog_cache_data::compress(THD *thd) { compressor->close(); - if ((error = m_cache.truncate(0))) goto compression_end; - // Since we deleted all events from the cache, we also need to - // reset event_counter. - event_counter = 0; // fill in the new transport event std::tie(buffer, size, std::ignore) = compressor->get_buffer(); - tple.set_payload((const char *)buffer); - tple.set_payload_size(size); - tple.set_compression_type(ctype); - tple.set_uncompressed_size(uncompressed_size); + if (likely(size < uncompressed_size)) { + tple.set_payload((const char *)buffer); + tple.set_payload_size(size); + tple.set_compression_type(ctype); + tple.set_uncompressed_size(uncompressed_size); + + // write back the new cache contents + if ((error = m_cache.truncate(0))) goto compression_end; + // Since we deleted all events from the cache, we also need to + // reset event_counter. + event_counter = 0; + error = write_event(&tple); + } else { + ctype = binary_log::transaction::compression::type::NONE; + assert(m_cache.length() == uncompressed_size); + } - // write back the new cache contents - error = write_event(&tple); compression_end: // revert back to the default buffer, so that we don't overuse memory