[HACKERS] bitset counting as a user defined function in postgresql 9.2?

2013-08-24 Thread Kanarupan Kularatnarajah
As an initial attempt to try hands-on with postgresql, I've learned on user
created functions and some other internals of postgresql.

Few materials on postgresql indicate that the aggregate functions are slow
due to some internal reasons (index covering, null etc).

I'm looking forward to implement my own bit counting or counting mechanism
(I've gone through some bit twiddling as well) via user defined functions
(in C) and in cases I may need to create user defined data types as well.

Are there any possible scenarios where user defined count would perform
better than the underlying implementation? Is it worth a try?

And are there any better ways to evaluate, compare both? (other than
EXPLAIN ANALYZIS)

Please guide.

-- 
Regards,
K.Kanarupan
Undergraduate,
Dept. of Computer Science  Engineering
University of Moratuwa

Mobile:  +94 777 420 179


[HACKERS] What is the algorithm used for counting the set bit (number of ones) of a bitmap/bitarray/betset in postgresql?

2013-08-24 Thread Kanarupan Kularatnarajah
I've come across lookup tables, Hamming weights and Brain Kernighan's Algo.
Are they used (combined or separately) in bitmap counting?

Where can I find the coding and please explain the flow a count function
(for a bit counting) via coding rather than the high level architectural
diagrams (which I'm aware of).

I've noted using the below expression to count a particular bits (0 or 1
with minor modification). Could anyone explain at the coding level of
postgresql and what algorithms are used?

postgres= SELECT LENGTH( REPLACE( CAST( B'10100010'
AS TEXT ), '0', ''));


Regards,
K.Kanarupan
Undergraduate,k
Dept. of Computer Science  Engineering
University of Moratuwa

Mobile:  +94 777 420 179