全角スペースの影響

(8.0.26)
mysqlで確認


drop table tab1;
create table tab1(col1 bigint);
create unique index ind1 on tab1(col1);

drop procedure proc1;

delimiter //
create procedure proc1(in x int)
begin
  declare i bigint;
  set i = 0;
  start transaction;
  while i < x do
    set i = i + 1;
    insert into tab1 values(
     i
    );
  end while;
  commit;
end
//
delimiter ;

call proc1(1000000);

analyze table tab1;


select * from tab1 where col1 = 1;
select * from tab1 where col1 = 1;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to 
your MySQL server version for the right syntax 
to use near 'select * from tab1 where col1 = 1' at line 1

→全角スペースが入っているとSQL実行はエラーとなる

 

 

(19c)
sqlplusで確認

drop table tab1 purge;
create table tab1(col1 int);
create unique index ind1 on tab1(col1);

declare
begin
for i in 1..1000000 loop
  insert into tab1 values(
    i
   );
  
end loop;
end;
/
;

commit;

exec dbms_stats.gather_table_stats(user,'TAB1');


select * from tab1 where col1 = 1;
select * from tab1 where col1 = 1;


explain plan for
select /*+ FULL(tab1) */ * from tab1 where col1 = 1;

select * from table(dbms_xplan.display(format=>'ALL') );


explain plan for
select /*+ FULL(tab1) */ * from tab1 where col1 = 1;

select * from table(dbms_xplan.display(format=>'ALL') );


→全角スペースが入っていてもSQL実行、ヒント句使用ともに可能

 

(14)
psqlで確認


drop table tab1;
create table tab1(col1 bigint);
create unique index ind1 on tab1(col1);

start transaction;
insert into tab1 select
   g
from generate_series(1,1000000) g;
commit;

analyze tab1;

select * from tab1 where col1 = 1;
select * from tab1 where col1 = 1;

→全角スペースが入っているとSQL実行はエラーとなる

 

 

(2019)
SSMSで確認

drop table tab1;
create table tab1(col1 bigint);
create unique index ind1 on tab1(col1);

set nocount on
declare @i int;
set @i = 1;
begin transaction;
while @i <= 1000000
begin
  insert into tab1 values(
     @i
    );
 set @i = @i + 1;
end
commit;

update statistics tab1;

select * from tab1 where col1 = 1;
select * from tab1 where col1 = 1;

select * from tab1 with ( index ( 0 ) ) where col1 = 1;
select * from tab1 ( index ( 0 ) ) where col1 = 1;

メッセージ 1018、レベル 15、状態 1、行 7
'index' 付近に不適切な構文があります。この構文がテーブル ヒントの一部の場合、
WITH キーワードとかっこが必要になります。適切な構文については、SQL Server オンライン ブックを参照してください。

→全角スペースが入っていてもSQLは実行可能だが、ヒント句はエラーとなる