小编Ami*_*mir的帖子

如何通过缓存键锁定?

我试图实现一个通用的线程安全的Cache方法,我想知道我应该如何实现它的锁.

它应该看起来像这样:

//private static readonly lockObject = new Object();

public T GetCache<T>(string key, Func<T> valueFactory...)
{

  // try to pull from cache here

  lock (lockObject) // I don't want to use static object lock here because then every time a lock is performed, all cached objects in my site have to wait, regarding of the cache key.
  {
    // cache was empty before we got the lock, check again inside the lock

    // cache is still empty, so retreive the …
Run Code Online (Sandbox Code Playgroud)

c# asp.net caching locking thread-safety

14
推荐指数
1
解决办法
3376
查看次数

通过查询优化Oracle订单

我有一个大约有500万行的表,看起来像这样:

Erp_in:

corr_id varchar(50) (almost Unique)
corr_type nvarchar(1) (4 distinct values)
interface varchar(20) (around 10 distinct values)
indate DateTime
Run Code Online (Sandbox Code Playgroud)

使用3个不同的索引(corr_id,interface和indate)
而且我还有另一个表,我通常会将其与原始表连接,大约有100000行

Erp_In_failed:

corr_id
interface
error (clob)   
input (clob)
Run Code Online (Sandbox Code Playgroud)

带索引(corr_id和接口)

我想要优化的查询是简单的,因为:

SELECT a.corr_id, a.interface, a.indate, b.error 
FROM erp_in a left join erp_in_failed b on a.corr_id = b.corr_id and a.interface =          b.interface
Order by a.indate desc;
Run Code Online (Sandbox Code Playgroud)

如果我删除了订单,则查询不会花费那么长时间,但是如果不是更多,则对数据进行排序大约需要3分钟.

我该怎么做才能优化查询?我正在考虑将旧数据分区/删除到历史表/可能创建一个序列主键并按顺序或其他任何你想要的顺序...

编辑:
执行计划表示全表扫描,并且它不是连接需要这么长时间的顺序.
即使这个查询也需要永远:

SELECT * FROM erp_in
ORDER BY indate;
Run Code Online (Sandbox Code Playgroud)

我尝试过使用Paging,但这也不起作用,并且需要花费几分钟才能获得20个结果,也许我做错了?

如果我在indate字段上添加WHERE子句,它会使用索引,但只有当它小于20天时,除此之外的任何内容仍然使用全表扫描.(即使有40天,添加INDEX提示使查询运行得更快,但仍然不够).

只是为了好奇,我有一个简单的表,有100万行,订单需要几秒钟,有什么区别?是100万足以在RAM中排序?

谢谢,

sql oracle optimization partitioning query-optimization

5
推荐指数
1
解决办法
8695
查看次数