8000 Proof of concept · postgres/postgres@f9a0494 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9a0494

Browse files
committed
Proof of concept
1 parent 626e6ed commit f9a0494

File tree

168 files changed

+19283
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+19283
-25
lines changed

GNUmakefile.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,12 @@ distcheck: dist
131131
rm -rf $(distdir) $(dummy)
132132
@echo "Distribution integrity checks out."
133133

134+
LIBPQPARSEROBJS= $(shell cat src/backend/access/objfiles.txt src/backend/bootstrap/objfiles.txt src/backend/catalog/objfiles.txt src/backend/parser/objfiles.txt src/backend/commands/objfiles.txt src/backend/executor/objfiles.txt src/backend/foreign/objfiles.txt src/backend/lib/objfiles.txt src/backend/libpq/objfiles.txt src/backend/nodes/objfiles.txt src/backend/optimizer/objfiles.txt src/backend/port/objfiles.txt src/backend/postmaster/objfiles.txt src/backend/regex/objfiles.txt src/backend/replication/objfiles.txt src/backend/rewrite/objfiles.txt src/backend/storage/objfiles.txt src/backend/tcop/objfiles.txt src/backend/tsearch/objfiles.txt src/backend/utils/objfiles.txt src/timezone/objfiles.txt src/backend/parser/objfiles.txt)
135+
136+
libpqparser:
137+
ar cr libpqparser.a $(LIBPQPARSEROBJS)
138+
ranlib libpqparser.a
139+
cp src/port/libpgport_srv.a $(DESTDIR)$(libdir)
140+
cp libpqparser.a $(DESTDIR)$(libdir)/
141+
134142
.PHONY: dist distdir distcheck docs install-docs world check-world install-world installcheck-world

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
PostgreSQL Wire Protocol Experiment
2+
===================================
3+
4+
DRAFT
5+
-----
6+
7+
Original PostgreSQL README file
8+
-------------------------------
9+
The original PostgreSQL README file is [here](postgres/blob/master/README).
10+
11+
Overview
12+
--------
13+
This is an experiment to see what happens if SQL isn't used as a wire protocol for relational database access.
14+
15+
The reasoning is as follows:
16+
* Most sophisticated relational database libraries (including ORMs) store queries internally as expression trees.
17+
* These expression trees are converted to SQL for transmission to a database.
18+
* The database then parses the SQL into an expression tree.
19+
* In theory, the expression tree can be passed directly from the client to the server, rather than going through
20+
the intermediate SQL conversion step.
21+
22+
Status
23+
------
24+
As at the date of writing (12/16/2012) this is a minimally viable proof of concept:
25+
* It can execute simple SQL arithmetic expressions. (E.g. "select 1 + 2;")
26+
* It can select simple columns from tables (no namespacing, etc.) (E.g. "select first_name from users;")
27+
* It can name selected columns (E.g. "select 2 * 5 as result;")
28+
29+
Solution Components
30+
-------------------
31+
There are two repositories associated with this experiment:
32+
* A modified version of PostgreSQL that can accept a serialized expression tree.
33+
* A modified version of ruby-pg, the ruby client-side interface for PostgreSQL.
34+
This component links to customized PostgreSQL libraries that parse SQL to an expression tree, before passing
35+
that expression tree to the PostgreSQL server.
36+
37+
Building
38+
--------
39+
40+
### Install Prefix
41+
To be sure you don't break your existing Postgresql installation, we'll install somewhere else:
42+
43+
export INSTALL_PREFIX="${HOME}/test-postgresql"
44+
export DB_PREFIX="${HOME}/testdb"
45+
export DB_NAME="testdb"
46+
47+
### Postgresql
48+
1. Download, unpack and cd
49+
2. Build and install
50+
51+
export CFLAGS="-g -fPIC"
52+
autoconf
53+
./configure --prefix=${INSTALL_PREFIX} --enable-debug --with-libxml
54+
make && make install
55+
56+
### ruby-pg
57+
1. Set path
58+
PATH="${INSTALL_PREFIX}/bin:$PATH"; export PATH
59+
2. Download, unpack and cd
60+
3. Build and install
61+
62+
rake install_gem
63+
64+
Testing
65+
--------
66+
### Setup test database
67+
1. Create database
68+
initdb -D ${DB_PREFIX}
69+
2. Run postgresql server
70+
postgres -D ${DB_PREFIX}
71+
3. Create test table
72+
73+
psql ${DB_NAME}
74+
create table test (num integer, str varchar(50));
75+
insert into test values (14, 'Test');
76+
^D
77+
78+
### Run client
79+
irb
80+
require 'pg'
81+
conn = PG.connect( host: "localhost", dbname: ENV["DB_PREFIX"])
82+
x = conn.exec "select * from test;"
83+
x.first
84+
85+
Build Notes
86+
-----------------
87+
### Build Environment
88+
89+
My development system runs FreeBSD 9.0. To build in this environment, you must upgrade GCC (I'm using 4.8).
90+

config/programs.m4

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,24 @@ AC_DEFUN([PGAC_CHECK_STRIP],
235235
AC_SUBST(STRIP_STATIC_LIB)
236236
AC_SUBST(STRIP_SHARED_LIB)
237237
])# PGAC_CHECK_STRIP
238+
239+
# PGAC_PATH_ASN1C
240+
# ---------------
241+
# Look for asn1c, set the output variable ASN1C to its path if found.
242+
243+
AC_DEFUN([PGAC_PATH_ASN1C],
244+
[# Let the user override the search
245+
if test -z "$ASN1C"; then
246+
AC_PATH_PROGS(ASN1C, asn1c)
247+
fi
248+
249+
if test -z "$ASN1C"; then
250+
AC_MSG_WARN([
251+
*** Without asn1c you will not be able to build PostgreSQL from Git nor
252+
*** change any of the PDU definition files. (If you are using the
253+
*** official distribution of PostgreSQL then you do not need to worry
254+
*** about this, because the asn1c output is pre-generated.)])
255+
fi
256+
# We don't need AC_SUBST(ASN1C) because AC_PATH_PROG did it
257+
AC_SUBST(ASN1CFLAGS)
258+
])# PGAC_PATH_ASN1C

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ esac
835835

