pikelang / Pike

Pike is a dynamic programming language with a syntax similar to Java and C. It is simple to learn, does not require long compilation passes and has powerful built-in data types allowing simple and really fast data manipulation.
http://pike.lysator.liu.se/
Other
194 stars 34 forks source link

Possible SQL option to avoid duplicating data #24

Closed Dsiefus closed 4 years ago

Dsiefus commented 5 years ago

It would be interesting to have an option when performing an SQL query so that it doesn't need to return any duplicate information: for example, right now

SQL->query("select moneda from table where id=2"); Result: ({ ([ "moneda": "EUR", "users.moneda": "EUR" ]) })

Each row is stored twice in memory, one with the table name at the beginning and one without it. That can be a big waste of memory in some cases, so an optional parameter to indicate that only 1 of the (currently) 2 values needs to be returned/stored could be useful.

tobij commented 5 years ago

Hi,

are you worried about the columns themselves? I would assume regular SQL databases/query results do not have excessive amounts of columns.

When it comes to the data, i.e. in your example above "EUR", it will exist only once; it is merely referenced twice. While there obviously is some overhead because of this, it is not like all result data is actually duplicated.

Dsiefus commented 5 years ago

In some cases the query could have many columns, and then the optional argument could be handy. I don't know if there are specific cases where it is desirable that the query result is stored like this, but I guess you have your reasons.

ghost commented 5 years ago

@tobij So if I understand the issue its just a flattening of references for the return object, and he wants one preserved in an easily mentally formatted form? Would this potentially open collisions of (n items more than one) with a common name child or would enacting an intentional collision of children potentially spring a safeguard and disable the feature of alias flattening?

ghost commented 5 years ago

I'm seeing an inline double depth ternary with assignment inside of a function's calling arguments. Thats impressively flexible and slightly terrifying. May I ask how num_rows() and num_fields() are being implimented? Are they like virtual overrides or an inheritance to be handled elsewhere? I have to learn more about your style, compiler and language! It seems to allow you to be VERY flexible.

how https://github.com/pikelang/Pike/blob/db46c523f02982311f06979193b0388e01ab4fc5/lib/modules/Sql.pmod/sql_result.pike#L38

grubba commented 5 years ago

Hmm... I'm not sure why f is reassigned there, as it has already been set to num_fields() a few lines earlier.

grubba commented 5 years ago

Anyway, Sql.pmod/sql_result.pike is a remnant of the old Sql implementation.

For the current implementation, the base class is __builtin.pmod/Sql.pmod/Connection.pike.