InnoDB如何对多列主键进行排序(How InnoDB sorts multi column primary keys)
我知道InnoDB中的主键是集群化的。 因此,使用自动增量整数作为主键具有已被排序并提高插入性能的好处。
但问题是我有一个这样的表与2列ID和哈希(和其他一些但不重要);
id int auto increment hash Guid
我需要在哈希列上对这个表进行分区,这意味着我必须将它放在主键中。
所以我正在考虑创建一个主键(id,hash)。id列将用于与其他表的连接。
问题是如果我将PK作为(id,hash),InnoDB将如何对它进行排序?
它是否会首先使用id列,然后使用散列或者是否会使用其他方式来确定密钥的顺序? 前者会更好,因为它从已经排序的auto inc列中受益,但我无法找到任何有关如何在组合列上完成排序的信息。
任何洞察到这一点非常感谢:)
I know that the primary key in InnoDB is clustered. So that using an auto increment integer as the primary key has the benefit of already being sorted and improves the insert performance.
But the issue is I have a table like this with 2 columns id and hash (and some other but not important );
id int auto increment hash Guid
I need to partition this table on the hash column, that means I have to put it in the primary key.
So I'm thinking of creating a primary key as (id,hash).The id column will be used in the joins with the other tables.
Problem is if I have the PK as (id,hash) how will InnoDB sort it ?
Will it use the id column first and then hash or will it use some other way to determine the order of the key ?. The former will be better as it benefits from the already sorted auto inc column but I could not find any info about how the sorting will be done on the composite columns.
Any insight into this is greatly appreciated :)
原文:https://stackoverflow.com/questions/6320676
最满意答案
var asciiString = "\u0094";
无论你怎么命名,它都将是一个Unicode字符串。 .NET只有Unicode字符串。
我正在从另一个系统检索用代码页437编码的ASCII字符串
将传入数据视为
byte[]
,而不是string
。var asciiBytes = new byte[] { 0x94 }; // 94 corresponds represents 'ö' in code page 437. var asciiEncoding = Encoding.GetEncoding(437); var unicodeString = asciiEncoding.GetString(asciiBytes);
var asciiString = "\u0094";
Whatever you name it, this will always be a Unicode string. .NET only has Unicode strings.
I am retrieving ASCII strings encoded with code page 437 from another system
Treat the incoming data as
byte[]
, not asstring
.var asciiBytes = new byte[] { 0x94 }; // 94 corresponds represents 'ö' in code page 437. var asciiEncoding = Encoding.GetEncoding(437); var unicodeString = asciiEncoding.GetString(asciiBytes);
相关问答
更多-
编码功能可以帮助你在这里,编码返回字符串的编码版本 In [44]: str = "ABCD" In [45]: [elem.encode("hex") for elem in str] Out[45]: ['41', '42', '43', '44'] 或者你可以使用数组模块 In [49]: import array In [50]: print array.array('B', "ABCD") array('B', [65, 66, 67, 68]) encode function can h ...
-
将bytearray转换为String的最佳方法是 public void convertByteArrayToString(Charset encoding) { byte[] byteArray = new byte[] {87, 79, 87, 46, 46, 46}; String value = new String(byteArray, encoding); System.out.println(value); } The Best ...
-
使用getBytes方法,给它相应的Charset (或Charset名称)。 例: String s = "Hello, there."; byte[] b = s.getBytes(StandardCharsets.US_ASCII); (Java 7之前: byte[] b = s.getBytes("US-ASCII"); ) Using the getBytes method, giving it the appropriate Charset (or Charset name). Exampl ...
-
根据您希望使用的编码: var str = System.Text.Encoding.Default.GetString(result); Depending on the encoding you wish to use: var str = System.Text.Encoding.Default.GetString(result);
-
如何将字节数组转换为十六进制字符串,反之亦然?(How do you convert a byte array to a hexadecimal string, and vice versa?)[2022-05-11]
或者: public static string ByteArrayToString(byte[] ba) { StringBuilder hex = new StringBuilder(ba.Length * 2); foreach (byte b in ba) hex.AppendFormat("{0:x2}", b); return hex.ToString(); } 要么: public static string ByteArrayToString(byte[] ba) { ... -
Java没有无符号类型,因此您必须将值存储在int数组中。 byte[] array = new BigInteger("123456").toByteArray(); int[] unsigned_array = new int[array.length]; for (int i = 0; i < array.length; i++) { unsigned_array[i] = array[i] >= 0 ? array[i] : array[i] + 256; } 非常坦率的。 Java ...
-
如何将字符代码大于127的字符串正确转换为字节数组?(How to convert a string with character codes above 127 to a byte array properly?)[2022-08-23]
var asciiString = "\u0094"; 无论你怎么命名,它都将是一个Unicode字符串。 .NET只有Unicode字符串。 我正在从另一个系统检索用代码页437编码的ASCII字符串 将传入数据视为byte[] ,而不是string 。 var asciiBytes = new byte[] { 0x94 }; // 94 corresponds represents 'ö' in code page 437. var asciiEncoding = Encoding.GetEnco ... -
将字节数组转换为字符串(Convert a byte array to string)[2022-01-02]
像这样的东西? >>> s = "104,101,108,108,111" >>> "".join(chr(int(number)) for number in s.split(",")) 'hello' Something like this? >>> s = "104,101,108,108,111" >>> "".join(chr(int(number)) for number in s.split(",")) 'hello' -
byte[] exampleByteArray = new byte[] { 0x00, 0x52, 0x50, 0x4D, 0x20, 0x3D, 0x20, 0x32, 0x35, 0x35, 0x2C, 0x36, 0x30, 0x0A, 0x00 }; exampleByteArray = exampleByteArray.Where(x=>x!=0x00).ToArray(); // not sure this is OK with your requirements string myStri ...
-
byte[]和String之间的“正确转换”是显式声明要使用的编码。 如果你从一个byte[] ,它实际上不包含文本数据,那么没有 “正确的转换”。 String是用于文本, byte[]是二进制数据,唯一真正需要做的事是避免转换,除非你绝对必须。 如果你真的必须使用一个String来保存二进制数据,那么最安全的方法是使用Base64编码。 Your byte array must have some encoding. The encoding cannot be ASCII if you've got ...