English 中文(简体)
VARCHAR附带的尺寸度量是什么?
原标题:What is a size metric attached to a VARCHAR?

我在整个应用程序中使用VARCHAR,发现一些特别令人困惑的地方。。。为什么我需要用一个长度来定义SQL VARCHAR列,例如VARCHAR(50)或VARCHAR(1000)?这个长度约束允许我定义首选的最大字符串长度,这是唯一的目的吗?VARCHAR(50)和VARCHAR(1000)之间是否存在性能差异?

最佳回答

这完全取决于DBMS的内部结构。例如,如果对varchar列进行索引,那么几乎可以肯定会得到一个设置为最大大小的关键部分。

这是因为索引必须非常高效,而且在这种情况下,您不想处理可变长度字段,因为这可能会减慢您的速度。

即使在数据库的数据区域,您也可能发现它只允许最大的大小。我看到过一些建议,只在一行中存储一个指向磁盘堆的指针,但这意味着每行读取两次磁盘,我认为这不是一个非常好的高性能选择。

列的大小会影响性能,比如一次可以读取多少条记录,一个n元树索引节点可以容纳多少条记录等等。

问题回答
  • SQLite: Size limits are completely ignored.
  • PostgreSQL: VARCHAR(N) is essentially equivalent to TEXT CHECK (LENGTH(x) <= N). There is no performance advantage to declaring a maximum size.
  • MySQL: Determines whether the string length is stored as one byte or two bytes.
  • Oracle: Higher size limits have a performance disadavantage.
  • MS SQL Server: VARCHAR columns greater than 900 bytes cannot be indexed.




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签