Git Product home page Git Product logo

Comments (1)

EdMcBane avatar EdMcBane commented on June 15, 2024

It looks like supabase_wrappers::scan::get_foreign_plan allocates the scan_clauses that end up in the query plan from the FDW temp memory context (state.tmp_ctx), which appears to be erroneous, as EXPLAIN ANALYZE accesses the plan and its quals well after the context has been reset by the many other calls to temp_ctx.reset.

It appears the plan and quals need to be allocated in the query memory context (the current one when supabase_wrappers::scan::get_foreign_plan is called) to live enough.

I'm wondering whether there are other similar instances due to the extensive use of state.temp_ctx for allocating data returned to pg.

At the moment, changing the code of supabase_wrappers::scan::get_foreign_plan as follows fixes the problem:

#[pg_guard]
pub(super) extern "C" fn get_foreign_plan<W: ForeignDataWrapper>(
    _root: *mut pg_sys::PlannerInfo,
    baserel: *mut pg_sys::RelOptInfo,
    _foreigntableid: pg_sys::Oid,
    _best_path: *mut pg_sys::ForeignPath,
    tlist: *mut pg_sys::List,
    scan_clauses: *mut pg_sys::List,
    outer_plan: *mut pg_sys::Plan,
) -> *mut pg_sys::ForeignScan {
    debug2!("---> get_foreign_plan");
    unsafe {
        let mut state = PgBox::<FdwState<W>>::from_pg((*baserel).fdw_private as _);
        // DO NOT ALLOCATE IN THE TEMP MEMCTX; pg will use the plan later if EXPLAIN ANALYZEing
        // state.tmp_ctx.reset();
        // let mut old_ctx = state.tmp_ctx.set_as_current();

        // make foreign scan plan
        let scan_clauses = pg_sys::extract_actual_clauses(scan_clauses, false);

        // old_ctx.set_as_current();

from wrappers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.