Are You in an Abusive Relationship with Your Phone

I watched the movie Alice, Darling, which made me think of abusive relationships. I will not describe the film here, but you should watch it, it’s good.

One of the thoughts that came to mind after the movie is how aside from people, other things are abusive to relationships. For example, bad habits, social media, and video streaming are vicious when not measured and restricted – just like abusive people.

Our bad habits allow these abusive relationships with technology to flourish, but don’t blame yourself yet. Modern apps and digital ecosystems are specifically designed for us to use them constantly, to make us feel part of a community, all while making us ignore the natural world and people around us. By ‘digital ecosystems,’ I’m referring to the interconnected networks of software, hardware, and services that make up the digital landscape we interact with daily. This includes social media platforms, search engines, and mobile applications, among others.
Just like abusive people in many relationships, digital ecosystems make you believe they care about you, but they don’t. Their goal is primarily attention-grabbing at best and manipulation at worst.

It sounds ridiculous to think of apps and technology as abusive partners, but they are. They embed themselves into our daily lives. They are why many of us ignore the world around us, our families, partners, kids, friends, etc. It happens, and I recognize people experience this at different levels, but most of us dedicate more time to technology (apps, gadgets, etc.) than to our beloved humans.

What’s the solution? I don’t know. I place myself in a position that helps me ignore technology. For example, when I sit to eat, I try not to take my phone out of my pocket. It stays there, which helps me avoid glancing at it occasionally. I work from home, so to separate my work life from my personal life, I add physical space. For example, I allocate specific hours to work and walk away from my work desk once I am done with it. I also only work on that desk during the week, during my work hours.

I have moved apps off of the home screen on my phone and only have what I consider essential apps there. For example, I have all notifications disabled. I look at the messaging app my family often uses to find out if there are any important messages from a family member. If an emergency arises, I’ll get a call.

I removed all work-related applications from my phone as well. So when I am off work, I am off work. And if an emergency came up where someone would need my assistance, they could text me or call me.

Technology has become an integral part of our lives today, and it’s hard to imagine living without it. However, it’s important to recognize that sometimes technology can be abusive to our relationships, just like people can. The constant use of technology can make us ignore the world around us, including our loved ones. Therefore, it’s up to us to take control of our relationship with technology and create boundaries.

The solutions mentioned in this essay are just a few ways to help us break free from the constant cycle of notifications, alerts, and the pressure to be connected 24/7. By taking control of our relationship with technology, we can ensure that our time and attention are directed toward the things that truly matter, our family, friends, and the natural world around us. So, let’s strive to be mindful of our technology use and create healthy relationships with it.

Allowing yourself to try something new

For years, my favorite drink of choice in the mornings and the evenings has been coffee. But occasionally, enjoy a hot cup of tea, specifically chamomile tea. That is the only tea that I would drink.

A few days ago, as I was about to start organizing some of my photos after dinner, I decided to get a cup of tea. To my surprise, the chamomile tea was gone, nada. And for the first time, I decided to try one of the many other teas we have at home. I felt brave, walked to the pantry, and grabbed some black tea. It was wonderful. A few days later, we were still out of chamomile tea, and I again picked a different tea, masala chai. It was even better than the simple black tea.

While taking advantage of different tea flavors is unimportant, this simple activity made me wonder how many other things I have missed for not wanting to try new things. I consider myself open-minded and a person who seeks new experiences, but I could be more of an explorer when it comes to daily life and work.

I noticed that when I’m home, I often eat the same things, watch the same stuff, spend time the same way, etc. When traveling, I often try new things, spend my time out and about, and work is often better. My experience while at home is what we usually call a routine. A routine in itself is not a bad thing. Having a routine helps me stay focused, productive, and happy. But adding some variety to it helps sparks creativity and even happiness.

You can have a routine and still try a new approach to working or spending your day. My goal is not to stay in my comfort zone, at least not in the areas where I want to experience and learn more. It all starts with small decisions, a different tea flavor, a different approach to a problem at work, reading a book on a topic I wouldn’t choose before, etc. Exposing yourself to new things can expand your world and perspective and make life, even the routine, more interesting.

