bizstation / transactd

The high-speed and advanced NoSQL interface plugin for MySQL / MariaDB.
GNU General Public License v2.0
18 stars 1 forks source link

What is the best code? #34

Open rush2ko opened 8 years ago

rush2ko commented 8 years ago

It is a sample table. CREATE TABLE recommand_info ( InfoSN INT(11) NOT NULL AUTO_INCREMENT, UserSN INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (InfoSN), UNIQUE INDEX UserSN (UserSN) ) COLLATE='utf8_general_ci' ENGINE=InnoDB;

I want to full record count from recommand_info table.

with activeTable:

query q; recordset rs; q.select(L"UserSN").reject(0xFFFF); at.read(q, rs); count = rs.size();

or

query q; recordset rs; q.select(L"UserSN").where(L"UserSN", L">", 0).reject(0xFFFF); at.read(q, rs); count = rs.size();

bizstation commented 8 years ago

No, it is not correct. Key value to start the searching has not been specified.

at.index(0).keyValue(INT_MIN).read(q, rs);

InfoSN is not unsigned. The start value must be INT_MIN to read from the first record.

There is a much faster way than above.

table* tb = db->openTable(L"recommand_info", TD_OPEN_READONLY);
uint_td count= tb->recordCount(false);
tb->release();

thanks.

rush2ko commented 8 years ago

Thank you so much.