首页 \ 问答 \ Mysql在哪里查询优化(Mysql where between query optimization)

Mysql在哪里查询优化(Mysql where between query optimization)

以下是自治系统号码数据库的格式(从该站点下载和解析!)。

range_start  range_end  number  cc  provider
-----------  ---------  ------  --  -------------------------------------
   16778240   16778495   56203  AU  AS56203 - BIGRED-NET-AU Big Red Group
   16793600   16809983   18144      AS18144

745465总行数

普通查询如下所示:

select * from table where 3232235520 BETWEEN range_start AND range_end

工作正常,但我查询大量的IP来检查他们的AS信息,最终需要花费太多的电话和时间。

Profiler快照:

Blackfire探查器快照

我有两个索引:

  1. id列
  2. range_start和range_end列上的组合索引作为make唯一行。

问题:

  1. 有没有办法在单个查询中查询大量的IP?
    • multiple where (IP between range_start and range_end) OR where (IP between range_start and range_end) OR ...有效,但我无法获取IP - >行映射或检索哪些IP的行。
  2. 有没有建议改变数据库结构以优化查询速度并减少时间?

任何帮助将不胜感激! 谢谢!


Below is the format of the database of Autonomous System Numbers ( download and parsed from this site! ).

range_start  range_end  number  cc  provider
-----------  ---------  ------  --  -------------------------------------
   16778240   16778495   56203  AU  AS56203 - BIGRED-NET-AU Big Red Group
   16793600   16809983   18144      AS18144

745465 total rows

A Normal query looks like this:

select * from table where 3232235520 BETWEEN range_start AND range_end

Works properly but I query a huge number of IPs to check for their AS information which ends up taking too many calls and time.

Profiler Snapshot:

Blackfire profiler snapshot

I've two indexes:

  1. id column
  2. a combine index on the range_start and range_end column as both the make unique row.

Questions:

  1. Is there a way to query a huge number of IPs in a single query?
    • multiple where (IP between range_start and range_end) OR where (IP between range_start and range_end) OR ... works but I can't get the IP -> row mapping or which rows are retrieved for which IP.
  2. Any suggestions to change the database structure to optimize the query speed and decrease the time?

Any help will be appreciated! Thanks!


原文:https://stackoverflow.com/questions/42513868
更新时间:2023-05-25 22:05

最满意答案

第二次查看你的代码(在我的咖啡之后,它更好), java.io.IOException: Pipe closed使用JSch 0.1.42 java.io.IOException: Pipe closed是由你建议的逻辑问题引起的:

你的finally块你的for循环中。 因为始终调用finally块,无论是否发生异常,客户端总是在第一个iteraton末尾的finally块中断开连接:

for(...){
    try{
        ...
    }catch(...){
        ...
    }finally{
        # this finally block is inside your for loop
        # finally block is always called whether an exception occur or not
        # on the first iteration, this is called and close your client
        try{
            if(client!=null){
                # nope, it will close the client for next iteration!
                client.disconnect();
            }if(fsdisPath!=null){
                # good to close this however
                fsdisPath.close();
            }
        }catch(Exceptionex){
            ex.printStackTrace();
        }
    }
}

相反,你应该有类似的东西:

try {
    for(...){
        try{
            ...
        }catch(...){
            ...
        }finally{
            try{
                if(fsdisPath!=null){
                    fsdisPath.close();
                }
            }catch(Exceptionex){
                ex.printStackTrace();
            }
        }
    }
} finally {
    if(client!=null){
        client.disconnect();
    }
}

将for循环作为代码可用性的函数也可能是个好主意;)

java.lang.NoSuchFieldError: identities是由您的应用程序使用不同的JSch版本的另一个标准引起的,因为您根据Maven依赖关系树提供了证据。

做了一个mvn依赖:tree -Dverbose在项目中(使用jsch 0.1.50)我发现该项目和我在原帖中添加了所有日志:特别是:+ - org.mule.transports:mule-transport -sftp:jar:3.4.0:编译[INFO] | + - (com.jcraft:jsch:jar:0.1.44-1:compile - 与0.1.42冲突省略)+ - (com.jcraft:jsch:jar:0.1.42:compile - 省略与0.1的冲突。 50)[INFO] - com.jcraft:jsch:jar:0.1.50:编译[INFO]


Looking at your code a second time (right after my coffee, it's better), java.io.IOException: Pipe closed with JSch 0.1.42 is effectively caused by a logic issue as you suggested:

Your finally block is inside your for loop. As a finally block is always called whether an exception occur or not your client is always disconnected by the finally block at the end of the very first iteraton:

for(...){
    try{
        ...
    }catch(...){
        ...
    }finally{
        # this finally block is inside your for loop
        # finally block is always called whether an exception occur or not
        # on the first iteration, this is called and close your client
        try{
            if(client!=null){
                # nope, it will close the client for next iteration!
                client.disconnect();
            }if(fsdisPath!=null){
                # good to close this however
                fsdisPath.close();
            }
        }catch(Exceptionex){
            ex.printStackTrace();
        }
    }
}

Instead you should have something like:

try {
    for(...){
        try{
            ...
        }catch(...){
            ...
        }finally{
            try{
                if(fsdisPath!=null){
                    fsdisPath.close();
                }
            }catch(Exceptionex){
                ex.printStackTrace();
            }
        }
    }
} finally {
    if(client!=null){
        client.disconnect();
    }
}

It may also be a good idea to have your for loop as a function for code lisibility ;)

java.lang.NoSuchFieldError: identities is caused by another par of your application using a different JSch version as you put into evidence per your Maven dependency tree.

did a mvn dependency:tree -Dverbose in the project (using jsch 0.1.50) and I found that the project and I have added all the logs in the original post: Particularly this : +- org.mule.transports:mule-transport-sftp:jar:3.4.0:compile [INFO] | +- (com.jcraft:jsch:jar:0.1.44-1:compile - omitted for conflict with 0.1.42) +- (com.jcraft:jsch:jar:0.1.42:compile - omitted for conflict with 0.1.50) [INFO] - com.jcraft:jsch:jar:0.1.50:compile [INFO]

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)