Processing cost between code and database

Asked

Viewed 83 times

1

Among the many forms of development, there was a doubt about what will consume the most of my processing between the same operation in different ways...

If I have a function that can be done directly in my database (a insert using a select as a basic example)

Insert into Tabela1(Coluna1,2Coluna,3_coluna) select (select cod from tabela3 where tabela3.nome = tabela2.nome)as 'Coluna1',valorx,valory from Tabela2  Tabela2.cod=z

and the same function can be done through my code

 MySqlCommand mySqlCommand_Select = new MySqlCommand("Busca valores tabela2", mySqlConnection);

MySqlCommand mySqlCommand_Select_2 = new MySqlCommand("Busca valores tabela3", mySqlConnection);

//...
//Unir Selects, trabalha os valores etc
//...

 MySqlCommand mySqlCommand_insert = new MySqlCommand("Insere os valores tabela1", mySqlConnection);

The process being carried out the same, the cost is higher for one or the other or is equal?

The question includes other operations that can be done directly in the bank and/or code (such as calculations, other darlings used as sub or as various searches) but it comes down to the cost of 'Outsource' or not these operations for my application

1 answer

2


You can only answer this on a case-by-case basis, which means you only measure with darlings, available optimizations, data load and actual access load. What is valid in one circumstance is not valid for another.

Anyway the two of you cheese will be executed in the database, so the premise of the question is false. I am considering that the query will be the same used in pure SQL.

Without more details, without knowing what optimizations are possible I would say that the cost is even. I don’t know if Mysql has any specific optimization that can make one of them faster.

It must have an insignificant marginal difference, spatially if it has a lot of data.

If the darlings are different is comparing oranges with bananas and the result is not useful.

In this case they seem different since one is doing everything at once and the other is doing it in three different parts. There is not so much question of doing in the database or not, it is the fact of being separate queries.

The fact that it is starting with the code only strengthens the problem because several data will travel between the application and the database without need. But again this only occurs because the query is another, not because it was started in the application.

  • Although I myself note that this not very well explained was the best way I found, but I believe that this answer is a large variant among the cases, still, what I wanted to ask was about the costs of things like large calculations and formulations for example, best would be to bring this data to my system or I can work with them still in sql(still talking about processing cost)

  • @Leolonghi, analyzing the question according to your argument here. It was not clear what his goal was, I believe that because of this, it was this answer that he got.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.