Re: Extending PostgreSQL with a Domain-Specific Language (DSL) -Development - Mailing list pgsql-hackers

From Tomas Vondra
Subject Re: Extending PostgreSQL with a Domain-Specific Language (DSL) -Development
Date
Msg-id 20190705184845.zxdddxwyufcw3b5h@development
Whole thread Raw
In response to Extending PostgreSQL with a Domain-Specific Language (DSL) -Development  (Tom Mercha <mercha_t@hotmail.com>)
Responses Re: Extending PostgreSQL with a Domain-Specific Language (DSL) -Development  (Tom Mercha <mercha_t@hotmail.com>)
List pgsql-hackers
On Fri, Jul 05, 2019 at 07:55:15AM +0000, Tom Mercha wrote:
>Dear Hackers
>
>I am interested in implementing my own Domain Specific Language (DSL)
>using PostgreSQL internals. Originally, the plan was not to use
>PostgreSQL and I had developed a grammar and used ANTLRv4 for parser
>work and general early development.
>
>Initially, I was hoping for a scenario where I could have PostgreSQL's
>parser to change grammar (e.g. SET parser_language=SQL vs. SET
>parser_language=myDSL) in which case my ANTLRv4 project would override
>the PostgreSQL parser module. I guess another direction that my project
>could take is to extend PostgreSQL's SQL parser to factor in my DSL
>keywords and requirements.
>
>To make matters more complicated, this version of ANTLR does not
>support code generation to C, but it does support generation to C++.
>Integrating the generated C++ code requires making it friendly to
>PostgreSQL e.g. using Plain Old Data Structures as described here
>https://www.postgresql.org/docs/9.0/extend-cpp.html, which seems to be
>suggesting to me that I may be using the wrong approach towards my
>goal.
>
>I would be grateful if anyone could provide any general advice or
>pointers regarding my approach, for example regarding development
>effort, so that the development with PostgreSQL internals can be smooth
>and of a high quality. Maybe somebody has come across another DSL
>attempt which used PostgreSQL and that I could follow as a reference?
>

I might be missing something, but it seems like you intend to replace
the SQL grammar we have with something else. It's not clear to me what
would be the point of doing that, and it definitely looks like a huge
amount of work - e.g. we don't have any support for switching between
two distinct grammars the way you envision, and just that alone seems
like a multi-year project. And if you don't have that capability, all
external tools kinda stop working. Good luck with running such database.

What I'd look at first is implementing the grammar as a procedural
language (think PL/pgSQL, pl/perl etc.) implementing whatever you expect
from your DSL. And it's not like you'd have to wrap everything in
functions, because we have anonymous DO blocks. So you could do:

  DO LANGUAGE mydsl $$
     ... whatever my dsl allows ...
  $$; 

It's still a fair amount of code to implement this (both the PL handler
and the DSL implementation), but it's orders of magnitude simpler than
what you described.

See https://www.postgresql.org/docs/current/plhandler.html for details
about how to write a language handler.


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services 



pgsql-hackers by date:

Previous
From: Binguo Bao
Date:
Subject: Re: Optimize partial TOAST decompression
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] [WIP] Effective storage of duplicates in B-tree index.