dolthub / go-mysql-server

A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aliases overwriting original column

robertf224 opened this issue · comments

Hi, I'm investigating creating a wrapper around this project for use in NodeJS, and in particular using prisma.

Issue I ran into came up when I tried using the prisma cli to push a schema into an in-memory db (modeled after the _example) directory using prisma's db push command. I first got an error about the INFORMATION_SCHEMA db not existing and copied this line to get that working. Then I ran into the actual issue here, which was this error: table "table_info" does not have column "table_name". I traced the error to this query in the prisma codebase.

You can repro by running this command against the _example directory example (after adding the information schema db):

SELECT DISTINCT BINARY table_info.table_name AS table_name
    FROM information_schema.tables AS table_info
    JOIN information_schema.columns AS column_info
        ON BINARY column_info.table_name = BINARY table_info.table_name
    WHERE
        table_info.table_schema = 'mydb'
        AND column_info.table_schema = 'mydb'
        -- Exclude views.
        AND table_info.table_type = 'BASE TABLE'
    ORDER BY BINARY table_info.table_name;

If you remove either the AS table_name in the column selection, or change the order by to just table_name, the query works as intended. I'm going to dig around a little bit and see if I can figure it out, but appears to have something to do with the alias AS table_name making table_info.table_name (the fully qualified column name) no longer accessible to the order by (interestingly the use of table_info.table_name in the join does not seem to matter).

Hi @robertf224, thanks for taking the time to report this bug. Working seamlessly with ORMs is one of our priorities right now. In general you will get more eyes on issues when you file them in the dolt repo even if you are only using the memory implementation right now.

I've been unable to reproduce your error so far. I added info schema to the database provider in _example/main.go, and ran variations of the query above while connected to the in-memory server instance. Is there any other setup I am missing? We definitely have existing alias issues, both with and without ORDER BY clauses.

Is this against the latest released version, or building from main?

ah good shout, I was running against the latest release / had just copy/pasted code from _example, works when I run against main. is there going to be a release soon? just managed to get it working w prisma w/ a simpler schema, tho in our full schema I ran into Error: unsupported feature: fulltext keys are unsupported but closer!

fulltext keys are still unsupported but on the roadmap for the next quarter:

dolthub/dolt#2987

As mentioned, we maintain both Dolt and go-mysql-server but we pay more attention to the Dolt queue because that's what most people use. So, if you see something you need SQL-wise, check there too.

awesome thanks! will track