836836
PGAC_PATH_BISON
837837
PGAC_PATH_FLEX
838+
PGAC_PATH_ASN1C
838839

839840
PGAC_PATH_PERL
840841
if test "$with_perl" = yes; then

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ top_builddir = ..
1313
include Makefile.global
1414

1515
SUBDIRS = \
16+
asn1 \
1617
common \
1718
port \
1819
timezone \

src/Makefile.global.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ PTHREAD_LIBS = @PTHREAD_LIBS@
204204
# Compilers
205205

206206
CPP = @CPP@
207-
CPPFLAGS = @CPPFLAGS@
207+
CPPFLAGS = @CPPFLAGS@ -I$(top_srcdir)/src/include/asn1
208208

209209
ifdef PGXS
210210
override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)
@@ -223,6 +223,7 @@ CFLAGS_VECTOR = @CFLAGS_VECTOR@
223223

224224
# Kind-of compilers
225225

226+
ASN1C = @ASN1C@
226227
BISON = @BISON@
227228
BISONFLAGS = @BISONFLAGS@ $(YFLAGS)
228229
FLEX = @FLEX@

src/asn1/ASNBinaryExpression.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Generated by asn1c-0.9.21 (http://lionet.info/asn1c)
3+
* From ASN.1 module "SQLQuery"
4+
* found in "SQLQuery.asn1"
5+
* `asn1c -fskeletons-copy -fnative-types`
6+
*/
7+
8+
#include <asn_internal.h>
9+
10+
#include "ASNBinaryExpression.h"
11+
12+
static asn_TYPE_member_t asn_MBR_ASNBinaryExpression_1[] = {
13+
{ ATF_POINTER, 0, offsetof(struct ASNBinaryExpression, lhs),
14+
-1 /* Ambiguous tag (CHOICE?) */,
15+
0,
16+
&asn_DEF_ASNExpression,
17+
0, /* Defer constraints checking to the member type */
18+
0, /* No PER visible constraints */
19+
0,
20+
"lhs"
21+
},
22+
{ ATF_NOFLAGS, 0, offsetof(struct ASNBinaryExpression, operator),
23+
(ASN_TAG_CLASS_UNIVERSAL | (10 << 2)),
24+
0,
25+
&asn_DEF_ASNBinaryOperator,
26+
0, /* Defer constraints checking to the member type */
27+
0, /* No PER visible constraints */
28+
0,
29+
"operator"
30+
},
31+
{ ATF_POINTER, 0, offsetof(struct ASNBinaryExpression, rhs),
32+
-1 /* Ambiguous tag (CHOICE?) */,
33+
0,
34+
&asn_DEF_ASNExpression,
35+
0, /* Defer constraints checking to the member type */
36+
0, /* No PER visible constraints */
37+
0,
38+
"rhs"
39+
},
40+
};
41+
static ber_tlv_tag_t asn_DEF_ASNBinaryExpression_tags_1[] = {
42+
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
43+
};
44+
static asn_TYPE_tag2member_t asn_MAP_ASNBinaryExpression_tag2el_1[] = {
45+
{ (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)), 1, 0, 0 }, /* operator at 54 */
46+
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 1 }, /* intConst at 46 */
47+
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 2, -1, 0 }, /* intConst at 46 */
48+
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 0, 0, 1 }, /* floatConst at 47 */
49+
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 2, -1, 0 }, /* floatConst at 47 */
50+
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 0, 0, 1 }, /* stringConst at 48 */
51+
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, -1, 0 }, /* stringConst at 48 */
52+
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 0, 0, 1 }, /* binaryExpr at 50 */
53+
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 2, -1, 0 } /* binaryExpr at 50 */
54+
};
55+
static asn_SEQUENCE_specifics_t asn_SPC_ASNBinaryExpression_specs_1 = {
56+
sizeof(struct ASNBinaryExpression),
57+
offsetof(struct ASNBinaryExpression, _asn_ctx),
58+
asn_MAP_ASNBinaryExpression_tag2el_1,
59+
9, /* Count of tags in the map */
60+
0, 0, 0, /* Optional elements (not needed) */
61+
-1, /* Start extensions */
62+
-1 /* Stop extensions */
63+
};
64+
asn_TYPE_descriptor_t asn_DEF_ASNBinaryExpression = {
65+
"ASNBinaryExpression",
66+
"ASNBinaryExpression",
67+
SEQUENCE_free,
68+
SEQUENCE_print,
69+
SEQUENCE_constraint,
70+
SEQUENCE_decode_ber,
71+
SEQUENCE_encode_der,
72+
SEQUENCE_decode_xer,
73+
SEQUENCE_encode_xer,
74+
SEQUENCE_decode_uper,
75+
SEQUENCE_encode_uper,
76+
0, /* Use generic outmost tag fetcher */
77+
asn_DEF_ASNBinaryExpression_tags_1,
78+
sizeof(asn_DEF_ASNBinaryExpression_tags_1)
79+
/sizeof(asn_DEF_ASNBinaryExpression_tags_1[0]), /* 1 */
80+
asn_DEF_ASNBinaryExpression_tags_1, /* Same as above */
81+
sizeof(asn_DEF_ASNBinaryExpression_tags_1)
82+
/sizeof(asn_DEF_ASNBinaryExpression_tags_1[0]), /* 1 */
83+
0, /* No PER visible constraints */
84+
asn_MBR_ASNBinaryExpression_1,
85+
3, /* Elements count */
86+
&asn_SPC_ASNBinaryExpression_specs_1 /* Additional specs */
87+
};
88+

