don-tay / simpledb

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

Bug bounty Lab 1: non equality predicates #33

Closed tishyakhanna97 closed 2 years ago

tishyakhanna97 commented 2 years ago

Lab 1

Check if non equality predicates work fine:

don-tay commented 2 years ago

Test queries

select sid,sname from student where sid=1
select sid,sname from student where sname='a'
select sid,sname from student where sid=sname
select sid,sname from student where sid>1
select sid,sname from student where sid<=1
select sid,sname from student where sname>='a'

Queries throwing error:

select sid,sname from student where sid='a'
select sid,sname from student where sid<sname
java.lang.NullPointerException: Cannot read field "value" because "anotherInteger" is null
        at java.base/java.lang.Integer.compareTo(Integer.java:1461)
        at simpledb.query.Constant.compareTo(Constant.java:36)
        at simpledb.query.Term.isTermSatisfied(Term.java:76)
        at simpledb.query.Term.isSatisfied(Term.java:37)
        at simpledb.query.Predicate.isSatisfied(Predicate.java:49)
        at simpledb.query.SelectScan.next(SelectScan.java:35)
        at simpledb.query.ProjectScan.next(ProjectScan.java:32)
        at test.SimpleIJ.doQuery(SimpleIJ.java:71)
        at test.SimpleIJ.main(SimpleIJ.java:39)
don-tay commented 2 years ago

Error above is caused by searching for string in an integer column. In postgres, this error is thrown as such

ERROR:  invalid input syntax for type integer: "a"
LINE 1: select sid,sname from student where sid='a';
                                                ^
don-tay commented 2 years ago

I think we can leave the error queries as it is, since postgres is not explicit about what causes the error too

tishyakhanna97 commented 2 years ago

@don-tay maybe can test non eq predicates when comparing diff tables as well

don-tay commented 2 years ago

Test queries for predicates in fields between different tables:

select sid, sname, eid from student, enroll where sid<studentid
select sid, sname, eid from student, enroll where sid<eid

Invalid queries (throwing error as expected)

select sid, sname, eid from student, enroll where sname<eid
don-tay commented 2 years ago

Following query not behaving as expected:

select sid,sname from student where sid!=1
index on sid used
 sid sname
----------
transaction 2 committed
select sid,sname from student where sid<>1    
index on sid used
 sid sname
----------
transaction 2 committed
don-tay commented 2 years ago

However, following query works:

select sid,sname from student where sname<>'a'
select eid from enroll where eid != 1

After a btree idx is created on enroll(eid), the above query gives incorrect result (empty table).

tishyakhanna97 commented 2 years ago

@don-tay Same finding while testing indexes. However, I think this is a bonus https://github.com/don-tay/simpledb/issues/34#issuecomment-1068730139

don-tay commented 2 years ago

Thanks Tishya, I will implement defaulting to a seq scan for non-equi pred

EDIT: PR #40

tishyakhanna97 commented 2 years ago

good to close? @don-tay