Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[yugabyte#2040] YSQL: Framework for expression pushdown part 2
Summary: Further extension of work done in 05a5386, which allows to execute Postgres code within TServer process. We use this ability to execute Postgres expression generated by the planner where data are and hence reduce amount data sent across network. In part 2 expression pushdown support for UPDATE statement was reworked, and support for sequential scan conditions was added. Summary of changes: # Refined communication protocol to send Postgres expressions down to DocDB. Now protobuf can carry three separate lists: ## Conditional expressions (row filter). Evaluated against current row, if any evaluation result is false, row is ignored; ## Target expression. Evaluated against current row to calculate values to insert into the table or return back to Postgres, or both; ## List of columns referenced by A and/or B. Column reference consists of DocDB identifier to locate value in the current row, Postgres identifier, by which the expressions refer it and Postgres type info needed to convert DocDB value to Datum/isnull pair expected by Postgres code. # Created new class DocPgExprExecutor to encapsulate Postgres expression evaluation. An instance of that class is intended to live during the protobuf request's handling and optimized to evaluate same set of expressions against multiple rows having same schema (rows of the same table). Lifecycle of a DocPgExprExecutor consists of two phases: initialization and evaluation. During initialization phase caller is supposed to provide table schema as well as conditions, targets and column references extracted from the protocol message. Those elements are processed and stored in internal data structures in a form optimized for fast evaluation. Elements provided during initialization phase can not be modified after evaluation phase begins. During evaluation phase caller provides the row and the storage for target values. The executor extracts the values and convert them to Postgres Datum/isnull pairs according to the column references. Then executor evaluates the conditions, and if any result is false the execution stops and result returned, target storage remains unchanged. If all they true, the executor evaluates target expressions and stores results. # Planner now has single function YbCanPushdownExpr to determine if DocDB can evaluate the expression. Same function collects column references along the way. A GUC variable yb_enable_expression_pushdown was introduced. If set to false, it makes YbCanPushdownExpr to always return false and effectively disable pushdown. The default is false for compatibility, if cluster undergoing rolling upgrade, plans without pushdown are compatible with older DocDB. Same logic that used to determine expression pushability was used for loosely related tasks, like analyze returning clause expression, determine if the statement is a "single row" a.k.a. "fast path". These logics are corrected. # Effectively reverts yugabyte#5257, see the comments on the issue for details. Features not implemented, but potentially can make part 3: - Push down conditions for UPDATE, DELETE statements, non-index conditions for index scans; - Push down target expressions for scans, if that reduces returned row width; - Parallel execution of expressions with pushed down conditions. They are expected to return much less bytes per second of results and Postgres instance collecting results less likely to become bottleneck; - Eliminate other DocDB expression types used by Postgres. They are simple ones (columns, constants) and can be replaced by equivalent serialized Postgres expressions. Test Plan: New tests were added where pushdown is enabled for the session: `ybd --java-test 'org.yb.pgsql.TestPgRegressPushdown'` Tests updated to reflect changes: `ybd --java-test 'org.yb.pgsql.TestPgRegressDml'` `ybd --java-test 'org.yb.pgsql.TestPgRegressPlanner'` For QA testing if upgrade from previous versions is not involved it is recommended to enable pushdown cluster-wide: `yb-ctl create --ysql_pg_conf_csv='yb_enable_expression_pushdown=true'` There might be differences in plans, but the query results are expected to be the same. Reviewers: neil, dsrinivasan, myang, yguan, jason, dmitry, mihnea Reviewed By: jason, mihnea Subscribers: mbautin, smishra, zyu, yql Differential Revision: https://phabricator.dev.yugabyte.com/D13038
- Loading branch information