Skip to content

Commit b808de0

Browse files
authored
Merge pull request #1 from nad2000/V10
V10
2 parents b864975 + 5c1df69 commit b808de0

File tree

3 files changed

+101
-34
lines changed

3 files changed

+101
-34
lines changed

.travis.yml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
sudo: required
2+
matrix:
3+
include:
4+
- env: PG_VERSION=9
5+
- env: PG_VERSION=10
6+
- env: PG_VERSION=11
7+
# - env: PG_VERSION=12
28

39
services:
4-
- docker
10+
- docker
511

612
before_install:
7-
- docker build -t image .
13+
- docker build --build-arg PG_VERSION=${PG_VERSION} -t image .
814

915
install:
10-
- docker run --name TEST -d image
11-
# wait for the database to come up
12-
- until docker exec TEST psql -U postgres -l; do echo "Waiting for postgres to start..."; sleep 0.5; done
16+
- docker run --name TEST -d image
17+
# wait for the database to come up
18+
- until docker exec TEST psql -U postgres -l; do echo "Waiting for postgres to start..."; sleep 0.5; done
1319

1420
script:
15-
- docker exec TEST psql -U postgres -c "CREATE EXTENSION uint" && echo "SUCCESS"
16-
- docker exec TEST psql -U postgres -c "CREATE TABLE test(col1 uint1, col2 uint2, col4 uint4);" && echo "SUCCESS"
17-
- docker exec TEST psql -U postgres -c "INSERT INTO test(col1, col2, col4) SELECT v % 127, v % 16256, v FROM generate_series(1, 100000) AS d(v)" && echo "SUCCESS"
18-
- docker exec TEST psql -U postgres -c "WITH t AS (SELECT DISTINCT col1 FROM test) SELECT count(*) FROM t" && echo "SUCCESS"
21+
- docker exec TEST psql -U postgres -c "CREATE EXTENSION uint" && echo "SUCCESS"
22+
- >-
23+
docker exec TEST psql -U postgres -c "CREATE TABLE IF NOT EXISTS test (
24+
col1 uint1, col2 uint2, col4 uint4);
25+
INSERT INTO test(col1, col2, col4)
26+
SELECT v % 127, v % 16256, v
27+
FROM generate_series(1, 100000, 42) AS d(v);
28+
WITH t AS (SELECT DISTINCT col1 FROM test) SELECT count(*) FROM t;" && echo "SUCCESS"
29+
- docker logs TEST
1930

