2
0

Prefer binary format for arrays

This improves performance decoding text[].
This commit is contained in:
Jack Christensen
2023-02-10 20:21:25 -06:00
parent 1f43e2e490
commit 4484831550
2 changed files with 18 additions and 1 deletions
+10 -1
View File
@@ -47,7 +47,16 @@ func (c *ArrayCodec) FormatSupported(format int16) bool {
}
func (c *ArrayCodec) PreferredFormat() int16 {
return c.ElementType.Codec.PreferredFormat()
// The binary format should always be preferred for arrays if it is supported. Usually, this will happen automatically
// because most types that support binary prefer it. However, text, json, and jsonb support binary but prefer the text
// format. This is because it is simpler for jsonb and PostgreSQL can be significantly faster using the text format
// for text-like data types than binary. However, arrays appear to always be faster in binary.
//
// https://www.postgresql.org/message-id/CAMovtNoHFod2jMAKQjjxv209PCTJx5Kc66anwWvX0mEiaXwgmA%40mail.gmail.com
if c.ElementType.Codec.FormatSupported(BinaryFormatCode) {
return BinaryFormatCode
}
return TextFormatCode
}
func (c *ArrayCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan {