Skip to content

Commit a6d68cd

Browse files
akscjoAmit Chauhan
andauthored
Added some changes to read query (#11)
Co-authored-by: Amit Chauhan <[email protected]>
1 parent b06e393 commit a6d68cd

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/main/java/com/yugabyte/simulation/service/GenericWorkload.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,56 @@ private void seedData(int numberToGenerate, int threads) {
216216
});
217217
}
218218

219+
220+
/*
221+
Assume some number of ranges: 64 (does not really have to map to number of tablets)
222+
From each range get these many rows: 10K rows needed DIVIDED BY num_ranges --> ~156 rows/range.
223+
From these 64 hash code ranges, now ask for 156 rows each.
224+
225+
SELECT pkid FROM T where yb_hash_code(pkid) >= 0 and yb_hash_code(pkid) < 1024 LIMIT 156
226+
UNION ALL
227+
SELECT pkid FROM T where yb_hash_code(pkid) >= 1024 and yb_hash_code(pkid) < 2048 LIMIT 156
228+
..
229+
...
230+
UNION ALL
231+
SELECT pkid FROM T where yb_hash_code(pkid) >= 64512 and yb_hash_code(pkid) < 65536
232+
*/
233+
219234
private List<UUID> getQueryList() {
220235
List<UUID> results = new ArrayList<UUID>(ROWS_TO_PRELOAD);
236+
int numOfRanges = 64;
237+
int limit = ROWS_TO_PRELOAD/numOfRanges;
238+
int runningHashCodeVal = 0;
239+
StringBuffer sbQuery = new StringBuffer();
240+
241+
while(runningHashCodeVal < 65536){
242+
if(runningHashCodeVal != 0){
243+
sbQuery.append(" UNION ALL ");
244+
}
245+
int nextHashVal = runningHashCodeVal + 1024;
246+
sbQuery.append(" (SELECT pkid FROM generic1 where yb_hash_code(pkid) >= "+runningHashCodeVal+" and yb_hash_code(pkid) < "+nextHashVal+" LIMIT "+limit+") ");
247+
runningHashCodeVal = nextHashVal;
248+
}
249+
250+
251+
221252
jdbcTemplate.setMaxRows(ROWS_TO_PRELOAD);
222253
jdbcTemplate.setFetchSize(ROWS_TO_PRELOAD);
223-
jdbcTemplate.query("select pkid, yb_hash_code(pkid) from generic1 where yb_hash_code(pkid) % 7 = 0 limit " + ROWS_TO_PRELOAD,
254+
System.out.println("query:"+sbQuery.toString());
255+
jdbcTemplate.query(sbQuery.toString(),
224256
new RowCallbackHandler() {
225257
@Override
226258
public void processRow(ResultSet rs) throws SQLException {
227259
UUID value = (UUID)rs.getObject(1);
228260
results.add(value);
229261
}
230262
});
263+
264+
// System.out.println("list of pkids:");
265+
// for(UUID pkId: results){
266+
// System.out.print(pkId.toString()+",");
267+
// }
268+
231269
return results;
232270
}
233271

0 commit comments

Comments
 (0)