We are still out of chamomile tea a week later, and it is okay.

My bookstore addiction

Do you like bookstores? I do, and apparently, many other people do too. Why? A bookstore is a place full of wonder and imagination. Each book can be a window into a different world, a unique story, perspective, or something new to learn. Walking around bookstores feeds my motivation to continue reading, learning, discovering, and writing. Books and magazines are, for me, more interesting than social media. There’s something about its staticity; it’s a written memory or thought captured and shared via a book or a moment captured in time via a photo in a magazine.

Bookstores are a place of happiness for me. The problem is, it is also a place where I can compulsively buy books and magazines and then not read them in a while—why? Is this a problem for you too? I do read a lot, and I mean a lot. Since late last year, I started the idea of reading a book per week, and I’ve been able to do it for the most part. Of course, I have skipped a few weeks here and there due to having a great time on holiday with the family. But even with all that reading, I still have a reading queue that keeps increasing due to buying books and magazines almost every time I walk into one of these beautiful, magical places we call bookstores.

The good news is I am balancing my reading with writing and note-taking. Reading without the writing or note-taking part is just entertainment, which is OK too. Most books I read have something in them that I want to remember or use in my daily life, and that happens even with fiction books. I am learning a simple way to develop my second brain to help me memorize pieces of information that I want to refer to later. I’ll share more details about this in a future post.

One of my current projects is to create a photo book showcasing bookstores from around the world, displaying photos of the outside and the bookstore interiors. I want to capture their essence as much as possible. And while one picture is worth a thousand words, I plan to write a few paragraphs describing each bookstore, my experience, and other information about its location, history, etc.

I have been taking photos of every bookstore I visit around the world, and already have a nice collection of pictures. I will continue to visit bookstores whenever I have a chance. This project was and will continue to be an excuse to visit as many bookstores as possible.

This photo book project will probably be done by the end of this year and depending on how I feel about it, I might continue working on it one way or another. A website where I keep adding bookstore photos and description is also an option.

Maybe one day I will satisfy my hunger for bookstores by opening my own, but it is perhaps the experience of traveling and visiting different bookstores that I enjoy.

How to (efficiently) delete millions of records in a SQL table

A while ago, I blogged about how to efficiently update millions of records in a SQL table, today I’d like to show you a simple trick to do the same when deleting millions of records in a SQL table.

The idea is the same, you don’t want to do it all at once, instead, you want to delete a fixed number of records at a time. Why do we need to do this? For starters, when you delete data from a table, a lot of things happen behind the scenes, and because of this, you need to be careful when removing data, especially, large amounts of data.

Many activities are performed by SQL when removing data, and because of this, it is important to know that certain items like the ones listed below can affect the locking and performance behavior of SQL delete statements:

  • Number of indexes in the table
  • Poor indexed foreign keys
  • Lock escalation mode
  • Isolation levels
  • Batch sizes of the delete statement
  • Trigger(s)
  • Temporal tables

One thing you need to consider is also cascade deletes, when you delete data from one table, SQL might also attempt to remove data from a few or many more tables with references to the data you are deleting. This is a good things as it prevents orphan records, but it has also the potential to affect the performance of your delete statements.

The list above shows you some of the main areas to consider when removing large amounts of data, but in this post, I will assume you have considered having the correct type of indexes to make sure that the indexes are helpful when deleting data, and not the reason for table blocking or worst, deadlocks.

I’d like to show you how to do batch deletes to only delete an specific number of records at a time. Performing the delete in batches, helps avoiding or reducing locking on the tables where the data is being removed. Below are some examples on how to do this in code, as well as when deleting data directly via SQL code.

Batch deletes with C#

n C#, you can use the Dapper library to delete data in batches using the “DELETE” statement in conjunction with a “WHERE” clause and a loop to iterate through a set of records.

Here is an example of how to delete data in batches of 1000 records using Dapper:

