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

Infinite compile time with slightly modified sql (no error) #1116

Open
enaut opened this issue Mar 17, 2021 · 2 comments
Open

Infinite compile time with slightly modified sql (no error) #1116

enaut opened this issue Mar 17, 2021 · 2 comments
Labels
bug db:sqlite Related to SQLite

Comments

@enaut
Copy link

enaut commented Mar 17, 2021

I hat a "working" program and realized I made a logic error while querying - meaning I did not get all results. So I exchanged the sqlquery with a working one (tested in sqlite) but now my build does not compile any more. Not as usual that I forgot to change something... But now it starts compilation, compiles all the modules then maxes one CPU with my last module and does so forever cancelled after 15 min +, where it was done before in max 2 minutes on full rebuild.

I use sqlx in combination with actix-web which is why I can't use the most recent version.

sqlx={version="0.4", features = [ "sqlite", "macros", "runtime-actix-rustls", "chrono", "migrate" ]}

The logically incorrect but working query:

select
    links.id,
    links.title,
    links.target,
    links.code,
    links.author,
    links.created_at,
    users.id as uid,
    users.username,
    users.email,
    users.role,
    count as count
from
    links
    join (
        select
            clicks.link,
            count(clicks.id) as count
        from
            clicks
        group by
            clicks.link
    ) on links.id = link
    join users on links.author = users.id

The failing query:

select
    links.id,
    links.title,
    links.target,
    links.code,
    links.author,
    links.created_at,
    users.id as uid,
    users.username,
    users.email,
    users.role,
    count(click) as count
from
    links
    left join (
        select
            clicks.link,
            clicks.id as click
        from
            clicks
    ) on links.id = link
    join users on links.author = users.id
    group by links.id

the .schema

CREATE TABLE users
(
    id INTEGER PRIMARY KEY NOT NULL,
    username VARCHAR NOT NULL,
    email VARCHAR NOT NULL,
    password VARCHAR NOT NULL, role INTEGER DEFAULT 1 NOT NULL,

    UNIQUE(username, email)
);
CREATE TABLE links
(
    id INTEGER PRIMARY KEY NOT NULL,
    title VARCHAR NOT NULL,
    target VARCHAR NOT NULL,
    code VARCHAR NOT NULL,
    author INT NOT NULL,
    created_at TIMESTAMP NOT NULL,


    FOREIGN KEY
    (author)
       REFERENCES users
    (id),

    UNIQUE
    (code)
);
CREATE TABLE clicks
(
    id INTEGER PRIMARY KEY NOT NULL,
    link INT NOT NULL,
    created_at TIMESTAMP NOT NULL,

    FOREIGN KEY
    (link)
       REFERENCES links
    (id)
);
@enaut
Copy link
Author

enaut commented Mar 18, 2021

I experimented a little again but could not get this to compile with the query*! macros.

The same query compiles and runs just fine and as expected when I use the sqlx::query function

@TheNeikos
Copy link

TheNeikos commented Aug 5, 2021

This got fixed in #1002, a backport to 0.4.x would be great!

I have a fork here, where I applied this ontop of 0.4: https://github.com/TheNeikos/sqlx/tree/release/0.4

Use at your own discretion, as this might not be online forever (best would be to fork it yourself and maintain it there until you can switch to the latest version)

@abonander abonander added bug db:sqlite Related to SQLite labels Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug db:sqlite Related to SQLite
Projects
None yet
Development

No branches or pull requests

3 participants