indexing

mysql - join first and last records by group type?

梦想的初衷 提交于 2021-02-10 19:46:37
问题 With a table like: idx type dat 0 a foo1 1 b foo2 2 c foo3 3 a foo4 4 b foo5 5 c foo6 6 a foo7 7 b foo8 8 c foo9 How can i get the first and last data of each type: for example: a foo1 foo7 b foo2 foo8 c foo3 foo9 I have tried this query, but its way to slow, even with indexes on idx and type: select mins.type, mins.dat, mytable.dat from mytable --get the maximums inner join (select max(idx) as maxidx from mytable group by type) as a on a.maxidx = mytable.idx --join the maximums to the

Geopandas dataframe to GeoJSON to Elasticsearch index?

六眼飞鱼酱① 提交于 2021-02-10 14:44:51
问题 I've a question that is related to this question: I'm relatively new to python and now have started to visualize in Kibana, which I'm brand new at (as in, I've never used it before). Now I have a pandas datafram geoseries like this: ID Geometry 0 9417 POLYGON ((229611.185 536552.731, 229611.100 53... 1 3606 POLYGON ((131122.280 460609.117, 131108.312 46... 2 1822 POLYGON ((113160.653 517762.384, 113169.755 51... 3 7325 POLYGON ((196861.725 470370.632, 196869.990 47... 4 9258 POLYGON ((201372

Count on join of big tables with conditions is slow

孤街浪徒 提交于 2021-02-10 06:11:54
问题 This query had reasonable times when the table was small. I'm trying to identify what's the bottleneck, but I'm not sure how to analyze the EXPLAIN results. SELECT COUNT(*) FROM performance_analyses INNER JOIN total_sales ON total_sales.id = performance_analyses.total_sales_id WHERE (size > 0) AND total_sales.customer_id IN ( SELECT customers.id FROM customers WHERE customers.active = 't' AND customers.visible = 't' AND customers.organization_id = 3 ) AND total_sales.product_category_id IN (

Index on Composite attributes

瘦欲@ 提交于 2021-02-10 05:38:25
问题 When we create an index on an attribute a tree is created for this attribute. But what happens when we create an index with composite attributes? Two trees are created? Both are part of the same tree? What? 回答1: It concats the attributes in the same order as you have mentioned. It for the same reason, if you have an composite index on columns a,b,c in the same order, the index will be useful only if the left columns are searched WHERE a=4 ## uses index WHERE a=4 and b=10 ## uses index WHERE b

Using an array for in array indexing

徘徊边缘 提交于 2021-02-10 05:35:30
问题 Is there a nicer way to do this? a = rand(10,10) a[[CartesianIndex(i,i) for i in 1:10]] .= something I.e. using setindex! without a CartesianIndex or something like a[i,i for i in 1:10] .= something Or in general using setindex! with an array for syntax? 回答1: I like the CartesianIndex solution, but one other way would be to create a boolean mask: julia> a = rand(5, 5); julia> a[[i == j for i ∈ 1:5, j ∈ 1:5]] .= 0; julia> a 5×5 Array{Float64,2}: 0.0 0.376169 0.0248078 0.957535 0.522565 0

Pyomo Cannot index a component with an indexed set

空扰寡人 提交于 2021-02-10 05:14:42
问题 I have a Pyomo model that has a sparse set of values but I get the error Cannot index a component with an indexed set when I try to index a binary variable according to this sparse set. For a simplified example: model = ConcreteModel() model.S = Set([1, 4, 6]) model.V = Var(model.S, within=Binary) 回答1: The line model.S = Set([1, 4, 6]) creates an Indexed Set: that is a Set of 3 Sets, each one of which is empty (Pyomo treats positional arguments as indexing sets - just like in your comment

Pyomo Cannot index a component with an indexed set

ぐ巨炮叔叔 提交于 2021-02-10 05:14:33
问题 I have a Pyomo model that has a sparse set of values but I get the error Cannot index a component with an indexed set when I try to index a binary variable according to this sparse set. For a simplified example: model = ConcreteModel() model.S = Set([1, 4, 6]) model.V = Var(model.S, within=Binary) 回答1: The line model.S = Set([1, 4, 6]) creates an Indexed Set: that is a Set of 3 Sets, each one of which is empty (Pyomo treats positional arguments as indexing sets - just like in your comment

Pyomo Cannot index a component with an indexed set

房东的猫 提交于 2021-02-10 05:13:25
问题 I have a Pyomo model that has a sparse set of values but I get the error Cannot index a component with an indexed set when I try to index a binary variable according to this sparse set. For a simplified example: model = ConcreteModel() model.S = Set([1, 4, 6]) model.V = Var(model.S, within=Binary) 回答1: The line model.S = Set([1, 4, 6]) creates an Indexed Set: that is a Set of 3 Sets, each one of which is empty (Pyomo treats positional arguments as indexing sets - just like in your comment

Postgresql: query on jsonb column - index doesn't make it quicker

∥☆過路亽.° 提交于 2021-02-09 08:34:31
问题 There is a table in Postgresql 9.6 , query on jsonb column is slow compared to a relational table, and adding a GIN index on it doesn't make it quicker. Table: -- create table create table dummy_jsonb ( id serial8, data jsonb, primary key (id) ); -- create index CREATE INDEX dummy_jsonb_data_index ON dummy_jsonb USING gin (data); -- CREATE INDEX dummy_jsonb_data_index ON dummy_jsonb USING gin (data jsonb_path_ops); Generate data: -- generate data, CREATE OR REPLACE FUNCTION dummy_jsonb_gen

Postgresql: query on jsonb column - index doesn't make it quicker

左心房为你撑大大i 提交于 2021-02-09 08:27:55
问题 There is a table in Postgresql 9.6 , query on jsonb column is slow compared to a relational table, and adding a GIN index on it doesn't make it quicker. Table: -- create table create table dummy_jsonb ( id serial8, data jsonb, primary key (id) ); -- create index CREATE INDEX dummy_jsonb_data_index ON dummy_jsonb USING gin (data); -- CREATE INDEX dummy_jsonb_data_index ON dummy_jsonb USING gin (data jsonb_path_ops); Generate data: -- generate data, CREATE OR REPLACE FUNCTION dummy_jsonb_gen