MCPcopy Create free account
hub / github.com/dolthub/doltgresql / encodeInvertedIndexKeys

Method encodeInvertedIndexKeys

postgres/parser/json/json.go:763–785  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

761 return [][]byte{encoding.EncodeDecimalAscending(b, &dec)}, nil
762}
763func (j jsonArray) encodeInvertedIndexKeys(b []byte) ([][]byte, error) {
764 // Checking for an empty array.
765 if len(j) == 0 {
766 return [][]byte{encoding.EncodeJSONEmptyArray(b)}, nil
767 }
768
769 prefix := encoding.EncodeArrayAscending(b)
770 var outKeys [][]byte
771 for i := range j {
772 children, err := j[i].encodeInvertedIndexKeys(prefix[:len(prefix):len(prefix)])
773 if err != nil {
774 return nil, err
775 }
776 outKeys = append(outKeys, children...)
777 }
778
779 // Deduplicate the entries, since arrays can have duplicates - we don't want
780 // to emit duplicate keys from this method, as it's more expensive to
781 // deduplicate keys via KV (which will actually write the keys) than via SQL
782 // (just an in-memory sort and distinct).
783 outKeys = UniquifyByteSlices(outKeys)
784 return outKeys, nil
785}
786
787// UniquifyByteSlices takes as input a slice of slices of bytes, and
788// deduplicates them using a sort and unique. The output will not contain any

Callers 1

Calls 4

EncodeJSONEmptyArrayFunction · 0.92
EncodeArrayAscendingFunction · 0.92
UniquifyByteSlicesFunction · 0.85

Tested by

no test coverage detected