oracle - The fastest way to check if some records in a database table? -
I have a big table to work with. I have to see that there are some records whose parent_id is equal to my passing value. Currently I do this by implementing "my_table using select count (*) where parent_id =: id"; If the result> 0, it means that they exist.
Because this is a very large table, and I do not care what the actual number of records present, I just want to know if it exists, so I think count (*) Bit is disabled.
How do I apply this requirement most quickly? I'm using Oracle 10.
#Tips for Hibernation & amp; Tricks
It suggests writing in such a way:
Integer number = (integer) session .createQuery ("Select Count (*) to ...."). UniqueResult ();
I do not know what is the magic of the unique rule? Why does it fast?
To compare, select "1 from mytable where parent_id = passId and rowrum", which is more efficient?
If you are not interested in the number of records, then there is an EXISTS query one:
Select 'y' exists from double (where 1 select from your parents, where parent_id =: id)
if any record exists and nothing else So it will return 'Y'.
[Terms of your question on Hibernate's "Unique Result" - All this returns the same object when there is only one object to return - if multiple results return instead of 1 set of objects If the method goes, the method throws an exception.]
Comments
Post a Comment