Skip to content

Performance issue with SET VARIABLE #13993

@Beranger

Description

@Beranger

What happens?

The same request wrapping with the setting of a variable is way longer than the same request without the SET VARIABLE. I found it on a large duckdb database stored in our buckets but I manage to reproduce it with a simple example.
I find a workaround when trying to debug it, it s to use EXPLAIN ANALYSE

To Reproduce

code to reproduce:

SET enable_profiling TO 'no_output';
create table test as select range(10000000) as i;

.timer on
SELECT i
FROM test
WHERE i = null
LIMIT 1;

SET VARIABLE var_test = (
    SELECT i
    FROM test
    WHERE i = null
    LIMIT 1
);

EXPLAIN ANALYSE
SET VARIABLE var_test = (
    SELECT i
    FROM test
    WHERE i = null
    LIMIT 1
);

output:

D .timer on
D SELECT i
  FROM test
  WHERE i = null
  LIMIT 1;
Run Time (s): real 0.004 user 0.000000 sys 0.003315
D 
D SET VARIABLE var_test = (
      SELECT i
      FROM test
      WHERE i = null
      LIMIT 1
  );
Run Time (s): real 0.050 user 0.065433 sys 0.032705
D 
D EXPLAIN ANALYSE
  SET VARIABLE var_test = (
      SELECT i
      FROM test
      WHERE i = null
      LIMIT 1
  );
Run Time (s): real 0.001 user 0.001275 sys 0.000000

OS:

Ubuntu 22 x86_64

DuckDB Version:

1.1.0

DuckDB Client:

duckdb

Hardware:

I reproduce the issue on several hardware

Full Name:

Beranger Browaeys

Affiliation:

Nielseniq

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a nightly build

Did you include all relevant data sets for reproducing the issue?

No - Other reason (please specify in the issue body)

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions