Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内存中SQL/NoSQL-保留查询功能-可能使用MySQL或SQL Server_Mysql_Sql Server_Nosql_In Memory Database_Document Based Database - Fatal编程技术网

内存中SQL/NoSQL-保留查询功能-可能使用MySQL或SQL Server

内存中SQL/NoSQL-保留查询功能-可能使用MySQL或SQL Server,mysql,sql-server,nosql,in-memory-database,document-based-database,Mysql,Sql Server,Nosql,In Memory Database,Document Based Database,我希望能够在数据存储中运行一组记录/文档,但这些记录在RAM中始终保持新鲜。我只需要使用大约1.5GB到2GB的RAM(可能更少)。 这将是基于服务器的,而不是嵌入式的 我知道内存中的键值存储将不适合我,因为我需要丰富的查询功能 我知道MySQL可以做基于内存的表,但不确定人们是否会按照我的想法使用这个功能。SQL Server能否在内存中锁定表?整张桌子 我应该查看哪些其他数据存储?Map/Reduce样式的查询如果速度快的话也可以。SQLLite可以在内存中为关系数据库解决方案运行。对于非关

我希望能够在数据存储中运行一组记录/文档,但这些记录在RAM中始终保持新鲜。我只需要使用大约1.5GB到2GB的RAM(可能更少)。 这将是基于服务器的,而不是嵌入式的

我知道内存中的键值存储将不适合我,因为我需要丰富的查询功能

我知道MySQL可以做基于内存的表,但不确定人们是否会按照我的想法使用这个功能。SQL Server能否在内存中锁定表?整张桌子


我应该查看哪些其他数据存储?Map/Reduce样式的查询如果速度快的话也可以。SQLLite可以在内存中为关系数据库解决方案运行。对于非关系数据库,RavenDB可以在内存中运行

SQLLite可以在内存中为关系数据库解决方案运行。对于非关系数据库,RavenDB可以在内存中运行

如果您可以将数据表示为一组对象,那么您就可以使用“富查询”功能并在内存中完成所有操作:这将比几乎所有的数据库解决方案都快得多。如果您可以将所有数据都保存在内存中,那么就不用担心数据库了

注意:如果在.NET中执行此操作,则必须以64位模式构建项目,因为在32位应用程序上,RAM中的数据不能超过~1.5 GB。如果无法在64位模式下构建/运行,则可能需要一个数据库

更新 我不确定我是否遵循了你所说的:我不确定什么是流行系统,这会让我相信我没有使用流行系统。我也不知道什么是“土生土长”的对象,什么是“土生土长”的.NET系统。我使用的只是标准的.NET4.0,当我说对象时,我的意思是你写的类可以保存你的数据。从那时起,您将数据加载到内存中(我不知道如何获取数据:文件、数据库、网络等),然后Linq为您执行ORM。线程安全只在访问内部对象集合时才起作用,只需使用一个简单的锁即可


哦,如果是自制的.NET系统,那么这些对象是否托管在一台服务器上并受到多个客户端的攻击


对于我正在处理的数据,我不需要任何类型的丰富查询功能(既不需要在内存中,也不需要从数据库中获取),这就是为什么我们将无法放入内存的内容存储到嵌入式数据库()中的原因。这样,我们所有的数据都包含在磁盘上,当我们需要它时,我们会采用最短/最快的路径将其放入内存。通过网络只会降低速度,因此您可以这样做,但只能在绝对必要时这样做(即,您有一个硬约束,即2GB数据位于本地计算机以外的某个数据库中)。

如果您可以将数据表示为一组对象,那么您可以将其用作“丰富查询”这将比几乎所有的数据库解决方案都要快得多。如果您可以将所有数据都保存在内存中,那么就不用担心数据库了

注意:如果在.NET中执行此操作,则必须以64位模式构建项目,因为在32位应用程序上,RAM中的数据不能超过~1.5 GB。如果无法在64位模式下构建/运行,则可能需要一个数据库

更新 我不确定我是否遵循了你所说的:我不确定什么是流行系统,这会让我相信我没有使用流行系统。我也不知道什么是“土生土长”的对象,什么是“土生土长”的.NET系统。我使用的只是标准的.NET4.0,当我说对象时,我的意思是你写的类可以保存你的数据。从那时起,您将数据加载到内存中(我不知道如何获取数据:文件、数据库、网络等),然后Linq为您执行ORM。线程安全只在访问内部对象集合时才起作用,只需使用一个简单的锁即可


哦,如果是自制的.NET系统,那么这些对象是否托管在一台服务器上并受到多个客户端的攻击

对于我正在处理的数据,我不需要任何类型的丰富查询功能(既不需要在内存中,也不需要从数据库中获取),这就是为什么我们将无法放入内存的内容存储到嵌入式数据库()中的原因。这样,我们所有的数据都包含在磁盘上,当我们需要它时,我们会采用最短/最快的路径将其放入内存。通过网络只会降低您的速度,因此您可以这样做,但只能在绝对必要时这样做(即,您有一个硬约束,即2GB数据位于本地计算机以外的某个数据库上)。

是一个内存中符合ACID的SQL数据库,针对高速OLTP进行了优化。它运行在64位Linux或Mac OS X上,有一个开源社区版,以及多种语言的客户端库

