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

Hstore query support #3285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Hstore query support #3285

wants to merge 1 commit into from

Conversation

yinzara
Copy link

@yinzara yinzara commented Sep 19, 2024

This PR adds support for querying on hstore type columns which can map to either Dictionary<string, string> or ImmutableDictionary<string, string> in C#.

The following methods and properties are available for translation:

  • Dictionary<string, string>.Item (i.e. myDictionary["key"])
  • Dictionary<string, string>.Item
  • Dictionary<string, string>.ContainsKey
  • ImmutableDictionary<string, string>.ContainsKey
  • Dictionary<string, string>.ContainsValue
  • ImmutableDictionary<string, string>.ContainsValue
  • Dictionary<string, string>.Count
  • ImmutableDictionary<string, string>.Count
  • ImmutableDictionary<string, string>.IsEmpty
  • Enumerable.Any

AFAIK this is all the properties that could ever support translation except those that modify the hstore.
I attempted Keys and Values and could never get it to work correctly.

Fixes #212

@yinzara yinzara force-pushed the feature/212 branch 2 times, most recently from 8f6dad8 to 49431a8 Compare September 19, 2024 19:21

SELECT s."Id", s."Dictionary", s."DictionaryContainerEntityId", s."ImmutableDictionary", s."NullableDictionary", s."NullableImmutableDictionary"
FROM "SomeEntities" AS s
WHERE s."Dictionary" -> 'key' = @__valueToTest_0
Copy link
Author

@yinzara yinzara Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing this line to line 186, you see that when using a normal Dictionary<string, string>, accessing the indexer property causes the key being passed as the index to be a SqlConstantExpression while if use use an ImmutableDictionary<string, string>, the key being passed as the index is instead a SqlParameterExpression.

With the Nullable dictionary examples, you see the same behavior however you can see that for the ContainsKey translation, the key is being passed as the SqlParameterExpression both in the normal Dictionary and the ImmutableDictionary.

I have wracked my brain and looked throughout the codebase on how this could possibly happen. I do not treat the two types of dictionaries any differently in the hstore code I've added so the variation seems extremely perplexing to me.

This technically will not cause a functional issue. It will work either way.

However, because the Dictionary<string, string> access is being passed as a constant and not a parameter, if a 2nd query is made on a different key in the same running application, it will require a completely new query plan and not reuse the existing cached query.

Anyone have any ideas why this might be happening?

I don't think this should really hold up the PR, it's just strange :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translate hstore access to SQL
1 participant