summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.h10
-rw-r--r--sql/item_strfunc.cc1
-rw-r--r--sql/share/Makefile.am3
-rw-r--r--sql/sql_select.cc17
-rw-r--r--sql/udf_example.cc55
5 files changed, 73 insertions, 13 deletions
diff --git a/sql/item_func.h b/sql/item_func.h
index 5810307e81c..71eab66270e 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -520,11 +520,17 @@ public:
void update_used_tables()
{
item->update_used_tables() ; Item_func::update_used_tables();
- used_tables_cache|=item->used_tables();
+ used_tables_cache|= item->used_tables();
+ const_item_cache&= item->const_item();
}
const char *func_name() const { return "field"; }
void fix_length_and_dec()
- { maybe_null=0; max_length=2; used_tables_cache|=item->used_tables();}
+ {
+ maybe_null=0; max_length=3;
+ used_tables_cache|= item->used_tables();
+ const_item_cache&= item->const_item();
+ with_sum_func= with_sum_func || item->with_sum_func;
+ }
};
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index c00a7aabe66..ec47f42f2ec 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1199,6 +1199,7 @@ void Item_func_elt::fix_length_and_dec()
set_if_bigger(decimals,args[i]->decimals);
}
maybe_null=1; // NULL if wrong first arg
+ with_sum_func= with_sum_func || item->with_sum_func;
used_tables_cache|=item->used_tables();
const_item_cache&=item->const_item();
}
diff --git a/sql/share/Makefile.am b/sql/share/Makefile.am
index 9bbcf6668da..0caca9afdfb 100644
--- a/sql/share/Makefile.am
+++ b/sql/share/Makefile.am
@@ -23,3 +23,6 @@ install-data-local:
$(INSTALL_DATA) $(srcdir)/charsets/README $(DESTDIR)$(pkgdatadir)/charsets/README
$(INSTALL_DATA) $(srcdir)/charsets/Index $(DESTDIR)$(pkgdatadir)/charsets/Index
$(INSTALL_DATA) $(srcdir)/charsets/*.conf $(DESTDIR)$(pkgdatadir)/charsets
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a3288540562..539433f5208 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3288,7 +3288,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
KEY_PART_INFO *key_part_info;
Item_result_field **copy_func;
MI_COLUMNDEF *recinfo;
- uint temp_pool_slot;
+ uint temp_pool_slot=MY_BIT_NONE;
DBUG_ENTER("create_tmp_table");
DBUG_PRINT("enter",("distinct: %d save_sum_fields: %d allow_distinct_limit: %d group: %d",
@@ -3297,18 +3297,15 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
statistic_increment(created_tmp_tables, &LOCK_status);
- if(use_temp_pool) {
+ if (use_temp_pool)
temp_pool_slot = bitmap_set_next(temp_pool, TEMP_POOL_SIZE);
- if(temp_pool_slot != MY_BIT_NONE) // we got a slot
- sprintf(path, "%s%s_%lx_%i", mysql_tmpdir, tmp_file_prefix,
- current_pid, temp_pool_slot);
- else // if we run out of slots in the pool, fall back to old behavior
- sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid,
- thd->thread_id, thd->tmp_table++);
- } else {
+
+ if (temp_pool_slot != MY_BIT_NONE) // we got a slot
+ sprintf(path, "%s%s_%lx_%i", mysql_tmpdir, tmp_file_prefix,
+ current_pid, temp_pool_slot);
+ else // if we run out of slots or we are not using tempool
sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid,
thd->thread_id, thd->tmp_table++);
- };
if (group)
{
diff --git a/sql/udf_example.cc b/sql/udf_example.cc
index 9d94006b281..bf3aa3d0074 100644
--- a/sql/udf_example.cc
+++ b/sql/udf_example.cc
@@ -56,11 +56,13 @@
**
** Function 'myfunc_int' returns summary length of all its arguments.
**
+** Function 'sequence' returns an sequence starting from a certain number
+**
** On the end is a couple of functions that converts hostnames to ip and
** vice versa.
**
** A dynamicly loadable file should be compiled sharable
-** (something like: gcc -shared -o udf_example.so myfunc.cc).
+** (something like: gcc -shared -o my_func.so myfunc.cc).
** You can easily get all switches right by doing:
** cd sql ; make udf_example.o
** Take the compile line that make writes, remove the '-c' near the end of
@@ -74,6 +76,7 @@
** CREATE FUNCTION metaphon RETURNS STRING SONAME "udf_example.so";
** CREATE FUNCTION myfunc_double RETURNS REAL SONAME "udf_example.so";
** CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "udf_example.so";
+** CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so";
** CREATE FUNCTION lookup RETURNS STRING SONAME "udf_example.so";
** CREATE FUNCTION reverse_lookup RETURNS STRING SONAME "udf_example.so";
** CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "udf_example.so";
@@ -121,6 +124,10 @@ double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error);
longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error);
+my_bool sequence_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
+ void sequence_deinit(UDF_INIT *initid);
+long long sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
+ char *error);
}
@@ -535,6 +542,8 @@ double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
** This function should return the result as a long long
***************************************************************************/
+/* This function returns the sum of all arguments */
+
long long myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error)
{
@@ -559,6 +568,50 @@ long long myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
}
+/*
+ Simple example of how to get a sequences starting from the first argument
+ or 1 if no arguments have been given
+*/
+
+my_bool sequence_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+ if (args->arg_count > 1)
+ {
+ strmov(message,"This function takes none or 1 argument");
+ return 1;
+ }
+ if (args->arg_count)
+ args->arg_type[0]= INT_RESULT; // Force argument to int
+
+ if (!(initid->ptr=(char*) malloc(sizeof(longlong))))
+ {
+ strmov(message,"Couldn't allocate memory");
+ return 1;
+ }
+ bzero(initid->ptr,sizeof(longlong));
+ // Fool MySQL to think that this function is a constant
+ // This will ensure that MySQL only evalutes the function
+ // when the rows are sent to the client and not before any ORDER BY
+ // clauses
+ initid->const_item=1;
+ return 0;
+}
+
+void sequence_deinit(UDF_INIT *initid)
+{
+ if (initid->ptr)
+ free(initid->ptr);
+}
+
+long long sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
+ char *error)
+{
+ ulonglong val=0;
+ if (args->arg_count)
+ val= *((long long*) args->args[0]);
+ return ++ *((longlong*) initid->ptr) + val;
+}
+
/****************************************************************************
** Some functions that handles IP and hostname conversions
** The orignal function was from Zeev Suraski.