What are the Slack Archives?
Itโs a history of our time together in the Slack Community! Thereโs a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you wonโt be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hello! In spryker package `spy_price_product_store` there is an index of `spy_price_product_store-i
Comments
-
Hmm, this would not be an option for our case, as we import all the time quite a lot of products.
0 -
So it would take forever to reindex that table.
0 -
And then P&S would bite youโฆ
0 -
how does you bulk insert look like?
0 -
If you already use Postgres, have a look at the SQL based importers and use upsert statements.
Especially Postgres is pretty good at rescheduling indices.0 -
-
ah ok, you already use the CTE contruct
0 -
let me test this against my database
0 -
could take some time
0 -
Just test it when you have few millions of rowsโฆ
0 -
giovanni.piemontese Technical Lead @ Lรถffelhardt Spryker Solution Partner Posts: 871 ๐ง๐ปโ๐ - Cadet
we import 2,5Mio Prices with the same CTE in ca 20min...
0 -
With updates as well or only inserts?
0 -
We have bothโฆ
0 -
giovanni.piemontese Technical Lead @ Lรถffelhardt Spryker Solution Partner Posts: 871 ๐ง๐ปโ๐ - Cadet
i don't think that the problem is the index, because we have the same index and postgres
0 -
giovanni.piemontese Technical Lead @ Lรถffelhardt Spryker Solution Partner Posts: 871 ๐ง๐ปโ๐ - Cadet
insert and update.. both... price in our project is always fully import
0 -
Hmm, interesting ๐
0 -
Better use
Upserts (the ON CONFLICT clause) should be faster then building two changesets, that was at least a performance boost I found for our CTE imports.
0 -
giovanni.piemontese Technical Lead @ Lรถffelhardt Spryker Solution Partner Posts: 871 ๐ง๐ปโ๐ - Cadet
I share with u our query:
public function createPriceProductStoreSql(string $tableName, string $foreignKey, string $idProduct): string { $sql = sprintf("WITH records AS ( SELECT input.id_store, input.id_currency, input.%3\$s, input.id_price_product, input.gross_price, input.net_price, spy_price_product_store.id_price_product_store as idPriceProductStore, input.price_data, input.price_data_checksum FROM ( SELECT unnest(?::INTEGER[]) AS id_store, unnest(?::INTEGER[]) AS id_currency, unnest(?::INTEGER[]) AS %3\$s, unnest(?::INTEGER[]) AS id_price_product, unnest(?::INTEGER[]) AS gross_price, unnest(?::INTEGER[]) AS net_price, json_array_elements_text(?) AS price_data, unnest(?::VARCHAR[]) AS price_data_checksum ) input LEFT JOIN spy_price_product_store ON ( spy_price_product_store.fk_price_product = input.id_price_product AND spy_price_product_store.fk_currency = id_currency AND spy_price_product_store.fk_store = id_store ) ), updated AS ( UPDATE spy_price_product_store SET gross_price = records.gross_price, net_price = records.net_price, price_data = records.price_data, price_data_checksum = records.price_data_checksum FROM records WHERE spy_price_product_store.fk_price_product = records.id_price_product AND spy_price_product_store.fk_store = records.id_store AND spy_price_product_store.fk_currency = records.id_currency RETURNING idPriceProductStore as id_price_product_store ), inserted AS ( INSERT INTO spy_price_product_store ( id_price_product_store, fk_store, fk_currency, fk_price_product, net_price, gross_price, price_data, price_data_checksum ) ( SELECT nextval('spy_price_product_store_pk_seq'), id_store, id_currency, id_price_product, net_price, gross_price, price_data, price_data_checksum FROM records WHERE records.id_price_product IS NOT NULL AND records.idPriceProductStore IS NULL ) RETURNING id_price_product_store ) SELECT updated.id_price_product_store FROM updated UNION ALL SELECT inserted.id_price_product_store FROM inserted;", $tableName, $foreignKey, $idProduct); return $sql; }
smth is others in where condition in update query
0 -
please keep in mind: the upsert might bloat the sequence
0 -
please keep in mind: the upsert might bloat the sequence
Not if you do an LEFT JOIN to get the already existing entry (if there is one) and use
COALESCE(original_table.id_xyz, nextval('spy_original_table_pk_seq')) AS id_xyz
0 -
interesting approach
0 -
do you have some numbers on how this impacted performance?
0 -
@UJN2JRU4F This very much depends on what importer we had, but for one importer we achieved around 40% of performance increase (comparing the Spryer CTE approach and my approach above). But I do not have crunched numbers as we use the CTE approach only for a new data source which is in size and complexity not really comparable to the previous importers.
0 -
So, for the scale of data we have:
0 -
We have 2 price types
0 -
And 8 currencies
By doing basic calculations, we should have approx. (301591 + 47612) * 21 * 2 * 8= ~16.8 mil. rows. And at this size, it is very slow.
0 -
And thatโs the worst case scenario.
0 -
Does anyone have same size and it runs fine?
0 -
If we would have 21 stores we would already have put them onto different databases
0 -
Well we didnโt cause Spryker proposed to not to do thatโฆ
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K ๐ Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random