Search code examples
monetdb

Bitwise operations in Monetdb


I am new to Monetdb. I am using Postgresql mainly, but want to check Monetdb performace. In Postres I have column of type bit() filled with 0s and 1s. Then I am comparing each row to all other rows with bitwise AND on that column. Monetdb does not have bit() type so I used text. Any ideas how to do bitwise AND in monetdb and what type of column should I use for this? The query I tried:

select a.sentenecid, b.sentenecid, a.sentence AND b.sentence from test a, test b;

Solution

  • Monetdb supports bitwise operators for integer datatype through the calculator module, as documented here.

    So, you would just have to declare your column as integer, and use the bitwise operators &, |, ^, <<, >> in your SQL queries.

    For example, as tested with monetdb version Jul2015-SP2 :

    // bitwise AND. Result = 1
    Select 1 & 3; 
    
    // bitwise OR. Result = 3
    Select 1 | 3;    
    
    // bitwise XOR. Result = 2
    Select 1 ^ 3;    
    
    // Left bit shift. Result = 4
    Select 2 << 1;    
    
    // Right bit shift. Result = 1
    Select 2 >> 1;