MySQL Forums
Forum List  »  Connector/C++

Re: Microsoft C++ Exception std::out_of_range mysql-connector-c++-8.0.18-winx64
Posted by: egor s
Date: August 26, 2020 04:16AM

Hi,

I have table like this:

CREATE TABLE `a_very_big_table` (
`id` int(11) NOT NULL,
`f1` int(11) DEFAULT NULL,
`f2` int(11) DEFAULT NULL,
`f3` int(11) DEFAULT NULL,
`f4` int(11) DEFAULT NULL,
`f5` int(11) DEFAULT NULL,
`f6` int(11) DEFAULT NULL,
`f7` int(11) DEFAULT NULL,
`f8` int(11) DEFAULT NULL,
`f9` int(11) DEFAULT NULL,
`f10` int(11) DEFAULT NULL,
`f11` int(11) DEFAULT NULL,
`f12` int(11) DEFAULT NULL,
`f13` int(11) DEFAULT NULL,
`f14` int(11) DEFAULT NULL,
`f15` int(11) DEFAULT NULL,
`f16` int(11) DEFAULT NULL,
`f17` int(11) DEFAULT NULL,
`f18` int(11) DEFAULT NULL,
`f19` int(11) DEFAULT NULL,
`f20` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


with a lot of rows:

INSERT INTO a_very_big_table

SELECT number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number,number, number
FROM(
SELECT @row := @row + 1 AS number FROM
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t,
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2,
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3,
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t4,
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t5,
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t6,
(SELECT @row:=0) numbers
) tt;


c++ code:


struct MyData {
int id;
int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10;
int f11, f12, f13, f14, f15, f16, f17, f18, f19, f20;
};
std::vector<MyData> data;

auto t1 = std::chrono::system_clock::now();
auto res = session->sql(u8"SELECT * FROM a_very_big_table limit 1000").execute();
auto t2 = std::chrono::system_clock::now();
auto rows = res.fetchAll();

for (auto it : rows) {
MyData myData;
#define D(XX) myData.f##XX = it.get(XX)
myData.id = it.get(0);
D(1); D(2); D(3); D(4); D(5); D(6); D(7); D(8); D(9); D(10);
D(11); D(12); D(13); D(14); D(15); D(16); D(17); D(18); D(19); D(20);

data.emplace_back(std::move(myData));
}
auto t3 = std::chrono::system_clock::now();

std::cout
<< "query: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count()
<< " loop: " << std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t2).count() << std::endl;





I run this sample using visual studio 2017 v141 toolchain.
I read only 1000 rows, but my product database is about 1000000 rows.

1. Using std::out_of_range in Result.h (current version)

Release without attached debugger: "query: 1 loop: 72"
Release with attached debugger: "query: 1 loop: 11729"

Debug without attached debugger: "query: 3 loop: 579"
Debug with attached debugger: "query: 4 loop: 12935"

2. Using std::map::find in Result.h (my patched version)

Release without attached debugger: "query: 1 loop: 21"
Release with attached debugger: "query: 2 loop: 26"

Debug without attached debugger: "query: 4 loop: 495"
Debug with attached debugger: "query: 3 loop: 573"

Options: ReplyQuote




Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.