Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use create_upper_paths_hook for hypertable insert plan modifications #904

Conversation

erimatnor
Copy link
Contributor

This change refactors how we do planner modifications to insert data
into a hypertable. Instead of altering the finished plan tree produced
by the standard planner, we now use the create_upper_paths_hook to do
these modifications at the path stage during planning.

Apart from being a cleaner, and arguably more principled, way of doing
plan modifications, it also gives us better ability to modify plan
state during planning since the hook happens during the normal planner
run and not after. For instance, our CustomScan insert plan is now
created using a callback that has access to the PlannerInfo data,
which will be useful when planning, e.g., foreign queries using the
foreign data wrapper API.

NOTE: this is a change that we need for clustering.

@erimatnor erimatnor force-pushed the enordstr/refactor-insert-hooks-to-use-paths branch 2 times, most recently from 6b7a0e8 to afd9ac2 Compare December 14, 2018 08:33
@codecov-io
Copy link

codecov-io commented Dec 14, 2018

Codecov Report

Merging #904 into master will decrease coverage by 0.03%.
The diff coverage is 98.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #904      +/-   ##
==========================================
- Coverage   91.25%   91.22%   -0.04%     
==========================================
  Files          80       79       -1     
  Lines        9242     9227      -15     
==========================================
- Hits         8434     8417      -17     
- Misses        808      810       +2
Impacted Files Coverage Δ
src/plan_add_hashagg.c 97.05% <ø> (ø) ⬆️
src/hypertable_insert.c 97.26% <100%> (+2.97%) ⬆️
src/chunk_dispatch_plan.c 100% <100%> (+6.97%) ⬆️
src/planner.c 93.15% <95.65%> (-0.44%) ⬇️
src/loader/bgw_launcher.c 86.05% <0%> (-2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b137844...995e864. Read the comment docs.

@erimatnor erimatnor force-pushed the enordstr/refactor-insert-hooks-to-use-paths branch 2 times, most recently from dcb24d3 to 18b6c77 Compare December 14, 2018 09:11
Copy link
Contributor

@cevian cevian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments. But I feel I should point out that now we are doing manipulation for each path where before we did it for each plan (and there are more paths than plans). This is probably the right thing to do anyway but thought I'd point out this potential downside.

src/planner.c Outdated Show resolved Hide resolved
src/planner.c Outdated Show resolved Hide resolved
src/hypertable_insert.c Show resolved Hide resolved
src/hypertable_insert.c Outdated Show resolved Hide resolved
Copy link
Contributor

@niksajakovljevic niksajakovljevic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I left two minor comments.

src/hypertable_insert.c Show resolved Hide resolved
src/hypertable_insert.c Outdated Show resolved Hide resolved
@erimatnor erimatnor force-pushed the enordstr/refactor-insert-hooks-to-use-paths branch 5 times, most recently from d6e553f to fccce29 Compare December 18, 2018 08:20
This change refactors how we do planner modifications to insert data
into a hypertable. Instead of altering the finished plan tree produced
by the standard planner, we now use the create_upper_paths_hook to do
these modifications at the path stage during planning.

Apart from being a cleaner, and arguably more principled, way of doing
plan modifications, it also gives us better ability to modify plan
state during planning since the hook happens during the normal planner
run and not after. For instance, our CustomScan insert plan is now
created using a callback that has access to the PlannerInfo data,
which will be useful when planning, e.g., foreign queries using the
foreign data wrapper API.
@erimatnor erimatnor force-pushed the enordstr/refactor-insert-hooks-to-use-paths branch from fccce29 to 995e864 Compare December 18, 2018 17:45
Copy link
Contributor

@cevian cevian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. At some point we might consider just using our own node instead of wrapping modifyTable (to allow better re-use with the copy code). But I think that's a separate project.

Index rti = lfirst_int(lc_rel);
RangeTblEntry *rte = planner_rt_fetch(rti, root);

ht = ts_hypertable_cache_get_entry(hcache, rte->relid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to add a check here that we are always talking about the same hypertable here... That we aren't somehow mixing hypertables.

@erimatnor erimatnor merged commit d2edf3a into timescale:master Dec 19, 2018
@erimatnor erimatnor deleted the enordstr/refactor-insert-hooks-to-use-paths branch December 19, 2018 08:22
@JLockerman JLockerman added this to the 1.2.0 milestone Jan 29, 2019
@geetikabatra
Copy link

geetikabatra commented Aug 2, 2019

Hi @erimatnor, I came across this PR while trying to find a solution for HA TimescaleDB(link). I have a HA postgres cluster setup using Patroni. I would like to have a HA TimescaleDB on top of it. I know that it requires streaming replication for this use. How do I make it highly available and fail safe? Basic solution that comes to my mind is running two Timescale DB instances and then using HA Proxy over it. What do you think about it? Is there any other way to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants