← Back to team overview

maria-discuss team mailing list archive

Re: help - i'm not finding one sql function

 

Carsten, your example is very interesting. I didn't expect that 10 native funcs calls can be 242 times faster (in a real/realistic use case)!

A suggestion: one can use macros. strip_digits() can become a macro, so the code will be readable and there won't be performance problems. I use GNU m4 precompiler because I wasn't able to solve a problem with GCC.

An example from my macro lib.

Definition:

m4_define(<<EXECUTE_SQL>>, <<
	SET @`$1` := '$2';
	PREPARE `$1` FROM @`$1`;
	m4_ifelse($3, <<CLOSE>>, <<SET @`>>$1<<` := NULL;>>)
	EXECUTE `$1`;
	m4_ifelse($3, <<CLOSE>>, <<DEALLOCATE PREPARE `>>$1<<`;>>)
>>)

Usage:

EXECUTE_SQL(stmt, <<SELECT 1;>>)
EXECUTE_SQL(stmt, <<SELECT 2;>>, CLOSE)

Regards,
Federico


--------------------------------------------
Gio 20/3/14, Carsten Pedersen <carsten@xxxxxxxxxxx> ha scritto:

 Oggetto: Re: [Maria-discuss] help - i'm not finding one sql function
 A: "Roberto Spadim" <roberto@xxxxxxxxxxxxx>, "Maria Discuss" <maria-discuss@xxxxxxxxxxxxxxxxxxx>
 Data: Giovedì 20 marzo 2014, 09:50
 
 On 19-03-2014 15:51,
 Roberto Spadim wrote:
 > hi guys, i'm
 not finding a function to return how many character i
 have,
 > for example:
 >
 > "banana"
 >
 > i want a function
 that return 2 "n" characters, example:
 >
 substr_count("banana","n") => 2
 
 SELECT
 CHAR_LENGTH(field)-CHAR_LENGTH(REPLACE(field, 'n',
 ''))
 
 Many moons
 ago, I blogged about something similar, performance 
 considerations and how to make your own
 function:
 http://www.bitbybit.dk/carsten/blog/?p=55
 
 Best,
 
 / Carsten
 
 _______________________________________________
 Mailing list: https://launchpad.net/~maria-discuss
 Post to     : maria-discuss@xxxxxxxxxxxxxxxxxxx
 Unsubscribe : https://launchpad.net/~maria-discuss
 More help   : https://help.launchpad.net/ListHelp



References