Skip to content

snowFlakeID #6

@bvt123

Description

@bvt123

The scheduler uses a tuple(now64(),rowNumberInAllBlocks) to build a unique ID for coming events.
It's UInt64+UInt32. It could be done better by using SnowFlakeId (Int64). 22 bits is enough for operating 4M row blocks. for 1M blocks, we have space for 4 different cluster nodes.

create function toSnowflake64 as (dt,ch) ->
  bitOr(dateTime64ToSnowflake(dt),
   bitAnd(bitAnd(ch,0x3FFFFF)+
      bitAnd(bitShiftRight(ch, 20),0x3FFFFF)+
      bitAnd(bitShiftRight(ch, 40),0x3FFFFF),
      0x3FFFFF) 
  );

with rowNumberInAllBlocks() as rn,
  now64() as dt
SELECT hex(toSnowflake64(dt,rn) as sn),
  snowflakeToDateTime64(sn) 
from numbers(10);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions