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

perf(expr): support writer-style #[function] for bytea, jsonb and array type #13263

Open
wangrunji0408 opened this issue Nov 6, 2023 · 1 comment

Comments

@wangrunji0408
Copy link
Contributor

wangrunji0408 commented Nov 6, 2023

Is your feature request related to a problem? Please describe.

For functions that return varchar, we now support writer-style signatures, allowing functions to write results directly to the array buffer.

#[function("trim(varchar) -> varchar")]
pub fn trim(s: &str, writer: &mut impl Write) {
    writer.write_str(s.trim()).unwrap();
}

But this is not supported for functions that return bytea, jsonb or arrays. They have to return owned Box<[u8]>, JsonbVal or ListVal right now, which causes unnecessary overhead of malloc and memcpy.

Describe the solution you'd like

Similar to varchar, we can support a writer of type impl std::io::Write for bytea:

#[function("concat_op(bytea, bytea) -> bytea")]
pub fn concat_op(left: &[u8], right: &[u8], writer: &mut impl std::io::Write) {
    writer.write(left).unwrap();
    writer.write(right).unwrap();
}

and type JsonbBuilder(jsonbb::Builder) for jsonb:

#[function("subtract(jsonb, varchar) -> jsonb")]
fn jsonb_remove(v: JsonbRef<'_>, key: &str, builder: &mut JsonbBuilder) -> Result<()> {
    ...
}

Describe alternatives you've considered

No response

Additional context

No response

@github-actions github-actions bot added this to the release-1.5 milestone Nov 6, 2023
@wangrunji0408 wangrunji0408 changed the title perf(expr): support writer-style #[function] for bytea and jsonb type perf(expr): support writer-style #[function] for bytea, jsonb and array type Nov 8, 2023
@fuyufjh fuyufjh modified the milestones: release-1.5, release-1.6 Dec 6, 2023
@wangrunji0408 wangrunji0408 modified the milestones: release-1.6, release-1.7 Jan 9, 2024
Copy link
Contributor

This issue has been open for 60 days with no activity. Could you please update the status? Feel free to continue discussion or close as not planned.

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

No branches or pull requests

2 participants