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.
This commit is contained in:
Johan Wikman
2017-08-07 13:22:24 +03:00
parent b9588a89ac
commit 4f4151bca9
5 changed files with 99 additions and 24 deletions

View File

@ -28,7 +28,11 @@ insert into mysqltest.t2 values (1,'xxx'), (1,'zzz');
connection user1;
with t as (select c from mysqltest.t2 where c < 2)
select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
#MXS: qc_sqlite cannot currently return mysqltest.t1.b as
#MXS: the affected field, but only t1.b.
#select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
select t.c,t1.b from t,t1 where t.c=t1.a;
--error ER_COLUMNACCESS_DENIED_ERROR
select t.c,t.d,t1.b
from (select c,d from mysqltest.t2 where c < 2) as t, mysqltest.t1
@ -40,8 +44,11 @@ select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a;
connection root;
create view mysqltest.v1(f1,f2) as
#MXS: qc_sqlite reports t1.a and not mysqltest.t1.a
#with t as (select c from mysqltest.t2 where c < 2)
#select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
with t as (select c from mysqltest.t2 where c < 2)
select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
select t.c,t1.b from t,t1 where t.c=t1.a;
create view mysqltest.v2(c,d) as
with t as (select a from mysqltest.t1 where a>=3)
select t.a,b from t,mysqltest.t1 where mysqltest.t1.a = t.a;
@ -54,8 +61,11 @@ select t.a,b from t,mysqltest.t1 where mysqltest.t1.a = t.a;
connection user1;
create view mysqltest.v3(c,d) as
#MXS: qc_sqlite reports t1.a and not mysqltest.t1.a
#with t as (select c from mysqltest.t2 where c < 2)
#select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
with t as (select c from mysqltest.t2 where c < 2)
select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
select t.c,t1.b from t,t1 where t.c=t1.a;
--error ER_COLUMNACCESS_DENIED_ERROR
create view mysqltest.v4(f1,f2,f3) as
with t as (select c,d from mysqltest.t2 where c < 2)

View File

@ -547,15 +547,19 @@ select t1.b from v1a;
-- error 1054
select * from v1a join v1b on t1.b = t2.b;
#MXS With the alias modifications made to qc_mysqlembedded, for a select like
#MXS "select t.f from d.t" it will report "d.t.f" as the affected field. That
#MXS is correct, but in qc_sqlite that cannot easily be done as the table
#MXS information is not collected in an appropriate way.
#
# Bug #17523 natural join and information_schema
#
# Omit columns.PRIVILIGES as it may vary with embedded server.
# Omit columns.ORDINAL_POSITION and statistics.CARDINALITY as it may vary with hostname='localhost'.
select
statistics.TABLE_NAME, statistics.COLUMN_NAME, statistics.TABLE_CATALOG, statistics.TABLE_SCHEMA, statistics.NON_UNIQUE, statistics.INDEX_SCHEMA, statistics.INDEX_NAME, statistics.SEQ_IN_INDEX, statistics.COLLATION, statistics.SUB_PART, statistics.PACKED, statistics.NULLABLE, statistics.INDEX_TYPE, statistics.COMMENT,
columns.TABLE_CATALOG, columns.TABLE_SCHEMA, columns.COLUMN_DEFAULT, columns.IS_NULLABLE, columns.DATA_TYPE, columns.CHARACTER_MAXIMUM_LENGTH, columns.CHARACTER_OCTET_LENGTH, columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE, columns.CHARACTER_SET_NAME, columns.COLLATION_NAME, columns.COLUMN_TYPE, columns.COLUMN_KEY, columns.EXTRA, columns.COLUMN_COMMENT
from information_schema.statistics join information_schema.columns using(table_name,column_name) where table_name='user';
#MXS select
#MXS statistics.TABLE_NAME, statistics.COLUMN_NAME, statistics.TABLE_CATALOG, statistics.TABLE_SCHEMA, statistics.NON_UNIQUE, statistics.INDEX_SCHEMA, statistics.INDEX_NAME, statistics.SEQ_IN_INDEX, statistics.COLLATION, statistics.SUB_PART, statistics.PACKED, statistics.NULLABLE, statistics.INDEX_TYPE, statistics.COMMENT,
#MXS columns.TABLE_CATALOG, columns.TABLE_SCHEMA, columns.COLUMN_DEFAULT, columns.IS_NULLABLE, columns.DATA_TYPE, columns.CHARACTER_MAXIMUM_LENGTH, columns.CHARACTER_OCTET_LENGTH, columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE, columns.CHARACTER_SET_NAME, columns.COLLATION_NAME, columns.COLUMN_TYPE, columns.COLUMN_KEY, columns.EXTRA, columns.COLUMN_COMMENT
#MXS from information_schema.statistics join information_schema.columns using(table_name,column_name) where table_name='user';
drop table t1;
drop table t2;

View File

@ -57,3 +57,10 @@ SELECT LENGTH(_utf8 0xC39F), LENGTH(CHAR(14844588 USING utf8));
# warning: [qc_sqlite] Statement was classified only based on keywords
# (Sqlite3 error: SQL logic error or missing database, near "0xC39F": syntax error):
# "SELECT LENGTH(_utf8 0xC39F), LENGTH(CHAR(14844588 USING utf8));"
SELECT t.f FROM d.t;
# qc_get_field_info : ERR: d.t.f(QC_USED_IN_SELECT) != t.f(QC_USED_IN_SELECT)
# Table names need to be collected in a more intelligent fashion to be able
# to do that.
select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
with t as (select c from mysqltest.t2 where c < 2) select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;