title: Fastest queries in Postgres with Node.js client and connection pooling - stored functions or prepared statements?
body: <p>We have a Postgres database on AWS, with a table that will contain millions (but not tens of millions) of rows. Primary key is a single column. Data access is going to be basically uniformly distributed among the data rows, and it's going to be simple SELECT statements by primary key, so basically we get either one row or none as the result data set.</p>
  
  <p>Our client is written in Node.js using the <code>node-postgres</code> module. We are using connection pooling. We would like to do anything we reasonably can to execute our SELECTs as fast as possible; would prepared statements or stored functions be a good idea in this scenario? What would be, on paper, faster?</p>
  
  <p>Edit: we are currently handling connection pooling via the <code>pg-pool</code> module that comes with <code>node-psotgres</code> itself, and pick a new connection from the pool with every request. I am not sure whether the work done by the server when preparing a statement, or a stored function, is lost when the connection is handed back to the pool.</p>