cohenjo / pg_idx_advisor

A PostgreSQL extension to analyze queries and give indexing advice.
49 stars 8 forks source link

PostgreSQL 10 compatibility #7

Open ArturFormella opened 7 years ago

ArturFormella commented 7 years ago

Hello! I get the following error when trying to build with PostgreSQL 10

~/workspace/pg_idx_advisor$ make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fpic -I. -I./ -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o src/idx_adviser.o src/idx_adviser.c
src/idx_adviser.c: In function ‘_PG_init’:
src/idx_adviser.c:252:23: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  ExplainOneQuery_hook = ExplainOneQuery_callback;
                       ^
src/idx_adviser.c: At top level:
src/idx_adviser.c:277:1: warning: variably modified ‘_compile_assert_array’ at file scope
 compile_assert( ((Cost)-1) < 0 );
 ^~~~~~~~~~~~~~
src/idx_adviser.c:893:26: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
      info->amcostestimate=(RegProcedure)3800; //brincostestimate
                          ^
src/idx_adviser.c:901:39: error: ‘struct RelationData’ has no member named ‘rd_am’; did you mean ‘rd_att’?
   info->amcanorderbyop = indexRelation->rd_am->amcanorderbyop;
                                       ^~
src/idx_adviser.c:902:38: error: ‘struct RelationData’ has no member named ‘rd_am’; did you mean ‘rd_att’?
   info->amoptionalkey = indexRelation->rd_am->amoptionalkey;
                                      ^~
src/idx_adviser.c:903:38: error: ‘struct RelationData’ has no member named ‘rd_am’; did you mean ‘rd_att’?
   info->amsearcharray = indexRelation->rd_am->amsearcharray;
                                      ^~
src/idx_adviser.c:904:38: error: ‘struct RelationData’ has no member named ‘rd_am’; did you mean ‘rd_att’?
   info->amsearchnulls = indexRelation->rd_am->amsearchnulls;
                                      ^~
In file included from /usr/local/pgsql/include/server/postgres.h:47:0,
                 from src/idx_adviser.c:30:
src/idx_adviser.c:905:49: error: ‘struct RelationData’ has no member named ‘rd_am’; did you mean ‘rd_att’?
   info->amhasgettuple = OidIsValid(indexRelation->rd_am->amgettuple);
                                                 ^
/usr/local/pgsql/include/server/c.h:538:41: note: in definition of macro ‘OidIsValid’
 #define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
                                         ^~~~~~~~
src/idx_adviser.c:906:50: error: ‘struct RelationData’ has no member named ‘rd_am’; did you mean ‘rd_att’?
   info->amhasgetbitmap = OidIsValid(indexRelation->rd_am->amgetbitmap);
                                                  ^
/usr/local/pgsql/include/server/c.h:538:41: note: in definition of macro ‘OidIsValid’
 #define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
                                         ^~~~~~~~
src/idx_adviser.c:966:5: warning: implicit declaration of function ‘ChangeVarNodes’ [-Wimplicit-function-declaration]
     ChangeVarNodes((Node *) info->indexprs, 1, varno, 0);
     ^~~~~~~~~~~~~~

In file included from /usr/local/pgsql/include/server/lib/pairingheap.h:14:0,
                 from /usr/local/pgsql/include/server/utils/snapshot.h:19,
                 from /usr/local/pgsql/include/server/access/genam.h:22,
                 from src/idx_adviser.c:32:
/usr/local/pgsql/include/server/lib/stringinfo.h:121:13: note: expected ‘const char *’ but argument is of type ‘int’
 extern void appendStringInfoString(StringInfo str, const char *s);
             ^~~~~~~~~~~~~~~~~~~~~~
src/idx_adviser.c:1313:23: error: ‘BTREE_AM_OID’ undeclared (first use in this function)
                  case BTREE_AM_OID:
                       ^~~~~~~~~~~~
src/idx_adviser.c:1315:30: error: ‘GIN_AM_OID’ undeclared (first use in this function)
                         case GIN_AM_OID:
                              ^~~~~~~~~~
src/idx_adviser.c:1318:30: error: ‘GIST_AM_OID’ undeclared (first use in this function)
                         case GIST_AM_OID:
                              ^~~~~~~~~~~
src/idx_adviser.c:1322:30: error: ‘BRIN_AM_OID’ undeclared (first use in this function)
                         case BRIN_AM_OID:
                              ^~~~~~~~~~~
src/idx_adviser.c: In function ‘mark_used_candidates’:
src/idx_adviser.c:1651:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     const bool used = (idxcd->idxoid == idxScan->indexid);
     ^~~~~
