Re: add modulo (%) operator to pgbench - Mailing list pgsql-hackers

From Mitsumasa KONDO
Subject Re: add modulo (%) operator to pgbench
Date
Msg-id CADupcHUHTQnB6XPECXX7Pu2=SffzemO6Aku4iObH19rc+k3D_g@mail.gmail.com
Whole thread Raw
In response to Re: add modulo (%) operator to pgbench  (Mitsumasa KONDO <kondo.mitsumasa@gmail.com>)
Responses Re: add modulo (%) operator to pgbench  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
Hi,

Here is the review result.

#1. Patch compatibility
Little bit hunk, but it can patch to latest master.

#2. Functionality
No problem.

#3. Documentation
I think modulo operator explanation should put at last at the doc line.
Because the others are more frequently used.

#4. Algorithm 
You proposed three modulo algorithm, that are 
1. general modulo, 2. floor modulo and 3. euclidian modulo.

They calculate different value when modulo2 or reminder is negative number.
Calculate examples are here, 

1. general modulo (patch1)
    5 %  3 = 2
    5 % -3 = 1
   -5 %  3 = -1

2. floor modulo (patch2, 3)
   5 %  3  =  2
   5 % -3  = -2
  -5 %  3  =  2

3. euclidian modulo (patch2)
   5 %  3  =  2
   5 % -3  =  4
  -5 %  3  =  2

That's all.

I think if we want to create equal possibility and inutuitive random generator, we select floor modulo, as you see the upper example. It can create contrapositive random number. 1 and 2 method cannot.

I think euclidian modulo doesn't need by a lot of people. If we add it, many people will confuse, because they doesn't know the mathematic algorithms.
 
So I like patch3 which is simple and practical.

If you agree or reply my comment, I will mark ready for commiter.

Best Regards,
--
Mitsumsasa KONDO

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: gist vacuum gist access
Next
From: Etsuro Fujita
Date:
Subject: Re: Optimization for updating foreign tables in Postgres FDW