Index or Not Index

适合建索引的情况
* The column is queried frequently.

* A referential integrity constraint exists on the column.

* A UNIQUE key integrity constraint exists on the column.

*  Create an index if you frequently want to retrieve less than 15% of the rows in a large table.

* To improve performance on joins of multiple tables, index columns used for joins.
Primary and unique keys automatically have indexes, but you might want to create an index on a foreign key.

* There is a wide range of values (good for regular indexes).

* There is a small range of values (good for bitmap indexes).

* The column contains many nulls, but queries often select all rows having a value. 
   In this case, use the following phrase:
   WHERE COL_X > -9.99 * power(10,125)
   Using the preceding phrase is preferable to:
   WHERE COL_X IS NOT NULL
   This is because the first uses an index on COL_X (assuming that COL_X is a numeric column).

不适合建索引的情况
* Small tables do not require indexes. 

* There are many nulls in the column and you do not search on the not null values.

参考


这个错误通常发生在使用列表时,使用了元组作为索引。解决这个错误的方法有以下几种: 1. 使用整数索引:确保在使用列表时,使用的索引是整数类型而不是元组类型。例如,如果要访问列表中的第一个元素,可以使用索引0而不是(0,)。 2. 使用切片:如果需要访问列表的一部分元素,可以使用切片操作来获取一个新的列表。切片操作使用[start:end]的形式,其中start表示起始索引,end表示结束索引(不包含在切片中)。确保在使用切片时,起始索引和结束索引都是整数类型。 3. 检查索引的类型:在使用索引之前,可以使用type()函数检查索引的类型。如果发现索引是元组类型,可以进行相应的处理,例如将元组转换为整数或使用其他合适的索引方式。 4. 检查使用索引的上下文:有时候,错误可能是由于在错误的上下文中使用了索引导致的。检查代码中使用索引的地方,确保在正确的地方使用正确的索引类型。 下面是一个示例,演示了如何解决"list indices must be integers or slices, not Index"错误: ```python my_list = [1, 2, 3, 4, 5] index = (0,) # 错误的索引类型,应该是整数而不是元组 # 使用整数索引 print(my_list[0]) # 输出:1 # 使用切片 print(my_list[1:3]) # 输出:[2, 3] # 检查索引的类型 if type(index) == tuple: index = index[0] # 将元组索引转换为整数索引 print(my_list[index]) # 输出:1 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值