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

Map elementAt and hash table lookup #16476

Open
arunthirupathi opened this issue Jul 23, 2021 · 0 comments
Open

Map elementAt and hash table lookup #16476

arunthirupathi opened this issue Jul 23, 2021 · 0 comments

Comments

@arunthirupathi
Copy link

Map's elementAt implementation always computes hash table. https://github.com/prestodb/presto/blob/master/presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java#L263

This saves CPU for 2 cases.

  1. The block is shared (e.g. DictionaryBlock or think of broadcast join) and the same block is used for multiple key lookups (Same key or different key).
  2. The block is not shared, but the query is trying to look at multiple keys in the same map.

But there are cases, where only one key is looked at in the map. In this case computing hash table takes more time than doing a scan.
A simple example to demonstrate this is

SELECT ELEMENT_AT(Map, key) from Table

Today this query will compute hash tables in the Map and will do a single key lookup.

Should the Map.elementAt switched to heuristics based (similar to JIT profile guided optimization) ? First time always do a simple scan, but if multiple lookups are happening in the map, switch to hash tables ?

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

No branches or pull requests

1 participant