4 ms·
I wish there were SQL "primitives" functions instead of the SQL language. For example if I want to pick a single row by id, with SQL I must send a query string
by jokoon 4y ago
I wish there were SQL "primitives" functions instead of the SQL language.
For example if I want to pick a single row by id, with SQL I must send a query string, which results in parsing, which means lower latency.
If I want to randomly select 100k rows among a database of 1 million entries, I need to build 10k query strings (I think?), which won't be fast to parse. I don't think this happens when using C pointers in C, C++ or arrays in other languages.
- RedShift1 4y agoIsn't that what prepared statements solve? Only parsed on the first execution and after that only the parameters change.
- tremon 4y agoExactly. Prepared statements or stored procedures avoid the continuous re-parsing of identical queries.
- zasdffaa 4y agoIf by 'randomly select' you do mean randomly, the TABLESAMPLE is what you want (although random means random pages not rows and the amount returned may be over or under) SELECT * FROM Sales.Customer TABLESAMPLE SYSTEM (10 PERCENT) ; for example. You can of course specify by rows instead.
- rrrrrrrrrrrryan 4y agoTo get 100k random rows in T-SQL it's: SELECT TOP (100000) * FROM tblNm ORDER BY newid()
- xpe 4y agoWhy 10k queries? You can probably do this with one query.