summaryrefslogtreecommitdiff
path: root/sql/item.h
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2017-06-21 16:19:43 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2017-06-21 16:19:43 +0300
commit2e335a471ced0d86716f8c657f4d67f510712a30 (patch)
tree6fa56f9d9083007e874449b9c2b27579f718ed94 /sql/item.h
parent472c2d9b2fbb262665bdd08338ea902e8398010d (diff)
parent8baf9b0c469e2845d15cc1181bc6b101cdfba087 (diff)
downloadmariadb-git-2e335a471ced0d86716f8c657f4d67f510712a30.tar.gz
Merge remote-tracking branch '10.0' into 10.1
Diffstat (limited to 'sql/item.h')
-rw-r--r--sql/item.h35
1 files changed, 15 insertions, 20 deletions
diff --git a/sql/item.h b/sql/item.h
index d4484c1d74e..8ee76a626d4 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -857,25 +857,20 @@ public:
store return value of this method.
NOTE
- Buffer passed via argument should only be used if the item itself
- doesn't have an own String buffer. In case when the item maintains
- it's own string buffer, it's preferable to return it instead to
- minimize number of mallocs/memcpys.
- The caller of this method can modify returned string, but only in case
- when it was allocated on heap, (is_alloced() is true). This allows
- the caller to efficiently use a buffer allocated by a child without
- having to allocate a buffer of it's own. The buffer, given to
- val_str() as argument, belongs to the caller and is later used by the
- caller at it's own choosing.
- A few implications from the above:
- - unless you return a string object which only points to your buffer
- but doesn't manages it you should be ready that it will be
- modified.
- - even for not allocated strings (is_alloced() == false) the caller
- can change charset (see Item_func_{typecast/binary}. XXX: is this
- a bug?
- - still you should try to minimize data copying and return internal
- object whenever possible.
+ The caller can modify the returned String, if it's not marked
+ "const" (with the String::mark_as_const() method). That means that
+ if the item returns its own internal buffer (e.g. tmp_value), it
+ *must* be marked "const" [1]. So normally it's preferrable to
+ return the result value in the String, that was passed as an
+ argument. But, for example, SUBSTR() returns a String that simply
+ points into the buffer of SUBSTR()'s args[0]->val_str(). Such a
+ String is always "const", so it's ok to use tmp_value for that and
+ avoid reallocating/copying of the argument String.
+
+ [1] consider SELECT CONCAT(f, ":", f) FROM (SELECT func() AS f);
+ here the return value of f() is used twice in the top-level
+ select, and if they share the same tmp_value buffer, modifying the
+ first one will implicitly modify the second too.
RETURN
In case of NULL value return 0 (NULL pointer) and set null_value flag
@@ -1651,7 +1646,7 @@ public:
{ return this; }
virtual bool expr_cache_is_needed(THD *) { return FALSE; }
virtual Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs);
- bool needs_charset_converter(uint32 length, CHARSET_INFO *tocs)
+ bool needs_charset_converter(uint32 length, CHARSET_INFO *tocs) const
{
/*
This will return "true" if conversion happens: