@@ -199,7 +199,6 @@ bool IndexScanExecutor::ExecPrimaryIndexLookup() {
199
199
auto current_txn = executor_context_->GetTransaction ();
200
200
auto &manager = catalog::Manager::GetInstance ();
201
201
std::vector<ItemPointer> visible_tuple_locations;
202
- std::map<oid_t , std::vector<oid_t >> visible_tuples;
203
202
204
203
#ifdef LOG_TRACE_ENABLED
205
204
int num_tuples_examined = 0 ;
@@ -326,27 +325,53 @@ bool IndexScanExecutor::ExecPrimaryIndexLookup() {
326
325
LOG_TRACE (" %ld tuples after pruning boundaries" ,
327
326
visible_tuple_locations.size ());
328
327
328
+ // Add the tuple locations to the result vector in the order returned by
329
+ // the index scan. We might end up reading the same tile group multiple
330
+ // times. However, this is necessary to adhere to the ORDER BY clause
331
+ oid_t current_tile_group_oid = INVALID_OID;
332
+ std::vector<oid_t > tuples;
333
+
329
334
for (auto &visible_tuple_location : visible_tuple_locations) {
330
- visible_tuples[visible_tuple_location.block ]
331
- .push_back (visible_tuple_location.offset );
332
- }
335
+ if (current_tile_group_oid == INVALID_OID) {
336
+ current_tile_group_oid = visible_tuple_location.block ;
337
+ }
338
+ if (current_tile_group_oid == visible_tuple_location.block ) {
339
+ tuples.push_back (visible_tuple_location.offset );
340
+ } else {
341
+ // Since the tile_group_oids differ, fill in the current tile group
342
+ // into the result vector
343
+ auto &manager = catalog::Manager::GetInstance ();
344
+ auto tile_group = manager.GetTileGroup (current_tile_group_oid);
345
+ std::unique_ptr<LogicalTile> logical_tile (LogicalTileFactory::GetTile ());
346
+ // Add relevant columns to logical tile
347
+ logical_tile->AddColumns (tile_group, full_column_ids_);
348
+ logical_tile->AddPositionList (std::move (tuples));
349
+ if (column_ids_.size () != 0 ) {
350
+ logical_tile->ProjectColumns (full_column_ids_, column_ids_);
351
+ }
352
+ result_.push_back (logical_tile.release ());
333
353
334
- // Construct a logical tile for each block
335
- for (auto tuples : visible_tuples) {
336
- auto &manager = catalog::Manager::GetInstance ();
337
- auto tile_group = manager.GetTileGroup (tuples.first );
354
+ // Change the current_tile_group_oid and add the current tuple
355
+ tuples.clear ();
356
+ current_tile_group_oid = visible_tuple_location.block ;
357
+ tuples.push_back (visible_tuple_location.offset );
358
+ }
359
+ }
338
360
361
+ // Add the remaining tuples to the result vector
362
+ if ((current_tile_group_oid != INVALID_OID) && (!tuples.empty ())) {
363
+ auto tile_group = manager.GetTileGroup (current_tile_group_oid);
339
364
std::unique_ptr<LogicalTile> logical_tile (LogicalTileFactory::GetTile ());
340
365
// Add relevant columns to logical tile
341
366
logical_tile->AddColumns (tile_group, full_column_ids_);
342
- logical_tile->AddPositionList (std::move (tuples. second ));
367
+ logical_tile->AddPositionList (std::move (tuples));
343
368
if (column_ids_.size () != 0 ) {
344
369
logical_tile->ProjectColumns (full_column_ids_, column_ids_);
345
370
}
346
-
347
371
result_.push_back (logical_tile.release ());
348
372
}
349
373
374
+
350
375
done_ = true ;
351
376
352
377
LOG_TRACE (" Result tiles : %lu" , result_.size ());
@@ -408,7 +433,6 @@ bool IndexScanExecutor::ExecSecondaryIndexLookup() {
408
433
auto current_txn = executor_context_->GetTransaction ();
409
434
410
435
std::vector<ItemPointer> visible_tuple_locations;
411
- std::map<oid_t , std::vector<oid_t >> visible_tuples;
412
436
auto &manager = catalog::Manager::GetInstance ();
413
437
414
438
// Quickie Hack
@@ -567,24 +591,49 @@ bool IndexScanExecutor::ExecSecondaryIndexLookup() {
567
591
// Check whether the boundaries satisfy the required condition
568
592
CheckOpenRangeWithReturnedTuples (visible_tuple_locations);
569
593
594
+ // Add the tuple locations to the result vector in the order returned by
595
+ // the index scan. We might end up reading the same tile group multiple
596
+ // times. However, this is necessary to adhere to the ORDER BY clause
597
+ oid_t current_tile_group_oid = INVALID_OID;
598
+ std::vector<oid_t > tuples;
599
+
570
600
for (auto &visible_tuple_location : visible_tuple_locations) {
571
- visible_tuples[visible_tuple_location.block ]
572
- .push_back (visible_tuple_location.offset );
573
- }
601
+ if (current_tile_group_oid == INVALID_OID) {
602
+ current_tile_group_oid = visible_tuple_location.block ;
603
+ }
604
+ if (current_tile_group_oid == visible_tuple_location.block ) {
605
+ tuples.push_back (visible_tuple_location.offset );
606
+ } else {
607
+ // Since the tile_group_oids differ, fill in the current tile group
608
+ // into the result vector
609
+ auto &manager = catalog::Manager::GetInstance ();
610
+ auto tile_group = manager.GetTileGroup (current_tile_group_oid);
611
+ std::unique_ptr<LogicalTile> logical_tile (LogicalTileFactory::GetTile ());
612
+ // Add relevant columns to logical tile
613
+ logical_tile->AddColumns (tile_group, full_column_ids_);
614
+ logical_tile->AddPositionList (std::move (tuples));
615
+ if (column_ids_.size () != 0 ) {
616
+ logical_tile->ProjectColumns (full_column_ids_, column_ids_);
617
+ }
618
+ result_.push_back (logical_tile.release ());
574
619
575
- // Construct a logical tile for each block
576
- for (auto tuples : visible_tuples) {
577
- auto &manager = catalog::Manager::GetInstance ();
578
- auto tile_group = manager.GetTileGroup (tuples.first );
620
+ // Change the current_tile_group_oid and add the current tuple
621
+ tuples.clear ();
622
+ current_tile_group_oid = visible_tuple_location.block ;
623
+ tuples.push_back (visible_tuple_location.offset );
624
+ }
625
+ }
579
626
627
+ // Add the remaining tuples (if any) to the result vector
628
+ if ((current_tile_group_oid != INVALID_OID) && (!tuples.empty ())) {
629
+ auto tile_group = manager.GetTileGroup (current_tile_group_oid);
580
630
std::unique_ptr<LogicalTile> logical_tile (LogicalTileFactory::GetTile ());
581
631
// Add relevant columns to logical tile
582
632
logical_tile->AddColumns (tile_group, full_column_ids_);
583
- logical_tile->AddPositionList (std::move (tuples. second ));
633
+ logical_tile->AddPositionList (std::move (tuples));
584
634
if (column_ids_.size () != 0 ) {
585
635
logical_tile->ProjectColumns (full_column_ids_, column_ids_);
586
636
}
587
-
588
637
result_.push_back (logical_tile.release ());
589
638
}
590
639
@@ -663,19 +712,6 @@ bool IndexScanExecutor::CheckKeyConditions(const ItemPointer &tuple_location) {
663
712
// To make the procedure more uniform, we interpret IN as EQUAL
664
713
// and NOT IN as NOT EQUAL, and react based on expression type below
665
714
// accordingly
666
- /* if (expr_type == ExpressionType::COMPARE_IN) {
667
- bool bret = lhs.InList(rhs);
668
-
669
- if (bret == true) {
670
- diff = VALUE_COMPARE_EQUAL;
671
- } else {
672
- diff = VALUE_COMPARE_NO_EQUAL;
673
- }
674
- } else {
675
- diff = lhs.Compare(rhs);
676
- }
677
-
678
- LOG_TRACE("Difference : %d ", diff);*/
679
715
if (lhs.CompareEquals (rhs) == CmpBool::TRUE ) {
680
716
switch (expr_type) {
681
717
case ExpressionType::COMPARE_EQUAL:
0 commit comments