Skip to content

kishida/sqlparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

60 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

sqlparser

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,ใ‚ญใƒฃใƒ™ใƒ„,้‡Ž่œ]

About

tiny sql parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages