Hibernate: select bucketen0_.bucket_id as bucket1_1_, bucketen0_.bucket_number as bulket2_1_, bucketen0_.bucket_description as bucket3_1_, bucketen0_.status as status14_1_, bucketen0_.updated_timestamp as updated15_1_ from bucket bucketen0_ leftouterjoin bucket_location bucketlo1_ on bucketen0_.bucket_id=bucketlo1_.bucket_id where bucketlo1_.location = ? limit ? offset ?
3.2 query bucket_location sql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Hibernate: select bucketlo0_.bucket_id as bucket1_8_1_, bucketlo0_.bucket_location_id as bucket1_8_0_, bucketlo0_.location as location2_8_0_ from bucket_location bucketlo0_ where bucketlo0_.bucket_id in ( select bucketen0_.bucket_id from bucket bucketen0_ leftouterjoin bucket_location bucketlo1_ on bucketen0_.bucket_id=bucketlo1_.bucket_id where bucketlo1_.location = ? )
Hibernate: select zipcode0_.bucket_location_id as bucket5_9_1_, zipcode0_.valuation_type_code as valuatio2_9_0_, zipcode0_.handling_type_code as handling3_9_0_, zipcode0_.handling_type_description as handling4_9_0_ from bucket_location_zip_code zipcode0_ where zipcode0_.bucket_location_id in ( select bucketlo0_.bucket_location_id from bucket_location bucketlo0_ where bucketlo0_.bucket_id in ( select bucketen0_.bucket_id from bucket bucketen0_ leftouterjoin bucket_location bucketlo1_ on bucketen0_.bucket_id=bucketlo1_.bucket_id where bucketlo1_.location = ? ) )
Hibernate: select bucketlo0_.bucket_id as bucket1_8_1_, bucketlo0_.bucket_location_id as bucket1_8_0_, bucketlo0_.location as location2_8_0_ from bucket_location bucketlo0_ where bucketlo0_.bucket_id in ( ?, ?, ?, ?, ? )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Hibernate: select zipcode0_.bucket_location_id as bucket5_9_1_, zipcode0_.valuation_type_code as valuatio2_9_0_, zipcode0_.handling_type_code as handling3_9_0_, zipcode0_.handling_type_description as handling4_9_0_ from bucket_location_zip_code zipcode0_ where zipcode0_.bucket_location_id in ( select bucketlo0_.bucket_location_id from bucket_location bucketlo0_ where bucketlo0_.bucket_id in ( ?, ?, ?, ?, ? ) )
可以看到改进之后,sql中的查询条件变为了bucketlo0_.bucket_id in (?, ?, ?, ?, ?) 这样的限定范围的in查询,这样我们就可以通过设置@BatchSize及其value来限定查询的个数,从而达到最有效和最快速查询的目的。