src/asn1/ASNBinaryExpression.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Generated by asn1c-0.9.21 (http://lionet.info/asn1c)
3+
* From ASN.1 module "SQLQuery"
4+
* found in "SQLQuery.asn1"
5+
* `asn1c -fskeletons-copy -fnative-types`
6+
*/
7+
8+
#ifndef _ASNBinaryExpression_H_
9+
#define _ASNBinaryExpression_H_
10+
11+
12+
#include <asn_application.h>
13+
14+
/* Including external dependencies */
15+
#include "ASNBinaryOperator.h"
16+
#include <constr_SEQUENCE.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
/* Forward declarations */
23+
struct ASNExpression;
24+
25+
/* ASNBinaryExpression */
26+
typedef struct ASNBinaryExpression {
27+
struct ASNExpression *lhs;
28+
ASNBinaryOperator_t operator;
29+
struct ASNExpression *rhs;
30+
31+
/* Context for parsing across buffer boundaries */
32+
asn_struct_ctx_t _asn_ctx;
33+
} ASNBinaryExpression_t;
34+
35+
/* Implementation */
36+
extern asn_TYPE_descriptor_t asn_DEF_ASNBinaryExpression;
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
/* Referred external types */
43+
#include "ASNExpression.h"
44+
45+
#endif /* _ASNBinaryExpression_H_ */

0 commit comments

Comments
 (0)
0