|
7 | 7 | #include <access/tsmapi.h> |
8 | 8 | #include <access/xact.h> |
9 | 9 | #include <catalog/namespace.h> |
| 10 | +#include <catalog/pg_inherits.h> |
10 | 11 | #include <commands/extension.h> |
11 | 12 | #include <executor/nodeAgg.h> |
12 | 13 | #include <miscadmin.h> |
@@ -447,20 +448,10 @@ preprocess_query(Node *node, PreprocessQueryContext *context) |
447 | 448 | if (ht) |
448 | 449 | { |
449 | 450 | /* |
450 | | - * Mark hypertable RTEs we'd like to expand ourselves. |
451 | | - * We always do this for SELECTs from hypertables. |
452 | | - * |
453 | | - * For DML, we also always expand the non-target relations. |
454 | | - * |
455 | | - * The hypertables that are not expanded by our custom code |
456 | | - * here fall back to the standard Postgres inheritance |
457 | | - * hierarchy expansion. |
| 451 | + * Hypertable expansion marking is done in the |
| 452 | + * get_relation_info_hook, which also handles |
| 453 | + * hypertables appearing after function or view inlining. |
458 | 454 | */ |
459 | | - if (ts_guc_enable_optimizations && ts_guc_enable_constraint_exclusion && |
460 | | - rte->inh && (Index) query->resultRelation != rti) |
461 | | - { |
462 | | - rte_mark_for_expansion(rte); |
463 | | - } |
464 | 455 |
|
465 | 456 | if (TS_HYPERTABLE_HAS_COMPRESSION_TABLE(ht)) |
466 | 457 | { |
@@ -1500,20 +1491,6 @@ timescaledb_set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, Rang |
1500 | 1491 | break; |
1501 | 1492 |
|
1502 | 1493 | case TS_REL_HYPERTABLE: |
1503 | | - /* |
1504 | | - * Set the indexlist for a hypertable parent to NIL since we |
1505 | | - * should not try to do any index scans on hypertable parents, |
1506 | | - * similar to how it works for partitioned tables. |
1507 | | - * |
1508 | | - * This can happen when building a merge join path and computing |
1509 | | - * cost for it. See get_actual_variable_range(). |
1510 | | - * |
1511 | | - * This has to be after the hypertable is expanded, since the |
1512 | | - * indexlist is used during hypertable expansion. |
1513 | | - */ |
1514 | | - |
1515 | | - rel->indexlist = NIL; |
1516 | | - |
1517 | 1494 | if (!rte->inh) |
1518 | 1495 | { |
1519 | 1496 | /* |
@@ -1565,15 +1542,21 @@ timescaledb_get_relation_info_hook(PlannerInfo *root, Oid relation_objectid, boo |
1565 | 1542 | { |
1566 | 1543 | /* |
1567 | 1544 | * Mark hypertable RTEs we'd like to expand ourselves. |
1568 | | - * Hypertables inside inlineable functions don't get marked during |
1569 | | - * the query preprocessing step handled in preprocess_query(). |
1570 | | - * Therefore we do an extra try here. |
| 1545 | + * We always do this for SELECTs from hypertables. |
| 1546 | + * |
| 1547 | + * For DML, we also always expand the non-target relations. |
| 1548 | + * |
| 1549 | + * The hypertables that are not expanded by our custom code |
| 1550 | + * here fall back to the standard Postgres inheritance |
| 1551 | + * hierarchy expansion. |
1571 | 1552 | * |
1572 | | - * For the explanation of the logic, see the comments in |
1573 | | - * preprocess_query(). |
| 1553 | + * `inhparent` goes to false in two cases: a hypertable without |
| 1554 | + * chunks or a SELECT FROM ONLY hypertable. We still want to run our |
| 1555 | + * hypertable expansion code for hypertables w/o chunks. |
1574 | 1556 | */ |
1575 | | - if (ts_guc_enable_optimizations && ts_guc_enable_constraint_exclusion && inhparent && |
1576 | | - rte->ctename == NULL && rel->relid != (Index) query->resultRelation) |
| 1557 | + if (ts_guc_enable_optimizations && ts_guc_enable_constraint_exclusion && |
| 1558 | + (inhparent || !has_subclass(rte->relid)) && rte->ctename == NULL && |
| 1559 | + rel->relid != (Index) query->resultRelation) |
1577 | 1560 | { |
1578 | 1561 | rte_mark_for_expansion(rte); |
1579 | 1562 | } |
|
0 commit comments