uuid

using UUID as primary key in rails and polymorph relationships

耗尽温柔 提交于 2019-12-17 18:11:28
问题 I'm creating a rails 3 application that will be decentralized and I need to use UUID as primary key for my tables, what would be the best gem, plugin for the Job. I also would like to know if it is possible to make in ActiveRecord polymorphic relationships without using the polymorphicable_type column for it, given the case that I'm using UUID. I have created a demo http://github.com/boriscy/uuidrails3 that uses UUID as keys, you should check the module UUIDHelper inside lib/ and also all the

How to determine if a string is a valid v4 UUID? [duplicate]

浪子不回头ぞ 提交于 2019-12-17 18:03:20
问题 This question already has answers here : PHP verify valid UUID (2 answers) Closed 27 days ago . I'm making a validator based on UUID generated by client browser, I use this to identify a certain type data that the user sends; and would like to validate that the UUID that client sends it is in fact a valid Version 4 UUID . I found this PHP preg_match UUID v4, it's close but not exactly what I'm looking for. I wish to know if exists something similar to is_empty() or strtodate() Where if string

Convert UUID 32-character hex string into a “YouTube-style” short id and back

佐手、 提交于 2019-12-17 17:27:09
问题 I'm assigning all my MongoDB documents a GUID using uuid.uuid1(). I want a way I can derive an 11 character, unique, case-sensitive YouTube-like ID, such as 1_XmY09uRJ4 from uuid's resulting hex string which looks like ae0a0c98-f1e5-11e1-9t2b-1231381dac60 I want to be able to match the shortened ID to the hex and vice-versa, dynamically without having to store another string in the database. Does anyone have some sample code or can point me in the direction of the module or formula that can

Mysql InnoDB 引擎 主键性能

天涯浪子 提交于 2019-12-17 13:59:28
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前些天看到网上有人说:“Mysql InnoDB 引擎 主键不适合用UUID , 若要用UUID的话可考虑用 自增ID做物理主键,UUID做逻辑主键。” 带着以上问题,本人做了如下测试: 先自报测试环境: 测试电脑配置如图: MySQL 5.1(社区版) my.ini配置如下 [client] port = 3306 socket = MySQL [mysqld] port = 3306 socket = MySQL key_buffer_size = 64M max_allowed_packet = 16M thread_cache_size = 8 thread_concurrency = 8 max_connections = 100 table_open_cache = 2048 sort_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 24M net_buffer_length = 2K thread_stack = 1024K server-id = 1 character-set-server=utf8 default-storage-engine=INNODB [mysqldump] quick max_allowed

Mybatis插入数据行ID生成策略

倾然丶 夕夏残阳落幕 提交于 2019-12-17 13:59:11
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Oracle: <insert id="insert" parameterType="vo.Category"> <selectKey resultType="java.lang.Short" order="BEFORE" keyProperty="id"> SELECT SEQ_TEST.NEXTVAL FROM DUAL </selectKey> insert into category (id,name_zh, parent_id, show_order, delete_status, description ) values ( #{id,jdbcType=NUMBER}, #{nameZh,jdbcType=VARCHAR}, #{parentId,jdbcType=NUMBER}, #{showOrder,jdbcType=NUMBER}, #{deleteStatus,jdbcType=NUMBER}, #{description,jdbcType=VARCHAR} ) </insert> MySQL: 针对自增主键的表,在插入时不需要主键,而是在插入过程自动获取一个自增的主键,比如MySQL,可以采用如下两种配置方式: <insert id="insert" parameterType="vo

MySQL 自增主键和UUID

妖精的绣舞 提交于 2019-12-17 13:10:40
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 关于自增主键和UUID的比较,可以从数据插入前,插入中,插入三个阶段进行比较,他们有各自的有点,当然也有各自的不足。下面就分三个阶段说说优缺点。 插入前 1)UUID 需要手动维护,要求是保证每次生成的数据都是不一致的,然后我们需要手写sql插入,如果代码逻辑中含有大量这种非业务相关的代码,其实是很不友好的,所以尽量透明。但是在代码中(Java)你可以在未插入之前就知道了主键ID,这个在有关联表需要插入时非常不错。 2)自增主键 插入前无需维护,编写的sql也不用管这个字段,数据库自己维护,对写程序来说完全透明。缺点就是插入前代码中(Java)并不知道主键。 插入中 1)UUID 长度相对比较大,如果大批量数据插入,在网络传输间,实际上这个字段占用的空间是不容小觑的,当然一般的程序不会担心这个,因为选用 Hibernate 的人,基本不会在乎某个字段的事。另外,既然是主键那么必然要考虑主键的唯一性,如何做这个唯一的校验呢?尤其是并发情况下,如果有多个相同的键同时插入怎么办?所以我觉得这里会有个锁(可能是锁索引,也可能是锁表),因此使用UUID并发插入肯定会发生阻塞的。这个可以去试验一下,开两个事务,使用相同的ID插入,后一个插入肯定会被阻塞,所以我觉得这里肯定有一个判断是否已经存在键的代码,而且是同步的

