[MDEV-31715] dbug_print(select_lex) prints inequivalent query when const table is involved Created: 2023-07-17  Updated: 2023-07-17  Resolved: 2023-07-17

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 11.0
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Yuchen Pei Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

Assuming the query printed by dbug_print(select_lex) should produce the same result as the original query, the following example shows dbug_print does not always follow this rule:

CREATE TABLE tbl_a (
  a int,
  primary key (a)
);
 
CREATE TABLE tbl_b (
  c int,
  d int,
  primary key (c, d)
);
 
INSERT INTO tbl_a VALUES (1), (2), (3);
INSERT INTO tbl_b VALUES (1, 11), (2, 22), (3, 33);
 
# original query
SELECT d FROM tbl_a JOIN tbl_b ON a = c WHERE a IN (1);
# dbug_print(join->select_lex) before join->optimize(), ok: prduces one row
select tbl_b.d AS d from (tbl_a join tbl_b on(tbl_a.a = tbl_b.c)) where tbl_a.a = 1;
# dbug_print(join->select_lex) before join->exec(), not equivalent: produces three rows
select tbl_b.d AS d from tbl_a join tbl_b where tbl_b.c = 1;
 
drop table tbl_a,tbl_b;

The table tbl_a was optimised into a const table, which might be why dbug_print prints a inequivalent query because the query does not capture this piece of information.



 Comments   
Comment by Yuchen Pei [ 2023-07-17 ]

From sanja in #engineering, dbug_print "is supposed to print what is really in the SELECT_LEX. Usually it should be an equivalent select (if it was not optimised out)"

Generated at Thu Feb 08 10:25:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.