oracle 什么是 HASH JOIN 时的 HASH TABLE?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13211921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:13:27  来源:igfitidea点击:

What is a HASH TABLE when doing HASH JOIN?

oraclequery-optimizationoracle9i

提问by Savitha

In HASH JOIN method of oracle, HASH TABLE will be built on one of the tables and other will be joined depending on the values in the hash table.

在oracle的HASH JOIN方法中,HASH TABLE将建立在其中一个表上,其他将根据哈希表中的值进行连接。

Could you please let me know what is Hash table? What is the structure of hash table? how will it be created?

你能告诉我什么是哈希表吗?哈希表的结构是什么?它将如何创建?

采纳答案by Roger

A hash table is a table where you can store stuff by the use of a key. It is like an array but stores things differently

哈希表是一个表,您可以在其中使用键存储内容。它就像一个数组,但存储的东西不同

a('CanBeVarchar') := 1; -- A hash table

In oracle, they are called associative arrays or index by tables.and you make one like this:

在 oracle 中,它们被称为关联数组或表索引。你做一个这样的:

TYPE aHashTable IS TABLE OF [number|varchar2|user-defined-types] INDEX BY VARCHAR2(30);
myTable aHashTable;

So, what is it? it's just a bunch of key-value pairs. The data is stored as a linked list with head nodes that group the data by the use of something called HashCode to find things faster. Something like this:

那么,它是什么?它只是一堆键值对。数据存储为带有头节点的链表,这些头节点通过使用称为 HashCode 的东西对数据进行分组以更快地查找内容。像这样的东西:

a    ->     b     ->    c
Any         Bitter      Class
Array       Bold        Count

Say you are storing random words and it's meaning (a dictionary); when you store a word that begins with a, it is stored in the 'a' group. So, say you want this myTable('Albatroz') := 'It's a bird', the hash code will be calculated and put in the A head node, where it belongs: just above the 'Any'. a, has a link to Any, which has a link to Array and so on.

假设您正在存储随机单词及其含义(字典);当您存储以 a 开头的单词时,它将存储在 'a' 组中。所以,假设你想要这个myTable('Albatroz') := 'It's a bird',哈希码将被计算并放在它所属的 A 头节点中:就在“Any”之上。a, 有一个指向 Any 的链接,它有一个指向 Array 的链接等等。

Now, the cool thing about it is that you get fast data retreival, say you want the meaning of Count, you do this definition := myTable('Count');It will ignore searching for Any, Array, Bitter, Bold. Will search directly in the C head node, going trhough Class and finally Count; that is fast!

现在,关于它的很酷的事情是你可以获得快速的数据检索,比如你想要的含义Count,你这样做definition := myTable('Count');它会忽略搜索任何、数组、苦味、粗体。会直接在C头节点中搜索,经过Class,最后是Count;这很快!

Here a wikipedia Link: http://en.wikipedia.org/wiki/Hash_table

这里是维基百科链接:http: //en.wikipedia.org/wiki/Hash_table

Note that my example is oversimplified read with a little bit of more detail in the link.

请注意,我的示例过于简化,链接中包含更多细节。

Read more details like the load factor: What happens if i get a LOT of elements in the a group and few in the b and c; now searching for a word that begins with a is not very optinmal, is it? the hash table uses the load factor to reorganize and distribute the load of each node, for example, the table can be converted to subgroups:

阅读更多详细信息,如负载因子:如果我在 a 组中有很多元素而 b 和 c 中的元素很少,会发生什么;现在搜索以 a 开头的单词不是很理想,是吗?哈希表使用负载因子对每个节点的负载进行重新组织和分配,例如可以将表转换为子组:

From this

由此

a          b     ->    c
Any        Bitter      Class
Anode      Bold        Count
Anti       
Array
Arrays
Arrow

To this

对此

an    ->   ar      b     ->    c
Any        Array   Bitter      Class
Anode      Arrays  Bold        Count
Anti       Arrow

Now looking for words like Arrowwill be faster.

现在寻找像这样的词Arrow会更快。