2031
after_success:
21-
- docker login -e $DOCKER_HUB_EMAIL -u $DOCKER_HUB_USER_ID -p $DOCKER_HUB_PWD
22-
- docker tag image $DOCKER_HUB_USER_ID/postgres-uint:$TRAVIS_COMMIT
23-
- docker tag image $DOCKER_HUB_USER_ID/postgres-uint:latest
24-
- docker push $DOCKER_HUB_USER_ID/postgres-uint:$TRAVIS_COMMIT
25-
- docker push $DOCKER_HUB_USER_ID/postgres-uint:latest
32+
- docker login -u $DOCKER_HUB_USER_ID -p $DOCKER_HUB_PWD
33+
- docker tag image $DOCKER_HUB_USER_ID/postgres-uint:v$PG_VERSION
34+
- docker push $DOCKER_HUB_USER_ID/postgres-uint:v$PG_VERSION
35+
- >
36+
if [ $PG_VERSION == 11 ] ; then
37+
docker tag image $DOCKER_HUB_USER_ID/postgres-uint:latest
38+
docker push $DOCKER_HUB_USER_ID/postgres-uint:latest
39+
fi
2640
2741
after_script:
28-
- docker stop TEST
29-
- docker rm -f TEST
30-
42+
- docker stop TEST
43+
- docker rm -f TEST

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
FROM postgres:9
1+
ARG PG_VERSION
2+
FROM postgres:${PG_VERSION:-9}
23
COPY . /uint
34
RUN apt-get update -y && apt-get upgrade -y \
45
&& apt-get install -y --no-install-recommends \
56
gcc \
67
build-essential \
78
postgresql-server-dev-all \
89
&& cd /uint && PATH=/usr/lib/postgresql/${PG_MAJOR}/bin:$PATH make install \
9-
&& apt-get purge -y build-essential binutils comerr-dev cpp dctrl-tools gcc krb5-multidev libasan* libatomic1 libc-dev-bin libc6-dev libcilkrts5 libcloog-isl4 libgomp1 libgssrpc4 libisl* libitm1 libkadm5clnt-mit9 libkadm5srv-mit9 libkdb5-7 liblsan0 libmpc3 libmpfr4 libpq-dev libquadmath0 libssl-dev libtsan0 libubsan0 linux-libc-dev make postgresql-server-dev-all zlib1g-dev \
10-
&& apt-get autoremove -y \
10+
&& apt-get purge -y build-essential binutils comerr-dev cpp dctrl-tools gcc krb5-multidev libasan* libatomic1 libc-dev-bin libc6-dev libcilkrts5 libcloog-isl4 libgomp1 libgssrpc4 libisl* libitm1 libkadm5clnt-mit9 libkadm5srv-mit9 libkdb5-7 liblsan0 libmpc3 libmpfr4 libpq-dev libquadmath0 libssl-dev libtsan0 libubsan0 linux-libc-dev make postgresql-server-dev-all zlib1g-dev ; \
11+
apt-get autoremove -y \
1112
&& apt-get autoclean -y \
1213
&& cd / && rm -rf /uint \
1314
&& rm -rf /var/lib/apt/lists/*

uint.c

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@
2020
#define PG_RETURN_UINT8(x) return UInt8GetDatum(x)
2121
#define PG_RETURN_UINT16(x) return UInt16GetDatum(x)
2222

23-
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
24-
# define likely(x) __builtin_expect((x),1)
25-
# define unlikely(x) __builtin_expect((x),0)
26-
#else
27-
# define likely(x) (x)
28-
# define unlikely(x) (x)
23+
#if !defined(likely) && !defined(unlikely)
24+
# if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
25+
# define likely(x) __builtin_expect((x),1)
26+
# define unlikely(x) __builtin_expect((x),0)
27+
# else
28+
# define likely(x) (x)
29+
# define unlikely(x) (x)
30+
# endif
2931
#endif
3032

3133
#ifdef PG_MODULE_MAGIC
3234
PG_MODULE_MAGIC;
3335
#endif
3436

37+
3538
/*
3639
* ==================
3740
* UINT1 DECLARATIONS
@@ -214,6 +217,7 @@ PG_FUNCTION_INFO_V1(uint1le);
214217
PG_FUNCTION_INFO_V1(uint1gt);
215218
PG_FUNCTION_INFO_V1(uint1ge);
216219
PG_FUNCTION_INFO_V1(uint1int4eq);
220+
PG_FUNCTION_INFO_V1(int4uint1eq);
217221

218222
/**
219223
* This function implements the "equal" (=) operator for the uint1 datatype.
@@ -743,6 +747,7 @@ PG_FUNCTION_INFO_V1(uint2le);
743747
PG_FUNCTION_INFO_V1(uint2gt);
744748
PG_FUNCTION_INFO_V1(uint2ge);
745749
PG_FUNCTION_INFO_V1(uint2int4eq);
750+
PG_FUNCTION_INFO_V1(int4uint2eq);
746751

747752
/**
748753
* This function implements the "equal" (=) operator for the uint2 datatype.
@@ -2029,8 +2034,12 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
20292034
double (*convert_stats)(Datum))
20302035
{
20312036
double hist_selec;
2037+
#if PG_VERSION_NUM < 100000
20322038
Datum *values;
20332039
int nvalues;
2040+
#else
2041+
AttStatsSlot sslot;
2042+
#endif
20342043

20352044
hist_selec = 0.0;
20362045

@@ -2045,13 +2054,29 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
20452054
* the reverse way if isgt is TRUE.
20462055
*/
20472056
if(HeapTupleIsValid(vardata->statsTuple) &&
2057+
#if PG_VERSION_NUM < 90000
2058+
get_attstatsslot(vardata->statsTuple, vardata->atttype,
2059+
vardata->atttypmod, STATISTIC_KIND_HISTOGRAM,
2060+
InvalidOid,
2061+
&values, &nvalues, NULL, NULL)
2062+
#elif PG_VERSION_NUM < 100000
20482063
get_attstatsslot(vardata->statsTuple, vardata->atttype,
20492064
vardata->atttypmod, STATISTIC_KIND_HISTOGRAM,
20502065
InvalidOid,
20512066
NULL, /* Added for postgresql 9 compatibality */
2052-
&values, &nvalues, NULL, NULL))
2067+
&values, &nvalues, NULL, NULL)
2068+
#else
2069+
get_attstatsslot(&sslot,
2070+
vardata->statsTuple, vardata->atttype,
2071+
vardata->atttypmod, STATISTIC_KIND_HISTOGRAM)
2072+
#endif
2073+
)
20532074
{
2054-
if(nvalues > 1) {
2075+
if(
2076+
#if PG_VERSION_NUM >= 100000
2077+
sslot.
2078+
#endif
2079+
nvalues > 1) {
20552080
/*
20562081
* Use binary search to find proper location, ie, the first slot
20572082
* at which the comparison fails. (If the given operator isn't
@@ -2061,13 +2086,21 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
20612086
*/
20622087
double histfrac;
20632088
int lobound = 0; /* first possible slot to search */
2064-
int hibound = nvalues; /* last+1 slot to search */
2089+
int hibound =
2090+
#if PG_VERSION_NUM >= 100000
2091+
sslot.
2092+
#endif
2093+
nvalues; /* last+1 slot to search */
20652094

20662095
while(lobound < hibound) {
20672096
int probe = (lobound + hibound) / 2;
20682097
bool ltcmp;
20692098

2070-
ltcmp = DatumGetBool(FunctionCall2(opproc, values[probe], constval));
2099+
ltcmp = DatumGetBool(FunctionCall2(opproc,
2100+
#if PG_VERSION_NUM >= 100000
2101+
sslot.
2102+
#endif
2103+
values[probe], constval));
20712104
if(isgt)
20722105
ltcmp = !ltcmp;
20732106

@@ -2077,7 +2110,11 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
20772110
hibound = probe;
20782111
}
20792112

2080-
if(lobound >= nvalues) {
2113+
if(lobound >=
2114+
#if PG_VERSION_NUM >= 100000
2115+
sslot.
2116+
#endif
2117+
nvalues) {
20812118
/* Constant is above upper histogram boundary. */
20822119
histfrac = 1.0;
20832120
}
@@ -2096,8 +2133,16 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
20962133
*/
20972134

20982135
val = (*convert_value)(constval);
2099-
low = (*convert_stats)(values[i - 1]);
2100-
high = (*convert_stats)(values[i]);
2136+
low = (*convert_stats)(
2137+
#if PG_VERSION_NUM >= 100000
2138+
sslot.
2139+
#endif
2140+
values[i - 1]);
2141+
high = (*convert_stats)(
2142+
#if PG_VERSION_NUM >= 100000
2143+
sslot.
2144+
#endif
2145+
values[i]);
21012146

21022147
if(high <= low)
21032148
binfrac = 0.5; /* cope if bin boundaries appear identical */
@@ -2124,7 +2169,11 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
21242169
* binfrac partial bin below the constant.
21252170
*/
21262171
histfrac = (double) (i - 1) + binfrac;
2127-
histfrac /= (double) (nvalues - 1);
2172+
histfrac /= (double) (
2173+
#if PG_VERSION_NUM >= 100000
2174+
sslot.
2175+
#endif
2176+
nvalues - 1);
21282177
}
21292178

21302179
/*
@@ -2145,7 +2194,11 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
21452194
else if (hist_selec > 0.9999)
21462195
hist_selec = 0.9999;
21472196
}
2197+
#if PG_VERSION_NUM < 100000
21482198
free_attstatsslot(vardata->atttype, values, nvalues, NULL, 0);
2199+
#else
2200+
free_attstatsslot(&sslot);
2201+
#endif
21492202
}
21502203
return hist_selec;
21512204
}

0 commit comments

Comments
 (0)