[MDEV-29218] PS + array binding does not work with triggers Created: 2022-07-30  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.4.26, 10.6.9, 10.8.4, 10.11
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Luciano Barcaro Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None

Attachments: File MDEV29218.c    

 Description   

Hi Georg, whassup?

I found another bug related to executemany. (Does not affect execute with explicit values)

If my table has any trigger, only one row is inserted. But, the trigger is called n times (n rows passed) with the same data.

import mariadb
 
db = mariadb.connect(host='10.4.0.8', user='Administrador', password='XXXXX', database='tmp')
qr = db.cursor(buffered=True)
qr.execute('drop table if exists aaa')
qr.execute("""
CREATE TABLE `aaa` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `some_field` varchar(10) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB
""")
 
to_be_inserted = [(None, f'aaa_{i}') for i in range(10)]
qr.executemany('insert into aaa values (?, ?) returning id', to_be_inserted)
inserted = qr.fetchall()
print(f'Should be', len(to_be_inserted), 'got', len(inserted), '. What whas inserted:', inserted)
 
# ----------------------
qr.execute('drop table if exists aaa_spy')
qr.execute("""
CREATE TABLE `aaa_spy` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `aaa_id` int(10) unsigned NOT NULL,
  `aaa_some_field` varchar(10) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM
""")
qr.execute('drop trigger if exists aaa_after_insert')
qr.execute("""
CREATE TRIGGER aaa_after_insert
AFTER INSERT
ON aaa FOR EACH ROW
   insert into aaa_spy values (null, new.id, new.some_field)
""")
 
to_be_inserted = [(None, f'aaa_{i}') for i in range(10, 20)]
qr.executemany('insert into aaa values (?, ?) returning id', to_be_inserted)
inserted = qr.fetchall()
print(f'Should be', len(to_be_inserted), 'got', len(inserted), '. What whas inserted:', inserted)  # Wrong!
 
# What was inserted?
qr.execute('select aaa_id, aaa_some_field from aaa_spy where aaa_id >= 11')
# always the same data...
for _id, f in qr:
    print(_id, f)

This snippet returns this:

Should be 10 got 10 . What whas inserted: [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)]
Should be 10 got 1 . What whas inserted: [(16,)]
16 aaa_10
16 aaa_10
16 aaa_10
16 aaa_10
16 aaa_10
16 aaa_10
16 aaa_10
16 aaa_10
16 aaa_10



 Comments   
Comment by Georg Richter [ 2022-07-31 ]

Moved from CONPY-219. Test case (in C) attached: While text protocol works ok, binary protocol fails.

Output:

# text protocol
# affected_rows: 3
# rows in t2: 3
# binary protocol
# affected_rows: 1
# rows in t2: 2

Comment by Sergei Golubchik [ 2022-08-01 ]

What server versions are affected?

Comment by Georg Richter [ 2022-08-01 ]

I reproduced it with 10.4 and 10.8 - other versions not tested yet.

Comment by Luciano Barcaro [ 2022-08-24 ]

Any news about this bug?

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