DEV Community

Michael
Michael

Posted on

GBase 8a Predicate Pushdown: _gcluster_optimizer_push_condition

When an outer query carries a condition over a subquery, the China-domestically developed GBase 8a MPP database from GBASE can push that condition down into the subquery. Fewer rows survive the inner scan, so the whole plan gets cheaper.

Parameter and values

_gcluster_optimizer_push_condition
Enter fullscreen mode Exit fullscreen mode

Enables condition pushdown. Takes [0|1|2], default 1:

  • 0: no pushdown
  • 1: pushdown at the gcluster layer
  • 2: pushdown at the gnode layer

Single-table subquery

With the default value (1), explain shows the filter (id{S} < 3) twice on the SCAN row; after turning the parameter off it appears only once.

gbase> show variables like '%_gcluster_optimizer_push_condition%';
+---------------------------------------------------------+-------+
| Variable_name                                           | Value |
+---------------------------------------------------------+-------+
| _gcluster_optimizer_push_condition                      | 1     |
+---------------------------------------------------------+-------+
1 rows in set (Elapsed: 00:00:00.00)

gbase> explain select * from (select * from t1)t where id<3;
+----+----------+-----------+------------------+-------------+-----------------+
| ID | MOTION   | OPERATION | TABLE            | CONDITION   | NO STAT Tab/Col |
+----+----------+-----------+------------------+-------------+-----------------+
| 00 | [RESULT] |  SCAN     | testdb.t1_t[DIS] | (id{S} < 3) | t1              |
|    |          |           |                  | (id{S} < 3) |                 |
+----+----------+-----------+------------------+-------------+-----------------+
2 rows in set (Elapsed: 00:00:00.00)

gbase> set _gcluster_optimizer_push_condition=0;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)

gbase> explain select * from (select * from t1)t where id<3;
+----+----------+-----------+------------------+-------------+-----------------+
| ID | MOTION   | OPERATION | TABLE            | CONDITION   | NO STAT Tab/Col |
+----+----------+-----------+------------------+-------------+-----------------+
| 00 | [RESULT] |  SCAN     | testdb.t1_t[DIS] | (id{S} < 3) | t1              |
+----+----------+-----------+------------------+-------------+-----------------+
1 row in set (Elapsed: 00:00:00.00)

gbase>
Enter fullscreen mode Exit fullscreen mode

Multi-table UNION ALL subquery

With the parameter on (the default), the id<10 filter is applied inside each table of the union all, and once more on the combined result. With it off, id<10 runs only after the union.

gbase> explain select * from (select * from t1 union all select * from t2)tt where tt.id<10;
+----+----------+-------------+---------+--------------+
| ID | MOTION   | OPERATION   | TABLE   | CONDITION    |
+----+----------+-------------+---------+--------------+
| 00 | [RESULT] |  SubQuery1  | tt      |              |
|    |          |   SCAN      | t1[DIS] | (id{S} < 10) |
|    |          |   UNION ALL |         |              |
|    |          |   SCAN      | t2[DIS] | (id{S} < 10) |
|    |          |  WHERE      |         | (id < 10)    |
+----+----------+-------------+---------+--------------+
5 rows in set (Elapsed: 00:00:00.00)

gbase> explain select * from (select * from t1 union all select * from t2)tt where tt.id<10;
+----+----------+-------------+---------+-----------+
| ID | MOTION   | OPERATION   | TABLE   | CONDITION |
+----+----------+-------------+---------+-----------+
| 00 | [RESULT] |  SubQuery1  | tt      |           |
|    |          |   Table     | t1[DIS] |           |
|    |          |   UNION ALL |         |           |
|    |          |   Table     | t2[DIS] |           |
|    |          |  WHERE      |         | (id < 10) |
+----+----------+-------------+---------+-----------+
5 rows in set (Elapsed: 00:00:00.01)
Enter fullscreen mode Exit fullscreen mode

Seeing the per-table (id{S} < 10) next to a trailing WHERE (id < 10) is how you confirm pushdown is active. Going forward, compare both explain plans before changing this on a gbase cluster — the extra inner filters usually help, but the gain depends on how selective the predicate is for the database, and a session-level set on gbase is the fastest way to A/B it without a restart.

Top comments (0)