Skip to content

INTERNAL Error: Attempted to access index 5 within vector of size 5 #15307

@ongspxm

Description

@ongspxm

What happens?

$ ./duckdb <06.sql 
INTERNAL Error: Attempted to access index 5 within vector of size 5
This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/dev/internal_errors

was trying to solve adventofcode2024 using duckdb, but i hit some internal errors

if anybody nids more info, or can point to me which part of the code base to look at,
i will try my best to read some code, and try to patch it up... (first time doing duckdb code)

To Reproduce

.mode csv

create table grid0 as (select vv[2] as c, vv[1] as cn, rn-1 as rn from
(select unnest(list_zip(range(130),string_split(column0,''))) as vv,
row_number() over () as rn from read_csv('input.txt',header=false)));

create table dd(d int,dx int,dy int);
insert into dd(d,dx,dy) values
(0,0,-1), (1,1,0), (2,0,1), (3,-1,0);

create macro get_grid(wx,wy) as table (
select c,cn,rn from grid0 where not (cn=wx and rn=wy)
union all select '#',wx,wy);

# preprocess cos actual process too expensive
create macro get_next(wx,wy) as table (with recursive
grid as (select * from get_grid(wx,wy))
select
    x0, y0, d0,
    case when v then x1 else x0 end as x1,
    case when v then y1 else y0 end as y1,
    case when v then d0 else (d0+1)%4 end as d1
from (select
    *, grid.c!='#' as v from
(select
    grid.cn as x0, grid.rn as y0, dd.d as d0,
    grid.cn+dd.dx as x1, grid.rn+dd.dy as y1,
from grid cross join dd where grid.c!='#')
join grid on x1=cn and y1=rn));

create macro get_path(wx,wy) as table (with recursive
grid as materialized (select * from get_grid(wx,wy)),
next as materialized (select * from get_next(wx,wy)),
p as (
select cn as x,rn as y,0 as d, [cn||'_'||rn||'_'||d] as hh
from grid where c='^'
union all
select next.x1, next.y1, next.d1 as d,
    list_append(p.hh, next.x1||'_'||next.y1||'_'||next.d1) as hh
from p join next on p.x=next.x0 and p.y=next.y0 and p.d=next.d0
where not exists (select 1 from (select unnest(p2.hh) as c from p p2)
    group by c having count(*)>1))
select *, row_number() over () as s from p);

create table steps as (select * from get_path(-1,-1));
select count(*) as ans1 from (select x,y from steps group by x,y);

create macro have_loop(wx,wy) as (select max(c)==2 from
(select count(*) as c from get_path(wx,wy) group by x,y,d));

create table aa as
(select cn,rn from steps
join dd on steps.d=dd.d
join grid0 on steps.x+dd.dx=grid0.cn and steps.y+dd.dy=grid0.rn
where grid0.c!='#' group by cn,rn limit 1);

# this is the line that triggers the error
select cn,rn,have_loop(cn,rn) as v from aa;

file.sql

....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...

input.txt

OS:

x86_64

DuckDB Version:

v1.1.3 1986445

DuckDB Client:

cli

Hardware:

No response

Full Name:

metta ong

Affiliation:

nus

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

I have tested with a stable release

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

Yes

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