Skip to content

Instantly share code, notes, and snippets.

@RunsFor
Last active March 27, 2019 15:07
Show Gist options
  • Save RunsFor/8942c87f8790c1e26412a216820b529f to your computer and use it in GitHub Desktop.
Save RunsFor/8942c87f8790c1e26412a216820b529f to your computer and use it in GitHub Desktop.
Count nil values in the index
box.cfg{}
statuses = { 'sent', 'delivered' }
uuid = require('uuid')
clock = require('clock')
box.schema.create_space('fragments')
box.space.fragments:create_index('pk')
box.space.fragments:create_index('status', { unique = false, parts = {{3, 'string', is_nullable = true}}})
for i =1,500000,1 do box.space.fragments:insert({i,uuid.str(), statuses[math.random(0,2)]}) end
box.space.fragments.index.status:count('sent') -- 166695
box.space.fragments.index.status:count('delivered') -- 166836
box.space.fragments.index.status:count({box.NULL}) -- 166469
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment