tiny sql parser
execute kis.sqlparser.SqlAnalizer
Table tshohin = new Table("shohin", Stream.of("id", "name", "bunrui_id", "price")
.map(s -> new Column(s)).collect(Collectors.toList()));
Table tbunrui = new Table("bunrui", Stream.of("id", "name", "seisen")
.map(s -> new Column(s)).collect(Collectors.toList()));
tbunrui
.insert(1, "้่", 1)
.insert(2, "ใใ ใใฎ", 1)
.insert(3, "่ๅญ", 2);
tshohin
.insert(1, "ใใใ", 2, 250)
.insert(2, "ใญใฃใใ", 1, 200)
.insert(3, "ใใใฎใใฎ", 3, 150)
.insert(4, "ใใฎใ", 3, 120)
.insert(5, "ใใฝใณใณ", 0, 34800);
result
select id, name from shohin where price between 130 and 200 or id=1
ๅๆใใฉใณ:select
<- filter[between shohin.price:130:200 or shohin.id = 1]
<- table[shohin]
่ซ็ๆ้ฉๅ:select
<- filter[between shohin.price:130:200 or shohin.id = 1]
<- table[shohin]
[1,ใใใ]
[2,ใญใฃใใ]
[3,ใใใฎใใฎ]
select id, name from shohin where price between 130 and 200
ๅๆใใฉใณ:select
<- filter[between shohin.price:130:200]
<- table[shohin]
่ซ็ๆ้ฉๅ:select
<- filter[between shohin.price:130:200]
<- table[shohin]
[2,ใญใฃใใ]
[3,ใใใฎใใฎ]
ๆฎ้ใฎJOIN
select shohin.id, shohin.name,bunrui.name
from shohin left join bunrui on shohin.bunrui_id=bunrui.id
ๅๆใใฉใณ:select
<- join(nested loop)
<- table[shohin]
/
<- table[bunrui]
่ซ็ๆ้ฉๅ:select
<- join(nested loop)
<- table[shohin]
/
<- table[bunrui]
[1,ใใใ,ใใ ใใฎ]
[2,ใญใฃใใ,้่]
[3,ใใใฎใใฎ,่ๅญ]
[4,ใใฎใ,่ๅญ]
[5,ใใฝใณใณ,null]
optimize
ๅธธใซ็ใชใฎใงๆกไปถ็็ฅ
select id, name from shohin where 2 < 3
ๅๆใใฉใณ:select
<- filter[2 < 3]
<- table[shohin]
่ซ็ๆ้ฉๅ:select
<- table[shohin]
[1,ใใใ]
[2,ใญใฃใใ]
[3,ใใใฎใใฎ]
[4,ใใฎใ]
[5,ใใฝใณใณ]
ๅธธใซๅฝใชใฎใง็ฉบใซใชใ
select id, name from shohin where price < 130 and 2 > 3
ๅๆใใฉใณ:select
<- filter[shohin.price < 130 and 2 > 3]
<- table[shohin]
่ซ็ๆ้ฉๅ:select
<- empty
<- table[shohin]
ใกใคใณใใผใใซใฎใฟใซ้ขไฟใฎใใๆกไปถใฏJOINใฎๅใซ้ฉ็จ
select shohin.id, shohin.name,bunrui.name
from shohin left join bunrui on shohin.bunrui_id=bunrui.id
where shohin.price <= 300 and bunrui.seisen=1
ๅๆใใฉใณ:select
<- filter[shohin.price <= 300 and bunrui.seisen = 1]
<- join(nested loop)
<- table[shohin]
/
<- table[bunrui]
่ซ็ๆ้ฉๅ:select
<- filter[bunrui.seisen = 1]
<- join(nested loop)
<- filter[shohin.price <= 300]
<- table[shohin]
/
<- table[bunrui]
[1,ใใใ,ใใ ใใฎ]
[2,ใญใฃใใ,้่]