SQL:优化查询以进行少量IO操作(SQL : Optimizing query to have few IO operations)
如何重写以下查询以返回具有少量IO操作和较少响应时间的结果
select *, (select Product_Name from InventoryMaster J2 where J1.ParentItem=J2.ItemId) as ParentName, (select Description from InventoryMaster J2 where J1.ParentItem=J2.ItemId) as ParentDesc from InventoryMaster J1 where Flag like '%N%'
InventoryMaster表有一个父Item列,它将存储另一条记录ItemId(用于父子关系)的某些记录
How can i rewrite the below query to return results with few IO operation and less response time
select *, (select Product_Name from InventoryMaster J2 where J1.ParentItem=J2.ItemId) as ParentName, (select Description from InventoryMaster J2 where J1.ParentItem=J2.ItemId) as ParentDesc from InventoryMaster J1 where Flag like '%N%'
The InventoryMaster table has a parent Item column where it will store another records ItemId (for parent-child relatioship) for some records
原文:https://stackoverflow.com/questions/1737103
最满意答案
您可以使用
ScheduledExecutorService
进行此操作。 从示例文档中:import static java.util.concurrent.TimeUnit.*; class BeeperControl { private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); public void beepForAnHour() { final Runnable beeper = new Runnable() { public void run() { System.out.println("beep"); } }; final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); scheduler.schedule(new Runnable() { public void run() { beeperHandle.cancel(true); } }, 60 * 60, SECONDS); } }
您可以创建此
ExecutorService
的实例,并告诉它以某个时间间隔刷新令牌。但也许更简单的解决方案是使用线程同步来确保在多个线程争用它时只发生一次令牌刷新。 可以使用
ReentrantLock
或Semaphore
确保只有一个线程刷新令牌。You could use a
ScheduledExecutorService
for this. From the example docs:import static java.util.concurrent.TimeUnit.*; class BeeperControl { private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); public void beepForAnHour() { final Runnable beeper = new Runnable() { public void run() { System.out.println("beep"); } }; final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); scheduler.schedule(new Runnable() { public void run() { beeperHandle.cancel(true); } }, 60 * 60, SECONDS); } }
You could create an instance of this
ExecutorService
and tell it to refresh the token at some interval.But perhaps a simpler solution is to use thread synchronization to ensure only one token refresh happens when multiple threads are contesting for it.
ReentrantLock
orSemaphore
could be used to ensure only one thread is refreshing the token.
相关问答
更多-
如何在全局范围内保存变量标记并每10小时更新一次(How to save a variable token Globally and update it every 10 hours)[2023-05-13]
您可以使用ScheduledExecutorService进行此操作。 从示例文档中: import static java.util.concurrent.TimeUnit.*; class BeeperControl { private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); public void beepForAnHour() { final Runnab ... -
rrdtool只需10个小时(rrdtool graphing only 10 hours)[2022-09-17]
解决方案是初始化添加此参数的数据库: RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 The solution was initial ... -
update mytable set lastvisited=now() where person='john' and lastvisited<(now()-interval 10 hour); update mytable set lastvisited=now() where person='john' and lastvisited<(now()-interval 10 hour);
-
如何更新ECR登录令牌而不必每12小时重新生成一次?(How to update ECR login token without regenerate every 12 hours?)[2023-08-06]
据我所知,你必须在每16小时后(或8小时后我不记得这个数字)重新生成ECR令牌, 为此,您可以使用任何方法,如CRON工作,詹金斯工作或任何其他。 但是没有设置为ECR中的令牌设置年龄。 我没有看到你提供的链接,但看起来这是詹金斯的某种工作。 如果作业成功运行,请为作业设置定期构建触发器。 在配置Jenkins的作业页面中有一个选项“定期生成”,您需要指定CRON类似的设置。 如果您的工作本身在进行,请检查您机器上的钥匙/角色。 尽管如此,你的运气没有帮助邮政詹金斯控制台登录这里。 As I know, Y ... -
通过split()方法尝试这种方式, String timme = "13:10"; String[] time = timme.split ( ":" ); int hour = Integer.parseInt ( time[0].trim() ); int min = Integer.parseInt ( time[1].trim() ); Try this way, by split() method, String timme = "13:10"; String[] time = timme.s ...
-
你似乎在调用单一化的report而不是reports 。 if exercise.report.last 如果报告与exercise_many相关,则需要使用exercise.reports.last进行调用 此外,您在问题中提到了results ,但在视图中调用了reports 。 练习有很多结果。 ... exercise.report.last 请确保您调用适当的复数方法reports或results It seems you calling singularized report instead ...
-
如何更新corona SDK中的加载保存表中的一个变量(How do you update one variable in a load-save table in corona SDK)[2021-11-25]
尝试这个: local value = loadsave.loadTable("trying.json", system.DocumentsDirectory) if( 5+5 == 10) then value.one = "yes" loadsave.saveTabe(value, "trying.json", system.DocumentsDirectory) end Try this: local value = loadsave.loadTable("trying.json" ... -
我想你可以这样做: simple_variable = initial_value def ViewName(request): global simple_variable simple_variable = value ... def AnotherViewName(request): global simple_variable I think you can do this way: simple_variable = initial_value def ...
-
仅仅因为在那次迭代中,你的dict没有关键results 。 测试密钥是否在字典中的正确方法是: if 'result' in j: .... 如果您还想检查它的值是否为None或任何其他falsey值,则: if 'result' in j and j['result']: ... 与您调用服务相关的另一个假设是,服务器会不时地返回错误消息。 如果发生这种情况,JSON结构可能不是您所期望的,您应该检查文档是否说明了这一点并相应地处理它。 Simply because in tha ...
-
您可以将exception保存在变量中并在onPostExecute ()中检查它并隐藏您的按钮。 new AsyncTask
() { Exception error; @Override protected Boolean doInBackground(Void... params) { try { // do work return true; ...