~Parent #1293~
The field rank should show the last position (rank = 102) and default value should be null
rank = 1
Execute npm run mocha test/functional/system/blocks/chain.deleteLastBlock.js on 1.0.0 branch with only (type 2) register delegate
Technically, rank is working exactly as it should be (with regards to the query).
Because rank is calculated by row_number() OVER (ORDER BY a."vote" DESC, a."publicKey" ASC)::int the row_number() will be calculated for each row in the query result set. So if the query asks for 101 accounts, they will each get a row_number() between 1 and 101.
But if the query is limited to a single account where address = 'BLAH' then row_number() will return 1 since it is the only row in the result set - and therefore it's rank will also be 1.
Some potential approaches you can take to resolving this, listed in order of my preference:
Thanks @robladbrook for the detailed list, we will go with option 2 for now.
If the query is very slow and impacts the overall performance, we can study apply part of the solution reverted by https://github.com/LiskHQ/lisk/pull/1225
Most helpful comment
Technically, rank is working exactly as it should be (with regards to the query).
Because rank is calculated by
row_number() OVER (ORDER BY a."vote" DESC, a."publicKey" ASC)::intthe row_number() will be calculated for each row in the query result set. So if the query asks for 101 accounts, they will each get a row_number() between 1 and 101.But if the query is limited to a single account
where address = 'BLAH'then row_number() will return 1 since it is the only row in the result set - and therefore it's rank will also be 1.Some potential approaches you can take to resolving this, listed in order of my preference: