我有ID,startIPNum和endIPNum表。 startIPNum和endIPNum已經被轉換爲長字符而不是IP字符串。在startIPNum和endIPNum範圍內進行IP數字查找,並使用性能優化進行休眠
下面的查詢工作以及3000個3200毫秒
List<GeoIP> oneResult = new LinkedList(getHibernateTemplate().find(
"from GeoIP where "+ipNum+" >= startIpNum and "+ipNum+" <= endIpNum"));
此查詢的工作和地方3000之間花費的4700毫秒
List<GeoIP> oneResult = new LinkedList(getHibernateTemplate().find(
"from GeoIP where "+ipNum+" between startIpNum and endIpNum"));
的問題是,之間需要的地方:有沒有辦法來優化這種查找要花很少的時間?該表有超過3'500'000條記錄。
對於最長的前綴匹配IP地址查找,存在高度優化的數據結構,但它們不適合SQL數據庫模型。 (見例如http://www.cesnet.cz/doc/techzpravy/2002/datastruct/datastruct.pdf) – bew 2010-11-05 14:25:58