Hi there!
We are using Aerospike 5.2.0.12 and have a task to return all user keys(the expected number is about 2 million) by filter (cityName = London) and then process them using Java code. I can see two ways to do it:
- via scan
ScanPolicy scanPolicy = new ScanPolicy(aerospikeClient.getQueryPolicyDefault());
scanPolicy.filterExp = Exp.build(Exp.eq(Exp.stringBin("cityName"), Exp.val("London")));
scanPolicy.includeBinData = false;
scanPolicy.recordsPerSecond = 50000;
aerospikeClient.scanAll(scanPolicy, aerospikeTemplate.getNamespace(), "users-set", (key, record) -> executeSomeLogic(key.userKey));
- via query
QueryPolicy queryPolicy = new QueryPolicy(aerospikeClient.getQueryPolicyDefault());
queryPolicy.filterExp = Exp.build(Exp.eq(Exp.stringBin("cityName"), Exp.val("London")));
queryPolicy.includeBinData = false;
Statement statement = new Statement();
statement.setNamespace(aerospikeTemplate.getNamespace());
statement.setSetName("users-set");
statement.setRecordsPerSecond(50000);
RecordSet result = aerospikeClient.query(queryPolicy, statement);
result.forEach(keyRecord -> executeSomeLogic(keyRecord.key.userKey));
Do these two approaches have the same effectiveness and efficiency? Will the entire namespace be scanned in both cases? Is there any difference between them?