comp.lang.ada
 help / color / mirror / Atom feed
* Ada and PL/pgSQL ?
@ 2014-05-09 16:26 sdalemorrey
  2014-05-09 18:02 ` björn lundin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: sdalemorrey @ 2014-05-09 16:26 UTC (permalink / raw)


After careful review the most frequent and essential logic functions of this exchange application directly as a collection of stored procedures, functions and triggers in the Postgres database that will be backing it, seems to make the most sense.

The logic behind the decision is pretty clear cut.  Transit time back and forth between the database becomes cumulative and burdensome when you consider just how many queries are involved.

By way of example, we have a transactions table and an orders table.  Before an order can be placed, the transactions table must reflect a debit against the user account by the amount of their bid by way of a special "HELDFORORDER" flag that otherwise looks like a normal withdrawal transaction.  Then once the order is settled, that flag must be changed to DEBIT.

Thusly even a simple market order consists of several round trips to the database, unless the logic can be consolidated into a collection of functions that are stored in the DB.

Overall an order looks like this..

Step 1:  Check user balance and ensure it is sufficient to cover the order
Step 2:  Hold funds for order
Step 3:  Create Order
Step 4:  If market order or FOK then trigger the order matching engine.
Step 5:  Attempt to fill orders by comparing bid/ask and matching them.
Step 6:  Convert transaction hold flag to debit and link in the orderID.

Under the original system, each of these steps were at least one round trip between application core logic (a mix of PHP and C) and the DB (which was originally level and then moved to MySQL).  The minimum execution time for an order was 30s. However it was climbing as high as 5mins.  About 20% was query and transit time.  With a majority of the slow down occuring from table locks on db transactions.

Thus the decision to move that logic closer to the datastore, embedding it if at all possible. 

While researching the PL/pgSQL language I noticed that it bears a shocking similarity to Ada.  Almost like it's Ada but tailored for SQL.

Still I would like to maintain the safety and provability of Ada.
It appears that Postgres has the ability to import various languages such as C and execute those about as easily as it's own native language.

So the question I have here is, does anyone know of a path to get Ada functions operational in Postgres.  Or (assuming there is a pathway) is Postgres's PL/pgSQL going to give the same benefits of Ada?  

The languages are to my mind so similar that I'm having real difficulty seeing a major difference between the two.

Thanks for any info!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-05-10 11:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-09 16:26 Ada and PL/pgSQL ? sdalemorrey
2014-05-09 18:02 ` björn lundin
2014-05-09 19:59   ` sdalemorrey
2014-05-09 21:14     ` björn lundin
2014-05-10  9:37 ` Dirk Heinrichs
2014-05-10 10:40   ` Mike H
2014-05-10 11:04 ` björn lundin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox