Thread: Is there anyway to get list of table name, before raw parser is analyze?
Is there anyway to get list of table name, before raw parser is analyze?
From
Mohammad Heykal Abdillah
Date:
Hi all, Right now i am trying to understand how SQL parser is work. My question is there anyway to get list of table name and its atribut before raw parser is analyze? Because i like to understand how PostgreSQL "break-down" the asterik at target list, specialy in "natural join" case where PostgreSQL can give query result that have unabigous attribut and match the right join key. Thank You. -- Mohammad Heykal Abdillah <heykal.abdillah@gmail.com>
Re: Is there anyway to get list of table name, before raw parser is analyze?
From
Andrew Dunstan
Date:
Mohammad Heykal Abdillah wrote: > Hi all, > > Right now i am trying to understand how SQL parser is work. > > My question is there anyway to get list of table name and its atribut > before raw parser is analyze? > > Because i like to understand how PostgreSQL "break-down" the asterik at > target list, specialy in "natural join" case where PostgreSQL can give > query result that have unabigous attribut and match the right join key. > > > AIUI, expanding '*' is not done in the parser. The parser just makes an A_star node. See src/backend/gram.y for the parser spec. Maybe you need to explain what exactly you're trying to do. cheers andrew
Re: Is there anyway to get list of table name, before raw parser is analyze?
From
Mohammad Heykal Abdillah
Date:
On Min, 2010-05-30 at 00:44 -0400, Andrew Dunstan wrote: > > Mohammad Heykal Abdillah wrote: > > Hi all, > > > > Right now i am trying to understand how SQL parser is work. > > > > My question is there anyway to get list of table name and its atribut > > before raw parser is analyze? > > > > Because i like to understand how PostgreSQL "break-down" the asterik at > > target list, specialy in "natural join" case where PostgreSQL can give > > query result that have unabigous attribut and match the right join key. > > > > > > > > AIUI, expanding '*' is not done in the parser. The parser just makes an > A_star node. > > See src/backend/gram.y for the parser spec. > > Maybe you need to explain what exactly you're trying to do. > > cheers > > andrew Yes that i know, expanding '*' is done in analyzer part. I am try to do is, move the expanding process to "before" raw_parser that produce by gram.y is processed by analyzer. Like this : sql query -> gram.y -> raw_parse_tree -> (expand the '*') -> analyze In this way analyzer part only receiving the expanded '*' parse tree they wont expand the '*' again. I am aksing this because i didnt know how to (analyzer) scan database so it can return list of attribut from table. I have read the source code, and try manualy to replicate the process (from what i got is the RTE function) with no result. Thank You. -- Mohammad Heykal Abdillah <heykal.abdillah@gmail.com>
Re: Is there anyway to get list of table name, before raw parser is analyze?
From
Andrew Dunstan
Date:
Mohammad Heykal Abdillah wrote: > On Min, 2010-05-30 at 00:44 -0400, Andrew Dunstan wrote: > >> Mohammad Heykal Abdillah wrote: >> >>> Hi all, >>> >>> Right now i am trying to understand how SQL parser is work. >>> >>> My question is there anyway to get list of table name and its atribut >>> before raw parser is analyze? >>> >>> Because i like to understand how PostgreSQL "break-down" the asterik at >>> target list, specialy in "natural join" case where PostgreSQL can give >>> query result that have unabigous attribut and match the right join key. >>> >>> >>> >>> >> AIUI, expanding '*' is not done in the parser. The parser just makes an >> A_star node. >> >> See src/backend/gram.y for the parser spec. >> >> Maybe you need to explain what exactly you're trying to do. >> >> cheers >> >> andrew >> > > Yes that i know, expanding '*' is done in analyzer part. I am try to do > is, move the expanding process to "before" raw_parser that produce by > gram.y is processed by analyzer. Like this : > > sql query -> gram.y -> raw_parse_tree -> (expand the '*') -> analyze > > In this way analyzer part only receiving the expanded '*' parse tree > they wont expand the '*' again. I am aksing this because i didnt know > how to (analyzer) scan database so it can return list of attribut from > table. I have read the source code, and try manualy to replicate the > process (from what i got is the RTE function) with no result. > > Ok, but why? What are you trying to achieve? cheers andrew
Re: Is there anyway to get list of table name, before raw parser is analyze?
From
Mohammad Heykal Abdillah
Date:
On Min, 2010-05-30 at 07:57 -0400, Andrew Dunstan wrote: > > Yes that i know, expanding '*' is done in analyzer part. I am try to do > > is, move the expanding process to "before" raw_parser that produce by > > gram.y is processed by analyzer. Like this : > > > > sql query -> gram.y -> raw_parse_tree -> (expand the '*') -> analyze > > > > In this way analyzer part only receiving the expanded '*' parse tree > > they wont expand the '*' again. I am aksing this because i didnt know > > how to (analyzer) scan database so it can return list of attribut from > > table. I have read the source code, and try manualy to replicate the > > process (from what i got is the RTE function) with no result. > > > > > > Ok, but why? What are you trying to achieve? > > I try to implement parser some modified SQL, let's say SQL in my native language. So far i have make new gram.y structure that worked in my case. I have manualy form some raw parser tree, and it work. My problem is in my modified SQL spesification the "from clause" and "where clause (at part join key relation)" was eliminated for farious reason. So my modified SQL rely on "scanning" the whole database to find all table and its attribut then projected the result as defined in "select clause". But since i dont know how to scan the whole database to get relation name and attribut name, i cant implement it. By the way this is for my personal interest, so if you cant help that's ok. But if you can help, i realy realy appreciated it. Thank You. -- Mohammad Heykal Abdillah <heykal.abdillah@gmail.com>
Mohammad Heykal Abdillah <heykal.abdillah@gmail.com> writes: > Yes that i know, expanding '*' is done in analyzer part. I am try to do > is, move the expanding process to "before" raw_parser that produce by > gram.y is processed by analyzer. Like this : > sql query -> gram.y -> raw_parse_tree -> (expand the '*') -> analyze This seems fundamentally misguided. Using semantic knowledge from the system catalogs to interpret the raw parse tree is exactly what the analyze step is for. You can't move part of that operation to a separate pass without complicating matters a lot, and probably breaking some subtle considerations such as when to first obtain locks. Why don't you just modify parse analysis to do whatever it is you had in mind to do differently? regards, tom lane