-
-
Notifications
You must be signed in to change notification settings - Fork 641
Closed
Description
Problem
Table
CREATE TABLE IF NOT EXISTS `super_hero` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`property` bigint(20) NOT NULL,
`kind` char(10) NOT NULL,
`name` varchar(200) NOT NULL,
primary key (`id`),
key `idx_property` (`property`),
key `idx_kind_property` (`kind`, `property`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
Database Connection
const conn = await mysql.createConnection({
host: "localhost",
port: 15000,
user: "root",
password: process.env.PW,
database: "biginttest",
supportBigNumbers: true,
bigNumberStrings: true,
});
Insert
const insertData = `INSERT INTO super_hero (\`property\`, \`name\`) VALUES (?, ?)`;
const r1 = await conn.query(insertData, ["36028797018963970", "marvel", "ironman"]); // 2^55
const r2 = await conn.query(insertData, ["288230376151711740", "marvel", "black panther", ]); // 2^58
Select
const selectData = `SELECT * FROM super_hero WHERE kind = ? and property > ?`;
const [r1, _fields] = await conn.execute(selectData, [
"marvel",
"36028797018963970",
]);
Ok, I got [ { id: '2', property: '288230376151711740', kind: 'marvel', name: 'black panther' } ]
. This is reasonable. Because JavaScript only manipulate 2^53 range. But I found my query in mysql query log.
Bigint column pass string.
Environment
- node 14.20.1
- mysql2 3.2.0
- mysql 5.7.41
Expect
I think, Node.js manipulate bigint column by string, final query populate numeric value.
-- Current query
SELECT * FROM super_hero WHERE property = '36028797018963970'
-- Expect query
SELECT * FROM super_hero WHERE property = 36028797018963970
The current query may cause 'table-scan'. 'bigint' column compare that using by string value.
Reproducable Repo.
npm install
node src/create.js
node src/insert.js
node src/select.js
show variables like 'general%';
set global general_log = 'ON'
And You can connect docker terminal. tail -f
command execute log file.
Metadata
Metadata
Assignees
Labels
No labels