当你说“富查询能力”时,听起来更像是OLAP用例,但是如果查询具有基本的复杂性,那么它可能非常适合VoltDB。您可以分享更多关于您的用例的信息吗?

是一个内存中符合ACID的SQL数据库,它针对高速OLTP进行了优化。它运行在64位Linux或Mac OS X上,有一个开源社区版,以及多种语言的客户端库


当你说“富查询能力”时,听起来更像是OLAP用例,但是如果查询具有基本的复杂性,那么它可能非常适合VoltDB。你能分享更多关于你的用例吗?

我必须同意Lirik的观点。在.Net术语中,使用对象作为数据并使用LINQ查询数据集合必须是实现您的要求的最快方法之一,同时您还可以使用丰富的查询语言

如果你担心收藏的规模
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linq_Question
{
    public class Product
    {
        public enum Categories
        {
            CatOne,
            CatTwo,
            CatThree
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public Categories Category { get; set; }
        public decimal Price { get; set; }

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linq_Question
{
    public class ProductCriteria
    {
        public Product.Categories? WhereCategoryIs { get; set; }
        public decimal? WherePriceIsGreaterThan { get; set; }
        public decimal? WherePriceIsLessThan { get; set; }
        public string WhereNameContains { get; set; }

        public ProductCriteria()
        {

        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Linq_Question
{
    public class ProductRepository
    {
        private List<Product> products;

        public ProductRepository()
        {
            products = new List<Product>();
            products.Add(new Product() { Category = Product.Categories.CatOne, Id = 1, Name = "Product 1", Price = 100 });
            products.Add(new Product() { Category = Product.Categories.CatTwo, Id = 2, Name = "Product 2", Price = 120 });
            products.Add(new Product() { Category = Product.Categories.CatThree, Id = 3, Name = "Product 3", Price = 300 });
            products.Add(new Product() { Category = Product.Categories.CatOne, Id = 4, Name = "Product 4", Price = 400 });
            products.Add(new Product() { Category = Product.Categories.CatTwo, Id = 5, Name = "Product 5", Price = 500 });
            products.Add(new Product() { Category = Product.Categories.CatThree, Id = 6, Name = "Product 6", Price = 600 });
        }

        public IEnumerable<Product> Retrieve(ProductCriteria criteria)
        {
            return this.products.Where(FilterProducts(criteria));
        }

        private Func<Product, bool> FilterProducts(ProductCriteria criteria)
        {
            Expression<Func<Product, bool>> predicate = PredicateBuilder.True<Product>();
            List<IProductFilter> filters = new List<IProductFilter>();
            filters.Add(new PriceIsGreaterThanFilter());
            filters.Add(new CategoryFilter());

            foreach (var item in filters)
            {
                if (item.IsValidFilter(criteria))
                {
                    predicate = predicate.And(item.ApplyFilter(criteria));
                }
            }
            return predicate.Compile();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Linq_Question
{
    public interface IProductFilter
    {
        bool IsValidFilter(ProductCriteria criteria);
        Expression<Func<Product, bool>> ApplyFilter(ProductCriteria criteria);
    }

    public class CategoryFilter : IProductFilter
    {
        public bool IsValidFilter(ProductCriteria criteria)
        {
            return (criteria.WhereCategoryIs.HasValue);
        }

        public Expression<Func<Product, bool>> ApplyFilter(ProductCriteria criteria)
        {
            return (p => p.Category == criteria.WhereCategoryIs.GetValueOrDefault());
        }
    }

    public class PriceIsGreaterThanFilter : IProductFilter
    {
        public bool IsValidFilter(ProductCriteria criteria)
        {
            return (criteria.WherePriceIsGreaterThan.HasValue);
        }

        public Expression<Func<Product, bool>> ApplyFilter(ProductCriteria criteria)
        {
            return (p => p.Price > criteria.WherePriceIsGreaterThan.GetValueOrDefault());
        }
    }
}
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace Linq_Question
{
    public static class PredicateBuilder
    {
        public static Expression<Func<T, bool>> True<T>() { return f => true; }
        public static Expression<Func<T, bool>> False<T>() { return f => false; }

        public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
                                                            Expression<Func<T, bool>> expr2)
        {
            var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
            return Expression.Lambda<Func<T, bool>>
                  (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
        }

        public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
                                                             Expression<Func<T, bool>> expr2)
        {
            var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
            return Expression.Lambda<Func<T, bool>>
                  (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linq_Question
{
    class Program
    {
        static void Main(string[] args)
        {
            ProductRepository repo = new ProductRepository();
            Console.WriteLine("Items over 100");
            foreach (var item in repo.Retrieve(new ProductCriteria() { WherePriceIsGreaterThan = 100 }))
            {
                Console.WriteLine(string.Format("Name {0}, Category {1}, Price {2}", item.Name, item.Category, item.Price));
            }
            Console.WriteLine("Items with a Category of Two");
            foreach (var item in repo.Retrieve(new ProductCriteria() { WhereCategoryIs = Product.Categories.CatTwo }))
            {
                Console.WriteLine(string.Format("Name {0}, Category {1}, Price {2}", item.Name, item.Category, item.Price));
            }

            Console.Read();

        }
    }
}