indexing

SELECT with query variables not using INDEXes

谁说我不能喝 提交于 2020-01-03 09:11:30
问题 I was playing around (out of interest) with retrieving a tree of nodes in a simple adjacency list with a recursive query using local variables. The solution i have so far is fun but i wonder (and this is my only question) why MySQL refuses to use any INDEX to optimize this query. Shouldn't MySQL be able to lookup the nearest child(s) by using an INDEX ? I'm curious why MySQL doesn't. Even when i use FORCE INDEX the execution plan doesn't change. This is the query so far, with 5 being the ID

Check if the index exists or not Elasticsearch

筅森魡賤 提交于 2020-01-03 09:05:21
问题 I want to check in elasticsearch if the index exists or not. If it not exists it should create the index and do other functionality. I try to find out a solution for that, but did not find any perfect solution for that. Can anyone have any solution to solve this problem. I am using Elasticsearch library. **$client = new Elasticsearch\Client();** 回答1: As per index operations and source code the following should work $client = new Elasticsearch\Client(); $indexParams['index'] = 'my_index';

Pandas SettingWithCopyWarning When Using loc

自闭症网瘾萝莉.ら 提交于 2020-01-03 08:34:28
问题 Have a general question on assignments with indexing/slicing using .loc. Assume the below DataFrame, df: df: A B C 0 a b 1 a b 2 b a 3 c c 4 c a code to reproduce: df = pd.DataFrame({'A':list('aabcc'), 'B':list('bbaca'), 'C':5*[None]}) I create df1 using: df1=df.loc[df.A=='c'] df1: A B C 3 c c 4 c a I then assign a value to C based upon a value in B using: df1.loc[df1.B=='a','C']='d' The assignment works, but I receive a SettingWithCopy warning. Am I doing something wrong or is this the

Pandas SettingWithCopyWarning When Using loc

☆樱花仙子☆ 提交于 2020-01-03 08:32:30
问题 Have a general question on assignments with indexing/slicing using .loc. Assume the below DataFrame, df: df: A B C 0 a b 1 a b 2 b a 3 c c 4 c a code to reproduce: df = pd.DataFrame({'A':list('aabcc'), 'B':list('bbaca'), 'C':5*[None]}) I create df1 using: df1=df.loc[df.A=='c'] df1: A B C 3 c c 4 c a I then assign a value to C based upon a value in B using: df1.loc[df1.B=='a','C']='d' The assignment works, but I receive a SettingWithCopy warning. Am I doing something wrong or is this the

When should I create database indexes? [duplicate]

我与影子孤独终老i 提交于 2020-01-03 08:18:06
问题 This question already has answers here : When should you consider indexing your sql tables? (8 answers) Index all columns (5 answers) Closed last year . When to set index for a table, during table creation or on performance tuning? What are the advantages and disadvantages of indexing? 回答1: Many (most?) DBMS use indexes to support unique constraints. Always create indexes to enforce unique constraints; they (the constraints) are crucial to the correct operation of your database. Where you

Why MongoDB doesn't use Index Intersection?

牧云@^-^@ 提交于 2020-01-03 07:29:18
问题 I am trying to reproduce the first example of index intersection instruction (http://docs.mongodb.org/manual/core/index-intersection/) but facing a problem: mongo doesn't uses both indexes My steps: Download mongo (3.0.3) and install it Run mongod: mongod.exe --dbpath d:\data (folder is empty) Run mongo: mongo.exe Add indexes: db.orders.ensureIndex({ qty: 1 }) db.orders.ensureIndex({ item: 1 }) db.orders.getIndexes() [{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.orders" },

Django Model Choices: IntegerField vs CharField

寵の児 提交于 2020-01-03 07:17:54
问题 TL;DR : I have a table with millions of instances and I'm wondering how should I index it. I have a Django project that uses SQL Server as the database backend. After having a model with around 14 million instances in the Production environment, I realized that I was getting performance issues: class UserEvent(models.Model) A_EVENT = 'A' B_EVENT = 'B' types = ( (A_EVENT, 'Event A'), (B_EVENT, 'Event B') ) event_type = models.CharField(max_length=1, choices=types) contract = models.ForeignKey

why i make a 2dsphere index ,but when i query it shows s2cursor?

拜拜、爱过 提交于 2020-01-03 05:47:08
问题 why i make a 2dsphere index ,but when i query it shows s2cursor, i think it should be geosearchcursor. the mongodb document says this: http://docs.mongodb.org/manual/reference/method/cursor.explain/#explain-output-fields-core cursor is a string that reports the type of cursor used by the query operation: BasicCursor indicates a full collection scan. BtreeCursor indicates that the query used an index. The cursor includes name of the index. When a query uses an index, the output of explain()

Why is this Postgis distance query so slow? Postgres' query estimator off by a factor of 10000x?

喜欢而已 提交于 2020-01-03 05:37:12
问题 I'm trying to find all posts that were within a certain distance, but unfortunately for some inputs the query is extremely slow. Here's some examples: -- fast (1 millisecond) SELECT 1 FROM post po WHERE ST_DWithin(po.geog, ST_SetSRID(ST_MakePoint(-47, -70), 4326)::geography, 4500 * 1609.34) LIMIT 10; -- slow (2 seconds) SELECT 1 FROM post po WHERE (po.geog <-> ST_SetSRID(ST_MakePoint(-47, -70), 4326)::geography) < 4500 * 1609.34 LIMIT 10; -- slow (9 seconds) SELECT 1 FROM post po WHERE ST

Avoiding 'sort order by' in query plan

Deadly 提交于 2020-01-03 05:32:18
问题 I have a table like this: create table A ( fieldA numeric, fieldB varchar(255), fieldC varchar(255), ... fields ... constraints ... ); And I have unique B-tree index on fieldB . So, when I execute query like this: select /*+ index(a)*/ * from A a where fieldB > 'LOW' and fieldB < 'HIGH' order by fieldB I expect to see query plan with index range scan and without sort order by clause (or any other type of sort), because of existing index. In fact, I have sort order by in query plan explain