Spark Dataframe Random UUID changes after every transformation/action

梦想的初衷 提交于 2019-12-17 12:31:08
问题 I have a Spark dataframe with a column that includes a generated UUID. However, each time I do an action or transformation on the dataframe, it changes the UUID at each stage. How do I generate the UUID only once and have the UUID remain static thereafter. Some sample code to re-produce my issue is below: def process(spark: SparkSession): Unit = { import spark.implicits._ val sc = spark.sparkContext val sqlContext = spark.sqlContext sc.setLogLevel("OFF") // create dataframe val df = spark

Is there a 128 bit integer in C++?

百般思念 提交于 2019-12-17 10:56:28
问题 I need to store a 128 bits long UUID in a variable. Is there a 128-bit datatype in C++? I do not need arithmetic operations, I just want to easily store and read the value very fast. A new feature from C++11 would be fine, too. 回答1: GCC and Clang support __int128 回答2: Although GCC does provide __int128 , it is supported only for targets (processors) which have an integer mode wide enough to hold 128 bits. On a given system, sizeof() intmax_t and uintmax_t determine the maximum value that the

细聊分布式ID的生成方法

青春壹個敷衍的年華 提交于 2019-12-17 09:24:16
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 需求缘起   几乎所有的业务系统,都有生成一个记录标识的需求,例如: 1. 消息标识:message-id 2. 订单标识:order-id 3. 帖子标识:tiezi-id   这个记录标识往往就是数据库中的唯一主键,数据库上会建立聚集索引(cluster index),即在物理存储上以这个字段排序。这个记录标识上的查询,往往又有分页或者排序的业务需求,例如: 1. 拉取最新的一页消息: SELECT message-id ORDER BY time LIMIT 100 2. 拉取最新的一页订单: SELECT order-id ORDER BY time LIMIT 100 3. 拉取最新的一页帖子: SELECT tiezi-id ORDER BY time LIMIT 100   所以往往要有一个time字段,并且在time字段上建立普通索引(non-cluster index).我们都知道普通索引存储的是实际记录的指针,其访问效率会比聚集索引慢,如果记录标识在生成时能够基本按照时间有序,则可以省去这个time字段的索引查询: SELECT message-id ORDER BY message-id LIMIT 100   再次强调,能这么做的前提是message-id的生成基本是趋势时间递增的

How to Create Deterministic Guids

喜欢而已 提交于 2019-12-17 03:23:01
问题 In our application we are creating Xml files with an attribute that has a Guid value. This value needed to be consistent between file upgrades. So even if everything else in the file changes, the guid value for the attribute should remain the same. One obvious solution was to create a static dictionary with the filename and the Guids to be used for them. Then whenever we generate the file, we look up the dictionary for the filename and use the corresponding guid. But this is not feasible