57 Commits

Author SHA1 Message Date
Johan Wikman
9a8bb95be6 MXS-2014 Rename mxs_log_priority_is_enabled
- Renamed to mxs_log_is_priority_enabled
- That function instead of the macro is now consistently used
2018-08-16 09:59:43 +03:00
Markus Mäkelä
c1f930d23d
Fix query classifier initialization data race
The initialization code does some modification to the global code
(something about a page cache) and causes warnings with TSAN.
2018-08-13 10:28:02 +03:00
Johan Wikman
a044929661 MXS-1624 Allow the closing of an info object
If an info object can be dupped, it must also be possible to
close it.
2018-07-06 12:12:31 +03:00
Johan Wikman
295bae5673 MXS-1624 Implement qc_dup
Only for qc_sqlite.

After a second look qc_mysqlembedded will not support dupping
the statement information. Without additional changes, simply stashing
an info object away, parsing another new GWBUF, deleting that and
then using the stashed away info object will not work; the THD object
will be corrupted. As qc_mysqlembedded is _only_ used for verifying the
sqlite-based parser this is not important anyway.
2018-07-06 12:12:31 +03:00
Johan Wikman
4e168f36f7 MXS-1624 Make the QC info object explicit
The query classifier stores information about the statement carried
by a GWBUF in the GWBUF itself. We need to be able to store that
object out side the lifetime of the GWBUF. So, we require that a
query classifier is capable of duplicating references to that object.
2018-07-06 12:12:31 +03:00
Johan Wikman
cc0299aee6 Update change date of 2.3 2018-06-25 10:07:52 +03:00
Johan Wikman
254084fc5e MXS-1935 Accept "PREPARE name FROM @var" 2018-06-21 12:51:47 +03:00
Johan Wikman
776f199d01 MXS-1719 Treat # comments the same way as -- comments
sqlite does not treat # as the start of a to-end-of-line
comment. It cannot trivially be treated as such because at
startup sqlite parses statements containing the #-character.
Thus, only after sqlite has been initialized can it be treated
the same way as --.
2018-06-12 17:35:49 +03:00
dapeng huang
cd136b11a7 MXS-1891: dealloc named prepare should route to all (#174)
* dealloc named prepare route to all

* add newline

* erase from ps manager too

* little refactor
2018-06-12 10:45:11 +03:00
Markus Mäkelä
cddcc6d7d5
MXS-1896: Distinct LOAD DATA LOCAL INFILE from LOAD DATA INFILE
The two operations return different types of results and need to be
treated differently in order for them to be handled correctly in 2.2.

This fixes the unexpected internal state errors that happened in all 2.2
versions due to a wrong assumption made by readwritesplit. This fix is not
necessary for newer versions as the LOAD DATA LOCAL INFILE processing is
done with a simpler, and more robust, method.
2018-06-04 15:17:48 +03:00
Johan Wikman
3d8d2beaaa MXS-1787 Provide alias map when parsing an expression list
A statement like "CALL p1((SELECT f1()), ?);" needs an collection
for storing aliases when being parsed.
2018-04-13 13:50:28 +03:00
Johan Wikman
9b36ba5e0a MXS-1677: Don't assume all queries are in text form
After a temporary table is created, readwritesplit will check whether a
query drops or targets that temporary table. The check for query type was
missing from the table dropping part of the code. The temporary table read
part was checking that the query is a text form query.

Added a debug assertion to the query parsing function in qc_sqlite to
catch this type of interface misuse.
2018-02-24 17:02:51 +02:00
Markus Mäkelä
bce5627ee3
Fix out-of-bounds read on invalid query message
When the parsing of a query failed, the message would treat the parameter
as a string as the printf format was `%*s` instead of `%.*s`.

The manpage of printf states the following about the precision specifier:

    ... or the maximum number of characters to be printed from a string
        for `s` and `S` conversions.

This means that the field length specifier is somewhat meaningless for
strings.
2018-02-16 20:49:27 +02:00
Johan Wikman
5c10d0ae92 Merge branch '2.1' into 2.2 2018-02-12 14:00:08 +02:00
Markus Mäkelä
4089b6b6fd
MXS-1647: Detect API version mismatch
If the API versions do not match, MaxScale will treat this as an
error. The API versioning would allow backwards compatible changes but the
functionality to handle that is not implemented in MaxScale.

Updated API versions based on changes done to module APIs in 2.2.
2018-02-06 14:51:07 +02:00
Johan Wikman
c31881914b MXS-1584 Correctly classify "SELECT NEXT VALUE FOR seq" 2018-01-04 10:11:19 +02:00
Johan Wikman
dfc7b1713a Merge branch '2.1' into 2.2 2017-12-27 11:31:27 +02:00
Johan Wikman
1c58df8307 qc_sqlite: Copy database if tables are copied
To be able to correctly report the fullname of a table we must
copy the database, if it is available.
2017-11-20 15:15:58 +02:00
Johan Wikman
a51d23ded0 Bail out earlier when walking parse tree
No point walking the parse tree, if no information will be
collected.
2017-10-12 12:29:43 +03:00
Markus Mäkelä
eab7b7e2a3 Remove call to qc_sqlite_thread_end in qc_sqlite_process_end
Since the thread initialization was removed from the process
initialization function, the thread finish function should not be called
in the process finish function.
2017-09-17 11:55:12 +03:00
Markus Mäkelä
d00c5b2838 Move thread initialization into Worker::run
By moving the initialization into Worker::run, all threads, including the
main thread, are properly initialized. This was not noticed before as
qc_sqlite initialized the main thread in the process initialization
callback.
2017-09-15 18:08:49 +03:00
Markus Mäkelä
45e0e8bb59 Introduce internal protocol command enum
The enums exposed by the connector are not intended to be used by the
users of the library. The fact that the protocol, and other, modules used
it was in violation of how the library is intended to be used.

Adding an internal mapping into MaxScale also removes some of the
dependencies that the core has on the connector.
2017-09-14 15:30:43 +03:00
Markus Mäkelä
3676dcebb1 MXS-1398: Clean up mysql.h header
Cleaned up the MaxScale version of the mysql.h header by removing all
unused includes. This revealed a large amount of dependencies on these
removed includes in other files which needed to be fixed.

Also sorted all includes in changed files by type and alphabetical
order. Removed explicit revision history from modified files.
2017-09-14 15:30:43 +03:00
Johan Wikman
a2d0d24b2c Merge branch '2.1' into develop
Bringing in MXS-1406
2017-09-13 10:02:37 +03:00
Johan Wikman
19407a09f8 Remove unnecessary assert
We are only interested in asterisks and column names. Everything
else - integers, floating point numbers, strings, etc. - is of
no interest and not an error.
2017-09-07 13:46:44 +03:00
Johan Wikman
ad4e8dad94 MXS-1364 Drop the usage field
But for the most trivial statements did not really provide
useful information.

The arguments of the "function" '=' are now reported.
2017-08-24 09:58:18 +03:00
Johan Wikman
83ae19cd68 MXS-1364 Collect field usage of CASE and BETWEEN 2017-08-24 09:58:18 +03:00
Johan Wikman
c34140abd8 MXS-1364 Improve collection of arguments to IN 2017-08-22 11:01:50 +03:00
Johan Wikman
de9c1ef109 MXS-1364 Collect information of arguments to operators 2017-08-22 11:01:50 +03:00
Johan Wikman
feebc85d98 MXS-1364 Report true name and not alias name
With this change, in the case of a statement like

  select a as b from t where length(b) = 1

it will be reported that length accesses a and not b.
2017-08-22 11:01:50 +03:00
Johan Wikman
6812ae51fc MXS-1364 Collect function field usage
In qc_sqlite the fields that a particular function refers to are now
collected and reported. Qc_mysqlembedded needs to be updated accordingly
and also the compare utility. For subsequent commits.
2017-08-22 11:01:50 +03:00
Johan Wikman
65bf471bd7 MXS-1364 Factor out field name extraction
Will be used when function field usage is collected.
2017-08-22 11:01:50 +03:00
Johan Wikman
8bd234a442 MXS-1337 Manual array manipulation replaced with std::vector 2017-08-17 09:21:52 +03:00
Johan Wikman
de7004cb95 Merge branch '2.1' into develop 2017-08-15 10:31:30 +03:00
Johan Wikman
c662bea983 MXS-1359 Turn recursion into iteration
In case of very large compound selects or an INSERT with many
values, qc_sqlite could run out of stack space. To deal with
that, the critical recursion is turned into an iteration.
2017-08-14 13:29:19 +03:00
Johan Wikman
4dc41509af MXS-1337 Move more functions to QcSqliteInfo 2017-08-10 16:09:58 +03:00
Johan Wikman
8ce5147d39 MXS-1337 Moved functions to QcSqliteInfo 2017-08-10 15:57:48 +03:00
Johan Wikman
54a75a1752 MXS-1337 Move update_field_infos_from[sub]select to QcSqliteInfo 2017-08-10 15:45:25 +03:00
Johan Wikman
4eeff705ee MXS-1307 Catch "union all" selects 2017-08-10 14:45:27 +03:00
Johan Wikman
878bbe4a98 MXS-1307 Aliases must be stored hierarchically
Alias handling must be made so that in a subselect, aliases created
in an outer select are available, but aliases created in another
subselect are not.
2017-08-10 11:43:09 +03:00
Johan Wikman
aeb881afea MXS-1337 Better sqlite3 initialization
The sqlite3 initialization is done a bit more properly now.
It is also ensured that issues are logged at most once, even
if a statement is parsed twice.
2017-08-09 13:21:24 +03:00
Johan Wikman
1d693640c7 MXS-1337 All callbacks now exception safe
No exceptions can now ever escape from the C++ side of qc_sqlite
to sqlite3 (where they would cause havoc).
2017-08-08 15:46:01 +03:00
Johan Wikman
e084c0a464 MXS-1337 Thread initialization is checked by explicit callbacks
When any of the QcSqliteInfo member functions are called, they
can assume that thread initialization has been performed.
2017-08-08 15:46:01 +03:00
Johan Wikman
83a5614d2a MXS-1337 Initialization status moved to thread specific data
The initialization state is thread specific, not QcSqliteInfo
instance specific.
2017-08-08 15:46:01 +03:00
Johan Wikman
5c68494044 MXS-1337: More functions moved into QcSqliteInfo
All callbacks called by sqlite now only access the thread specific
QcSqliteInfo and call the corresponding function on that instance.
This is the first step in making qc_sqlite exception safe from the
point of view of sqlite3.

As the diff is confusing, basically the ONLY thing that has been
done is:

BEFORE:
-------
class QcSqliteInfo
{
    ...
};

static void some_helper(...) { ... }

void mxs_someCallback(...)
{
   QC_TRACE();
   QcSqliteInfo* info = this_thread.pInfo;
   ss_dassert(info);

   info->m_status = ...;
   some_helper(info, ...);
}

AFTER:
------
class QcSqliteInfo
{
    ...
    void some_helper(...) { ... }

    void mxs_someCallback(...)
    {
        m_status = ...;
        some_helper(this, ...);
    }
};

void mxs_someCallback(...)
{
   QC_TRACE();
   QcSqliteInfo* pInfo = this_thread.pInfo;
   ss_dassert(pInfo);

   pInfo->mxs_someCallback(...);
}
2017-08-08 15:46:01 +03:00
Johan Wikman
4f4151bca9 MXS-1340 Report true table and not alias name
With this change, for a statement like

    SELECT t2.a FROM t1 t2;

the affected field is reported as t1.a and not as t2.a, as it
was before.

For a statement like

    SELECT t.f FROM d.t;

qc_mysqlembedded will now return "d.t.f" as the affected field,
while qc_sqlite will still return "t.f" as both implementations did
before. In qc_mysqlembedded's case that is a side-effect of the
alias handling. To get qc_sqlite to return the same (which would
be good), the table names would have to be collected in a smarter
way than they are now.
2017-08-08 15:46:01 +03:00
Johan Wikman
a438ff7c86 MXS-1340 is_sequence_related... functions moved to QcSqliteInfo 2017-08-07 08:31:41 +03:00
Johan Wikman
c29e8b2b9e MXS-1340 Move update_field_info to QcSqliteInfo 2017-08-07 08:31:41 +03:00
Johan Wikman
eecd7a03c5 MXS-1340 Collect alias names
Alias names for tables are now collected, so that the true
table name of a referred to field can be reported. That modification
will be made in a subsequent commit.
2017-08-07 08:31:41 +03:00
Johan Wikman
72c5d1844a MXS-1337 Add variable prefixes
Member variables of QcSqliteInfo now have m_, p, z and n prefixes
as appropriate.
2017-08-03 08:36:25 +03:00