don-tay / simpledb

Subset of SQL-compliant DBMS
0 stars 0 forks source link

Bug: Empty results in input tables throwing error #21

Closed don-tay closed 2 years ago

don-tay commented 2 years ago

When a source table is empty, the following operations will throw an error:

  1. Join (except nested loop join)
  2. Cross product
  3. Sort

This is caused by the implementation in their respective scans (ie. SortScan, ProductScan, IndexJoinScan)

For MergeJoinScan, it uses SortScan as an intermediate step. Hence, it should be fixed when SortScan is resolved.

Sample queries: 1: Sort scan

select sname from student where sname='mary' order by sname

2: Product scan

select sname from student, enroll where sname='mary'

3: Joins (ie. merge join)

select eid, sectid from enroll, section where sectionid=sectid and prof='abc'
  1. Index-join (may need to comment out other joins due to bug in #14 )
    select sname from student, enroll where studentid=sid and sname='mary'

Sample error:

SQL> select eid, sectid from enroll, section where sectionid=sectid and prof='abc'
Running sort merge
 eid sectid
-----------
SQL Exception: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
don-tay commented 2 years ago

22 fixes 1,3,4 RESOLVED: but 2 is still not fixed:

SQL> select sname from student, enroll where sname='mary'
 sname
------
SQL Exception: java.lang.IllegalArgumentException: newPosition < 0: (-22 < 0)