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

panic when using subquery with jsonb_array_elements #12998

Closed
cloudcarver opened this issue Oct 23, 2023 · 0 comments · Fixed by #13098
Closed

panic when using subquery with jsonb_array_elements #12998

cloudcarver opened this issue Oct 23, 2023 · 0 comments · Fixed by #13098
Assignees
Labels
type/bug Something isn't working
Milestone

Comments

@cloudcarver
Copy link
Contributor

cloudcarver commented Oct 23, 2023

Describe the bug

Original Problem

✅The following statement works:

SELECT jsonb_array_elements(
    sharpe_ratio_based_opt(
        (
            SELECT jsonb_agg(u ORDER BY name) FROM assets_stat
        ), 
        (
            SELECT 
                jsonb_agg(jsonb_agg ORDER BY asset_a) AS Q 
            FROM (
                SELECT jsonb_agg(covar ORDER BY asset_b), asset_a 
                FROM covariances 
                GROUP BY asset_a)
        ), 
        0.0::FLOAT8
    )
);

✅This statement also works:

SELECT * FROM jsonb_array_elements(
    sharpe_ratio_based_opt('[0.5, 0.6]'::JSONB, '[[0.1, 0], [0, 0.2]]'::JSONB, 0.0::FLOAT8)
);

❌ However, this is not working:

SELECT * FROM jsonb_array_elements(
    sharpe_ratio_based_opt(
        (
            SELECT jsonb_agg(u ORDER BY name) FROM assets_stat
        ), 
        (
            SELECT 
                jsonb_agg(jsonb_agg ORDER BY asset_a) AS Q 
            FROM (
                SELECT jsonb_agg(covar ORDER BY asset_b), asset_a 
                FROM covariances 
                GROUP BY asset_a)
        ), 
        0.0::FLOAT8
    )
);

getting:

ERROR:  Panicked when processing: internal error: entered unreachable code: Subquery Subquery { kind: Scalar, query: BoundQuery { body: Select(BoundSelect { distinct: All, select_items: [jsonb_agg($1)], aliases: [Some("jsonb_agg")], from: Some(BaseTable(BoundBaseTable { table_id: TableId { table_id: 9001 }, table_catalog: TableCatalog { id: TableId { table_id: 9001 }, associated_source_id: None, name: "assets_stat", columns: [ColumnCatalog { column_desc: ColumnDesc { data_type: Varchar, column_id: #1, name: "name", field_descs: [], type_name: "", generated_or_default_column: None }, is_hidden: false }, ColumnCatalog { column_desc: ColumnDesc { data_type: Float64, column_id: #2, name: "u", field_descs: [], type_name: "", generated_or_default_column: None }, is_hidden: false }, ColumnCatalog { column_desc: ColumnDesc { data_type: Float64, column_id: #3, name: "d", field_descs: [], type_name: "", generated_or_default_column: None }, is_hidden: false }, ColumnCatalog { column_desc: ColumnDesc { data_type: Serial, column_id: #0, name: "_row_id", field_descs: [], type_name: "", generated_or_default_column: None }, is_hidden: true }], pk: [$3 ASC], stream_key: [3], table_type: Table, distribution_key: [3], append_only: false, cardinality: Cardinality { lo: 0, hi: Unlimited }, owner: 1, properties: WithOptions { inner: {} }, fragment_id: 8001, dml_fragment_id: Some(8002), vnode_col_index: None, row_id_index: Some(3), value_indices: [0, 1, 2, 3], definition: "CREATE TABLE assets_stat (name CHARACTER VARYING, u float8, d float8)", conflict_behavior: Overwrite, read_prefix_len_hint: 1, version: Some(TableVersion { version_id: 0, next_column_id: #4 }), watermark_columns: FixedBitSet { data: [0], length: 4 }, dist_key_in_pk: [], created_at_epoch: Some(Epoch(5295450471006208)), initialized_at_epoch: Some(Epoch(5295450467598336)), cleaned_by_watermark: false }, table_indexes: [], for_system_time_as_of_proctime: false })), where_clause: None, group_by: GroupKey([]), having: None, schema: Schema { fields: [jsonb_agg:Jsonb] } }), order: [], limit: None, offset: None, with_ties: false, extra_order_exprs: [] } } has not been unnested.
This is a bug. We would appreciate a bug report at https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Fbug&template=bug_report.yml
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

Simplified Problem

SELECT jsonb_array_elements((SELECT '[1, 2, 3]'::JSONB));

SELECT * FROM jsonb_array_elements('[1, 2, 3]'::JSONB);

SELECT * FROM jsonb_array_elements((SELECT '[1, 2, 3]'::JSONB));

getting:

ERROR:  Panicked when processing: internal error: entered unreachable code: 
Subquery Subquery { kind: Scalar, query: BoundQuery { body: Select(BoundSelect { distinct: All, select_items: ['[1, 2, 3]':Varchar::Jsonb], aliases: [Some("JSONB")], from: None, where_clause: None, group_by: GroupKey([]), having: None, schema: Schema { fields: [JSONB:Jsonb] } }), order: [], limit: None, offset: None, with_ties: false, extra_order_exprs: [] } } has not been unnested.
This is a bug. We would appreciate a bug report at https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Fbug&template=bug_report.yml

How did you deploy RisingWave?

docker

The version of RisingWave

dev=> SELECT VERSION();
                                  version                                   
----------------------------------------------------------------------------
 PostgreSQL 9.5-RisingWave-1.3.0 (c4c31bdc5e8763ae65ec23293e8c07bdfd4ab4df)
(1 row)

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants