← Back to team overview

maria-developers team mailing list archive

Re: Feature Request - Working auto_inc rement on BlackHole Engine

 

Hi!

>>>>> "Gordan" == Gordan Bobic <gordan@xxxxxxxxxx> writes:

Gordan> On 05/15/2013 09:24 PM, Roberto Spadim wrote:
>> hum, maybe a 'global variable' + a 'counter' function could do the job?
>> 
>> select add_and_return(@global_var,1)
>> could return old global_var value +1, and set the global_var to +1
>> 
>> just a idea.. like GET_LOCK(str,timeout) do, but without timeout

Gordan> How would the function avoid the race condition?

By using atomic auto increments supported by the cpu.

If you make this a two fold number:

32_bit_timestamp << 32 + auto_increment

Then this would even be safe in regards for server crashes.

Gordan> Is it actually possible to have user-defined global variables?

With a plugin, yes.

Regards,
Monty


References