using (IDbConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    int batchSize = 1000;
    int currentIndex = 0;
    while (true)
    {
        string deleteSql = "DELETE FROM myTable WHERE Id IN (SELECT Id FROM myTable ORDER BY Id OFFSET @index ROWS FETCH NEXT @batch ROWS ONLY)";
        var parameters = new { index = currentIndex, batch = batchSize };
        int rowsAffected = connection.Execute(deleteSql, parameters);
        if (rowsAffected == 0)
        {
            break;
        }
        currentIndex += rowsAffected;
    }
}

Please note that this is a simple example for demonstration purposes only and it is recommended that you add additional error handling and logging in your actual implementation.

Batch deletes with SQL

Here is an example of a DELETE statement that can be used to delete data in batches of 1000 records within Microsoft SQL.

DECLARE @batchSize INT = 1000;
DECLARE @currentIndex INT = 0;

WHILE 1 = 1
BEGIN
    DELETE FROM myTable
    WHERE Id IN (
        SELECT Id
        FROM myTable
        ORDER BY Id
        OFFSET @currentIndex ROWS
        FETCH NEXT @batchSize ROWS ONLY
    );

    SET @currentIndex = @currentIndex + @batchSize;

    IF @@ROWCOUNT = 0
        BREAK;
END;

This query uses a WHILE loop to repeatedly execute the DELETE statement until all rows have been deleted. The number of rows deleted in each iteration is determined by the @batchSize variable. The loop continues to execute as long as the @@ROWCOUNT variable is not 0.

It is worth noting that this kind of query can be resource-intensive if the table being deleted from is very large, so it’s important to test the performance on a test environment before running it on production. However, if you have the need to delete millions of records, this is still much better than attempting to delete all records at once.

It’s also worth noting that this query will work on SQL Server. If you are using other SQL databases such as MySQL, PostgreSQL or Oracle, the syntax may be slightly different.

The optimal batch size for deleting records in SQL will depend on various factors such as the size of the table, the amount of available memory, and the overall performance of the database. In general, larger batch sizes can be more efficient as they reduce the number of times the database needs to perform the delete operation, but they also require more memory to hold the set of records being deleted.

A batch size of 1000 records is a common starting point, but it may not be the best option for your specific use case. You may want to experiment with different batch sizes such as 5000 and observe the performance of your database to determine the optimal batch size for your needs.

It’s important to keep in mind that larger batch sizes can consume more memory, especially if your table is large and contains a lot of data. Also, If you have indexes on the table, then deleting large batch of records at once may lead to a more significant impact on the performance of the database.

In addition, if you are working with a production database, you should also consider the possible impact on other queries or transactions that might be executing concurrently. It’s always a good practice to test your code on a test environment before deploying to a production environment.

Lastly, if you have a table or tables where the data needs to be deleted often, you might want to create a scheduled SQL job that will run weekly or as often as you need to, and delete the data that isn’t needed anymore. This will be helpful to avoid deleting large amounts of data at once, and it will also keep your table(s) from increasing in size without need.

Happy coding!

The Logbook – part 3.

I wrote a brief post about starting a logbook in January 2021 and then an update on April 2021. This is the latest update about my use of the logbook, the tools I use for it, and how I plan to use it this year.

The logbook is a mini daily planner that I use to log daily activities and anything you want or need. There aren’t any rules or templates. Write down what you want each day, and log your day as detailed or briefly as you wish.

My use of the logbook has been very casual. I don’t write on it daily, but I want to change that. However, it’s been helpful, especially when looking back and learning more about my almost daily life. The logbook helps me think and capture data about my everyday life.

This year, I have specific questions I want to answer daily using my logbook. For example:

  • How much money did I spend today?
  • How much water do I consume every day?
  • How many cups of coffee do I consume every day?
  • Ideas and random thoughts

I’ve been doing this for about two years, but casually. I plan on writing casually in my logbook, but questions like the above need to be answered daily, which is my goal.

Why is this important? Writing down this information forces you to think about this and avoid living your life on autopilot. Writing it down on paper is the easiest thing for me. The daily planner I use is small and flexible, and I can carry it with me every day and everywhere. In addition, writing down anything on paper helps you memorize it more than typing it on a keyboard.

Tools I use to capture data about my everyday life:

Good luck and happy logging!