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

Add support for post_parse_analyze to PgHooks #800

Merged
merged 3 commits into from
Nov 2, 2022
Merged

Add support for post_parse_analyze to PgHooks #800

merged 3 commits into from
Nov 2, 2022

Conversation

jteplitz
Copy link

No description provided.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

There's a lot of code duplication in this PR to satisfy the cfg requirements? But it looks almost exactly the same? Why not just #[cfg] on a single let binding inside the pgx_post_parse_analyze function?

@jteplitz
Copy link
Author

Why not just #[cfg] on a single let binding inside the pgx_post_parse_analyze function?

I'd like to remove the duplicate code, but am not sure how to do it. I'm still new to rust so please let me know if there's something I can learn here!

The function signature is different in pg14 since it takes an extra argument. Is there a way to conditionally compile part of the parameter list in rust? We'd need something equivalent to this C code:

void pgx_post_parse_analyze(
ParseState *ps,
Query *query,
#if PG14 
JumbleState *jumble_state
#endif /* PG14 */
) {

My naive attempt to mark the parameter itself with a cfg attribute doesn't work

  unsafe extern "C" fn pgx_post_parse_analyze(
      parse_state: *mut pg_sys::ParseState,
      query: *mut pg_sys::Query,
      #[cfg(any(feature = "pg14"))]
      jumble_state: *mut JumbleState
  ) {
❯ cargo build --features pg11 --no-default-features
   Compiling pgx-pg-sys v0.5.3 (/home/eng/pgx/pgx-pg-sys)
   Compiling pgx v0.5.3 (/home/eng/pgx/pgx)
error[E0425]: cannot find value `jumble_state` in this scope
   --> pgx/src/hooks.rs:493:5
    |
493 |     jumble_state: *mut JumbleState
    |     ^^^^^^^^^^^^ not found in this scope

Also, I think we'd need 3 cfg blocks to make it work. Something like this:

+    #[cfg(any(feature = "pg14"))]
+    jumble_state: *mut JumbleState
 ) {
     fn prev(
         parse_state: PgBox<pg_sys::ParseState>,
         query: PgBox<pg_sys::Query>,
-        _jumble_state: Option<PgBox<JumbleState>>,
+        jumble_state: Option<PgBox<JumbleState>>,
     ) -> HookResult<()> {
         HookResult::new(unsafe {
             match HOOKS.as_mut().unwrap().prev_post_parse_analyze_hook.as_ref() {
                 None => (),
+                #[cfg(any(feature = "pg10", feature = "pg11", feature="pg12", feature="pg13"))]
                 Some(f) => (f)(parse_state.as_ptr(), query.as_ptr()),
+                #[cfg(any(feature = "pg14"))]
+                Some(f) => (f)(parse_state.as_ptr(), query.as_ptr(), jumble_state.unwrap().as_ptr()),

@workingjubilee
Copy link
Member

Ooh, the extra parameter part I didn't notice.

@workingjubilee
Copy link
Member

That might be hard to work around due to #794 but hopefully that will be fixed soon.

@workingjubilee
Copy link
Member

#813 was merged, you might want to take a second crack at this?

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

You probably will want to also support PostgreSQL 15.

@workingjubilee
Copy link
Member

I kind of wanted #794 to be fully fixed before landing this, but I don't think it's actually worth it to keep it open. So, I will approve and merge this after #830 lands and this is updated accordingly.

@BradyBonnette
Copy link
Contributor

@workingjubilee @jteplitz #830 has landed in develop

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

Thank you!

@workingjubilee workingjubilee merged commit 5361be7 into pgcentralfoundation:develop Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants