Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This diff implemented support for PostgreSQL. It has three main sections. - PostgreSQL utility functions in C++ - Compiler - Server Support - DocDB, Tablet, and Master. ============================================== PostgreSQL utility ============================================== We convert PostgreSQL code from C to C++ libraries and use the code for two main purposes. It's implemented in /yb/yql/pgsql/ybpostgres - Process messages coming from PostgreSQL clients. - Constructing messages to send to PostgreSQL clients. ============================================== Compiler Implementation ============================================== This diff compile Postgresql statements into protobuf code, which will be executed by DocDB. A. The database objects. - The "TABLE" is using "OID BIGINT" as hash key. When the table doesn't have its own primary key, "CTID TIMEUUID" is used as primary key. During insertion, the value "0" is always inserted into "OID" column. For database accessing, the conditional clause "WHERE oid = 0" would be attached to all statements. B. Implementation: The implementation for Postgresql support is divided into several components, each of which is developed in one directory and built into one library. The following notes describe the content and purpose of each library. (0) The yql/pgsql/processor library - This library defines the API for the compilation and execution processes. - This is the driver of all SQL statement processing. (1) The yql/pgsql/ybpostgres library - This library contains various utility functions that was developed by the original Postgresql. - Yugabyte components will call the utility functions in this library to perform their tasks. - The code has been converted into C++ style, but the contents is originated from Postgresql. (2) The yql/pgsql/util library - This library contains various utility functions that was developed by Yugabyte. (3) The yql/pgsql/syn library - This library contains the parser that compile SQL statements into parse tree. - We modify Postgresql original lex and yacc files to generate our own treeenodes. (4) The yql/pgsql/sem library - This library runs semantic analysis. ( 5) The yql/pgsql/pbgen library - This library traverses the parse tree to generate Protobuf code for all statement except DDL statements. - The generated protobuf code can be cached in tablet server with a statement ID for future use. - We might consider generate PB for DDL statement also. The executor would just send these PBs to master server for execution. (6) The yql/pgsql/pbexec library - For DDL statement, this library executes the treenode directly. - For non-DDL statement or statements that can be prepared, this library executes the generated protobuf code. (7) The yql/pgsql/ptree library - This library defines the treenode. - For coding convenience, the actually semantics analysis for each tree node is defined in the Analyze() method of each tree node. The semantic analyzer will call these functions when processing statements. (8) The yql/pgsql/proto library - This library defines the YugaByte protobuf code to be executed by tablet server. - In the future, tablet server should cache these PB code so that the compilation steps can be skipped over. (9) The yb/util/bf_pgsql - This library will be moved to "pgsql" directory later. - This library defines all supported functions and operators in Posgresql. - Operators such as +, -, /, *, =, >, >=, <, <=, etc are all specified and defined here. - Utility functions such as sin, cos, power, etc are specified and defined here. - Database-dependent functions such as aggregate functions are specified here, but their execution code are defined in tablet server. (10) The protocols in "yb/common" - The file "pgsql_protocol.proto" contains the protocol for communication between the proxy and tablet server. ============================================== DocDB, Tablet, and Master Implementation ============================================== - PGSQL types are added to distinguish clients, databases, schemas, tables, messages, and any DB entities from CQL and REDIS - The rest of the implementation is similar or the same as that for CQL and REDIS. Test Plan: Will be done on my next diff. Reviewers: mihnea, robert Reviewed By: robert Subscribers: mikhail, eng Differential Revision: https://phabricator.dev.yugabyte.com/D4245
- Loading branch information