1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add expression compilation support to LLVM JIT provider.

In addition to the interpretation of expressions (which back
evaluation of WHERE clauses, target list projection, aggregates
transition values etc) support compiling expressions to native code,
using the infrastructure added in earlier commits.

To avoid duplicating a lot of code, only support emitting code for
cases that are likely to be performance critical. For expression steps
that aren't deemed that, use the existing interpreter.

The generated code isn't great - some architectural changes are
required to address that. But this already yields a significant
speedup for some analytics queries, particularly with WHERE clauses
filtering a lot, or computing multiple aggregates.

Author: Andres Freund
Tested-By: Thomas Munro
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de

Disable JITing for VALUES() nodes.

VALUES() nodes are only ever executed once. This is primarily helpful
for debugging, when forcing JITing even for cheap queries.

Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
This commit is contained in:
Andres Freund
2018-03-20 02:20:46 -07:00
parent 7ced1d1247
commit 2a0faed9d7
13 changed files with 2890 additions and 3 deletions

View File

@ -36,6 +36,7 @@
#include "executor/execExpr.h"
#include "executor/nodeSubplan.h"
#include "funcapi.h"
#include "jit/jit.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
@ -623,6 +624,9 @@ ExecCheck(ExprState *state, ExprContext *econtext)
static void
ExecReadyExpr(ExprState *state)
{
if (jit_compile_expr(state))
return;
ExecReadyInterpretedExpr(state);
}

View File

@ -25,6 +25,7 @@
#include "executor/executor.h"
#include "executor/nodeValuesscan.h"
#include "jit/jit.h"
#include "utils/expandeddatum.h"
@ -98,6 +99,7 @@ ValuesNext(ValuesScanState *node)
bool *isnull;
ListCell *lc;
int resind;
int saved_jit_flags;
/*
* Get rid of any prior cycle's leftovers. We use ReScanExprContext
@ -128,7 +130,15 @@ ValuesNext(ValuesScanState *node)
oldsubplans = node->ss.ps.subPlan;
node->ss.ps.subPlan = NIL;
/*
* As the expressions are only ever used once, disable JIT for
* them. This is worthwhile because it's common to insert significant
* amounts of data via VALUES().
*/
saved_jit_flags = econtext->ecxt_estate->es_jit_flags;
econtext->ecxt_estate->es_jit_flags = PGJIT_NONE;
exprstatelist = ExecInitExprList(exprlist, &node->ss.ps);
econtext->ecxt_estate->es_jit_flags = saved_jit_flags;
node->ss.ps.subPlan = oldsubplans;