Re: popcount

Поиск
Список
Период
Сортировка
Искать
От
Daniel Verite
Тема
Re: popcount
Дата
Msg-id
5ea2932e-50f5-4a74-9550-5e3291b6652b@manitou-mail.org
Ответ на
popcount (David Fetter)
Список
Дерево обсуждения
popcount David Fetter <david@fetter.org>
Re: popcount "Daniel Verite" <daniel@manitou-mail.org>
Re: popcount David Fetter <david@fetter.org>
Re: popcount Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Re: popcount David Fetter <david@fetter.org>
Re: popcount Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Re: popcount Tom Lane <tgl@sss.pgh.pa.us>
Re: popcount David Fetter <david@fetter.org>
Re: popcount Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Re: popcount Robert Haas <robertmhaas@gmail.com>
Re: popcount David Fetter <david@fetter.org>
Re: popcount Isaac Morland <isaac.morland@gmail.com>
Re: popcount "Daniel Verite" <daniel@manitou-mail.org>
	David Fetter wrote:

+Datum
+byteapopcount(PG_FUNCTION_ARGS)
+{
+	bytea	*t1 = PG_GETARG_BYTEA_PP(0);
+	int		len, result;
+
+	len = VARSIZE_ANY_EXHDR(t1);
+	result = pg_popcount(VARDATA_ANY(t1), len);
+
+	PG_RETURN_INT32(result);
+}

The input may have more than 2 billion bits set to 1. The biggest possible
result should be 8 billion for bytea (1 GB with all bits set to 1).
So shouldn't this function return an int8?

There is a pre-existing function in core: bit_length(bytea) returning int4,
but it errors out for large values (in fact it's a SQL function that returns
octet_length($1)*8).

For the varbit case, it doesn't seem like it can hold so many bits, although
I don't see the limit documented in
https://www.postgresql.org/docs/current/datatype-bit.html


Best regards,
-- 
Daniel Vérité
PostgreSQL-powered mailer: https://www.manitou-mail.org
Twitter: @DanielVerite


В списке pgsql-hackers по дате отправления
От: Stephen Frost
Дата:
От: David Fetter
Дата:
Сообщение: Re: popcount
FAQ