citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.68k stars 671 forks source link

When we try to do large table joins on varchar columns, we get an error of the form: ERROR: cannot perform local joins that involve expressions DETAIL: local joins can be performed between columns only #76

Open Jhanbanan opened 8 years ago

Jhanbanan commented 8 years ago

When we try to do large table joins on varchar columns, we get an error of the form: ERROR: cannot perform local joins that involve expressions DETAIL: local joins can be performed between columns only. This is because we have a check in CheckJoinBetweenColumns() which requires the join clause to have only 'Var' nodes (i.e. columns). Postgres adds a relabel type cast to cast the varchar to text; hence the type of the node is not T_Var and the join fails.

Pcummings commented 8 years ago

Hey guys - I'm seeing this issue also. I'm trying to join on 2 partitioned columns which are varchar(50), unfortunately it fails with the following error: ERROR: cannot perform local joins that involve expressions DETAIL: local joins can be performed between columns only

metdos commented 8 years ago

Hey @Pcummings,

Thank you for your interest in Citus. Until we fix this issue, you can use text columns instead of varchar columns as a workaround.

Could you post your table schema and an example query -- so that when we fix this issue, we can make sure that we addressed your issue? (edited the question)

jasonmp85 commented 8 years ago

Here's the list of places I found questionable in my code search:

modify_planner

multi_logical_optimizer

multi_physical_planner

I believe #426 fixes something that wasn't even in the codebase when I initially researched #76, so more instances could have crept in during that interim period. Basically I searched for anywhere we did IsA(node, Var) but didn't call strip_implicit_coercions on node first. In any of those places, it's possible a RelabelType wrapper is wrapping the underlying Var, so the IsA check will fail.

@aamederen, can you look over the places I mentioned above and possibly see whether you can trigger any of the codepaths? If so, can you try adding strip_implicit_coercions calls to see whether the bugs can be easily fixed? These changes don't necessarily need to be pushed to #426, since that looks to fix something useful in an isolated way, but I don't want to lose track of the other places I discovered.

See this commit for the places I dropped TODOs back when I looked into this issue: 92b837281b9795622b451a9a1cdb8d1b3a350a95

sumedhpathak commented 8 years ago

@jasonmp85 @aamederen Could we separate these two into separate issues? It seems like we have some reproducible and known bugs, for which @aamederen has fixes in his PR. We also have other potential issues, which we first need to test if there are bugs at all.

While all related, I'd prefer to get some of these known bugs fixed first, and maybe keep this issue open as a high-level tracking one for the other potential problems.

Sounds OK?

jasonmp85 commented 8 years ago

While all related, I'd prefer to get some of these known bugs fixed first, and maybe keep this issue open as a high-level tracking one for the other potential problems.

Yup (I said as much above, though it was buried in the penultimate paragraph).

Sounds OK?

Yup.

metdos commented 8 years ago

Reopening to track other questionable places in the code. @aamederen will update here with his findings.