src/idx_adviser.c: In function ‘scan_query’:
src/idx_adviser.c:1928:11: warning: passing argument 1 of ‘scan_query’ from incompatible pointer type [-Wincompatible-pointer-types]
           rte->ctequery,
           ^~~
src/idx_adviser.c:1903:14: note: expected ‘const Query * const {aka const struct Query * const}’ but argument is of type ‘Node * const {aka struct Node * const}’
 static List* scan_query( const Query* const query,
              ^~~~~~~~~~
src/idx_adviser.c:1956:66: warning: passing argument 1 of ‘scan_generic_node’ from incompatible pointer type [-Wincompatible-pointer-types]
    candidates = merge_candidates( candidates, scan_generic_node( rte->joinaliasvars,
                                                                  ^~~
src/idx_adviser.c:78:14: note: expected ‘const Node * const {aka const struct Node * const}’ but argument is of type ‘List * const {aka struct List * const}’
 static List* scan_generic_node( const Node* const root,
              ^~~~~~~~~~~~~~~~~
/usr/local/pgsql/include/server/utils/elog.h:202:23: note: in definition of macro ‘elog’
   elog_finish(elevel, __VA_ARGS__); \
                       ^~~~~~~~~~~
src/idx_adviser.c:2291:90: error: ‘GIN_AM_OID’ undeclared (first use in this function)
      cand->amOid = ((tcategory == TYPCATEGORY_ARRAY)||(tcategory == TYPCATEGORY_USER)) ? GIN_AM_OID : BTREE_AM_OID ;
                                                                                          ^~~~~~~~~~
src/idx_adviser.c:2291:103: error: ‘BTREE_AM_OID’ undeclared (first use in this function)
      cand->amOid = ((tcategory == TYPCATEGORY_ARRAY)||(tcategory == TYPCATEGORY_USER)) ? GIN_AM_OID : BTREE_AM_OID ;
                                                                                                       ^~~~~~~~~~~~
In file included from /usr/local/pgsql/include/server/postgres.h:48:0,
                 from src/idx_adviser.c:30:
src/idx_adviser.c:2407:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘char *’ [-Wformat=]
       elog(ERROR, "cache lookup failed for attribute %d of relation %u",varname, rte->relid);
                   ^
/usr/local/pgsql/include/server/utils/elog.h:202:23: note: in definition of macro ‘elog’
   elog_finish(elevel, __VA_ARGS__); \
                       ^~~~~~~~~~~

<builtin>: recipe for target 'src/idx_adviser.o' failed
make: *** [src/idx_adviser.o] Error 1

My pg_config

$ pg_config
BINDIR = /usr/local/pgsql/bin
DOCDIR = /usr/local/pgsql/share/doc
HTMLDIR = /usr/local/pgsql/share/doc
INCLUDEDIR = /usr/local/pgsql/include
PKGINCLUDEDIR = /usr/local/pgsql/include
INCLUDEDIR-SERVER = /usr/local/pgsql/include/server
LIBDIR = /usr/local/pgsql/lib
PKGLIBDIR = /usr/local/pgsql/lib
LOCALEDIR = /usr/local/pgsql/share/locale
MANDIR = /usr/local/pgsql/share/man
SHAREDIR = /usr/local/pgsql/share
SYSCONFDIR = /usr/local/pgsql/etc
PGXS = /usr/local/pgsql/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-systemd' '--with-icu' '--with-uuid=ossp' '--with-libxml' '--with-libxslt' '--with-wal-segsize=64'
CC = gcc
CPPFLAGS = -DFRONTEND -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
CFLAGS_SL = -fpic
LDFLAGS = -L../../src/common -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lpthread -lxslt -lxml2 -lz -lreadline -lrt -lcrypt -ldl -lm
VERSION = PostgreSQL 10devel

Thanks in advance!

cohenjo commented 7 years ago

Hi, pg10 made lots of changes to the AM system. This project was mostly for learning purposes so I didn't follow the latest version.

I'll have a look if it's not too hard to update...

Note Diablo have a similar project they started recently - I think they are maintaining it actively.

Regards, Jony

jagmohankaintura commented 5 years ago

Similar Issue was encountered with 9.6 version.

src/idx_adviser.c: In function ‘get_relation_info_callback’: src/idx_adviser.c:872:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘void (*)()’ [-Wformat=] elog( DEBUG4 ,"IND ADV: amcostestimate=%d",info->amcostestimate); ^ src/idx_adviser.c:876:24: warning: assignment makes pointer from integer without a cast [enabled by default] info->amcostestimate=(RegProcedure)1268; //btcostestimate ^ src/idx_adviser.c:880:10: error: ‘BTREE_AM_OID’ undeclared (first use in this function) case BTREE_AM_OID: ^ src/idx_adviser.c:880:10: note: each undeclared identifier is reported only once for each function it appears in src/idx_adviser.c:881:26: warning: assignment makes pointer from integer without a cast [enabled by default] info->amcostestimate=(RegProcedure)1268; //btcostestimate ^ src/idx_adviser.c:883:10: error: ‘GIN_AM_OID’ undeclared (first use in this function) case GIN_AM_OID: ^ src/idx_adviser.c:884:26: warning: assignment makes pointer from integer without a cast [enabled by default] info->amcostestimate=(RegProcedure)772; //gistcostestimate ^ src/idx_adviser.c:888:10: error: ‘GIST_AM_OID’ undeclared (first use in this function) case GIST_AM_OID: ^ src/idx_adviser.c:889:26: warning: assignment makes pointer from integer without a cast [enabled by default] info->amcostestimate=(RegProcedure)772; //gistcostestimate ^ src/idx_adviser.c:892:10: error: ‘BRIN_AM_OID’ undeclared (first use in this function) case BRIN_AM_OID: ^ src/idx_adviser.c:893:26: warning: assignment makes pointer from integer without a cast [enabled by default] info->amcostestimate=(RegProcedure)3800; //brincostestimate ^ src/idx_adviser.c:901:39: error: ‘struct RelationData’ has no member named ‘rd_am’ info->amcanorderbyop = indexRelation->rd_am->amcanorderbyop; ^ src/idx_adviser.c:902:38: error: ‘struct RelationData’ has no member named ‘rd_am’ info->amoptionalkey = indexRelation->rd_am->amoptionalkey; ^ src/idx_adviser.c:903:38: error: ‘struct RelationData’ has no member named ‘rd_am’ info->amsearcharray = indexRelation->rd_am->amsearcharray; ^ src/idx_adviser.c:904:38: error: ‘struct RelationData’ has no member named ‘rd_am’ info->amsearchnulls = indexRelation->rd_am->amsearchnulls;

pg_config

BINDIR = /usr/pgsql-9.6/bin DOCDIR = /usr/pgsql-9.6/share/doc HTMLDIR = /usr/pgsql-9.6/share/doc INCLUDEDIR = /usr/pgsql-9.6/include PKGINCLUDEDIR = /usr/pgsql-9.6/include INCLUDEDIR-SERVER = /usr/pgsql-9.6/include/server LIBDIR = /usr/pgsql-9.6/lib PKGLIBDIR = /usr/pgsql-9.6/lib LOCALEDIR = /usr/pgsql-9.6/share/locale MANDIR = /usr/pgsql-9.6/share/man SHAREDIR = /usr/pgsql-9.6/share SYSCONFDIR = /usr/pgsql-9.6/etc PGXS = /usr/pgsql-9.6/lib/pgxs/src/makefiles/pgxs.mk CONFIGURE = '--prefix=/usr/pgsql-9.6' '--with-openssl' '--with-libxml' '--without-readline' CC = gcc CPPFLAGS = -DFRONTEND -D_GNU_SOURCE -I/usr/include/libxml2 CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 CFLAGS_SL = -fPIC LDFLAGS = -L../../src/common -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-9.6/lib',--enable-new-dtags LDFLAGS_EX = LDFLAGS_SL = LIBS = -lpgcommon -lpgport -lxml2 -lssl -lcrypto -lz -lrt -lcrypt -ldl -lm VERSION = PostgreSQL 9.6.5

dhughes20 commented 5 years ago

I'm also getting similar errors in PostgreSQL 10. Sounds like this extension was not make for this version. I googled "Note Diablo" but didn't see anything. Does anyone happen to know where this extension exists?

cohenjo commented 5 years ago

Hi, Yes, unfortunately I didn’t get to work much with Postgres lately so I didn’t have time to add all the new stuff they added for later versions.

There are a couple of nice extensions that help getting to know what PG is doing. If specifically you need hypothetical indexes have a look at: https://github.com/HypoPG/hypopg/

Have a look at PoWA - https://github.com/powa-team/powa It builds on top of many of the well used pg stats extensions: pg_stat_statements pg_qualstats pg_stat_kcache pg_wait_sampling pg_track_settings

I think this should point you to a good start :) Have a nice day